public final class JsonFlattener extends Object
JsonFlattener flattens any JSON nested objects or arrays into a
flattened JSON string or a Map<Stirng, Object>. The String key
will represents the corresponding position of value in the original nested
objects or arrays and the Object value are either String, Boolean, Long,
Double or null. | Modifier and Type | Field and Description |
|---|---|
static String |
ROOT
ROOT is the default key of the Map returned by
flattenAsMap(java.lang.String). |
| Constructor and Description |
|---|
JsonFlattener(Reader jsonReader)
Creates a JSON flattener.
|
JsonFlattener(String json)
Creates a JSON flattener.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o) |
String |
flatten()
Returns a flattened JSON string.
|
static String |
flatten(String json)
Returns a flattened JSON string.
|
Map<String,Object> |
flattenAsMap()
Returns a flattened JSON as Map.
|
static Map<String,Object> |
flattenAsMap(String json)
Returns a flattened JSON as Map.
|
int |
hashCode() |
String |
toString() |
JsonFlattener |
withFlattenMode(FlattenMode flattenMode)
A fluent setter to setup a mode of the
JsonFlattener. |
JsonFlattener |
withKeyTransformer(KeyTransformer keyTrans)
A fluent setter to setup a
KeyTransformer of the
JsonFlattener. |
JsonFlattener |
withLeftAndRightBrackets(char leftBracket,
char rightBracket)
A fluent setter to setup the left and right brackets within a key in the
flattened JSON.
|
JsonFlattener |
withPrintMode(PrintMode printMode)
A fluent setter to setup a print mode of the
JsonFlattener. |
JsonFlattener |
withSeparator(char separator)
A fluent setter to setup the separator within a key in the flattened JSON.
|
JsonFlattener |
withStringEscapePolicy(CharSequenceTranslatorFactory policy)
A fluent setter to setup the JSON string escape policy.
|
public static final String ROOT
ROOT is the default key of the Map returned by
flattenAsMap(java.lang.String). When JsonFlattener processes a JSON string
which is not a JSON object or array, the final outcome may not suit in a
Java Map. At that moment, JsonFlattener will put the result in the
Map with ROOT as its key.public JsonFlattener(String json)
json - the JSON stringpublic JsonFlattener(Reader jsonReader) throws IOException
jsonReader - the JSON readerIOException - if jsonReader cannot be readpublic static String flatten(String json)
json - the JSON stringpublic static Map<String,Object> flattenAsMap(String json)
json - the JSON stringpublic JsonFlattener withFlattenMode(FlattenMode flattenMode)
JsonFlattener.flattenMode - a FlattenModeJsonFlattenerpublic JsonFlattener withStringEscapePolicy(CharSequenceTranslatorFactory policy)
policy - any CharSequenceTranslatorFactory or a
StringEscapePolicyJsonFlattenerpublic JsonFlattener withSeparator(char separator)
separator - any characterJsonFlattenerpublic JsonFlattener withLeftAndRightBrackets(char leftBracket, char rightBracket)
leftBracket - any characterrightBracket - any characterJsonFlattenerpublic JsonFlattener withPrintMode(PrintMode printMode)
JsonFlattener. The
default print mode is minimal.printMode - a PrintModeJsonFlattenerpublic JsonFlattener withKeyTransformer(KeyTransformer keyTrans)
KeyTransformer of the
JsonFlattener.keyTrans - a KeyTransformerJsonFlattenerpublic String flatten()
public Map<String,Object> flattenAsMap()
Copyright © 2018. All rights reserved.