Class JsonUnflattener
- java.lang.Object
-
- com.github.wnameless.json.unflattener.JsonUnflattener
-
public final class JsonUnflattener extends Object
JsonUnflattenerprovides a staticunflatten(String)method to unflatten any flattened JSON string back to nested one.- Author:
- Wei-Ming Wu
-
-
Field Summary
Fields Modifier and Type Field Description static StringROOTROOTis the default key of the Map returned byunflattenAsMap(java.lang.String).
-
Constructor Summary
Constructors Constructor Description JsonUnflattener(com.github.wnameless.json.base.JsonCore<?> jsonCore, Reader jsonReader)Creates a JSON unflattener by givenJsonCoreand JSON string reader.JsonUnflattener(com.github.wnameless.json.base.JsonCore<?> jsonCore, String json)Creates a JSON unflattener by givenJsonCoreand JSON string.JsonUnflattener(com.github.wnameless.json.base.JsonCore<?> jsonCore, Map<String,?> flattenedMap)Creates a JSON unflattener by givenJsonCoreand flattenedMap.JsonUnflattener(Reader jsonReader)Creates a JSON unflattener by given JSON string reader.JsonUnflattener(String json)Creates a JSON unflattener by given JSON string.JsonUnflattener(Map<String,?> flattenedMap)Creates a JSON unflattener by given flattenedMap.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)inthashCode()StringtoString()Stringunflatten()Returns a JSON string of nested objects by the given flattened JSON string.static Stringunflatten(String json)Returns a JSON string of nested objects by the given flattened JSON string.static Stringunflatten(Map<String,?> flattenedMap)Returns a JSON string of nested objects by the given flattened Map.Map<String,Object>unflattenAsMap()Returns a Java Map of nested objects by the given flattened JSON string.static Map<String,Object>unflattenAsMap(String json)Returns a Java Map of nested objects by the given flattened JSON string.static Map<String,Object>unflattenAsMap(Map<String,?> flattenedMap)Returns a Java Map of nested objects by the given flattened Map.JsonUnflattenerwithFlattenMode(FlattenMode flattenMode)A fluent setter to setup a mode of theJsonUnflattener.JsonUnflattenerwithKeyTransformer(KeyTransformer keyTrans)A fluent setter to setup aKeyTransformerof theJsonUnflattener.JsonUnflattenerwithLeftAndRightBrackets(char leftBracket, char rightBracket)A fluent setter to setup the left and right brackets within a key in the flattened JSON.JsonUnflattenerwithPrintMode(PrintMode printMode)A fluent setter to setup a print mode of theJsonUnflattener.JsonUnflattenerwithSeparator(char separator)A fluent setter to setup the separator within a key in the flattened JSON.
-
-
-
Field Detail
-
ROOT
public static final String ROOT
ROOTis the default key of the Map returned byunflattenAsMap(java.lang.String). WhenJsonUnflattenerprocesses a JSON string which is not a JSON object or array, the final outcome may not suit in a Java Map. At that moment,JsonUnflattenerwill put the result in the Map withROOTas its key.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JsonUnflattener
public JsonUnflattener(String json)
Creates a JSON unflattener by given JSON string.- Parameters:
json- a JSON string
-
JsonUnflattener
public JsonUnflattener(com.github.wnameless.json.base.JsonCore<?> jsonCore, String json)Creates a JSON unflattener by givenJsonCoreand JSON string.- Parameters:
jsonCore- aJsonCorejson- a JSON string
-
JsonUnflattener
public JsonUnflattener(Reader jsonReader) throws IOException
Creates a JSON unflattener by given JSON string reader.- Parameters:
jsonReader- a JSON reader- Throws:
IOException- if the jsonReader cannot be read
-
JsonUnflattener
public JsonUnflattener(com.github.wnameless.json.base.JsonCore<?> jsonCore, Reader jsonReader) throws IOExceptionCreates a JSON unflattener by givenJsonCoreand JSON string reader.- Parameters:
jsonCore- aJsonCorejsonReader- a JSON reader- Throws:
IOException- if the jsonReader cannot be read
-
JsonUnflattener
public JsonUnflattener(Map<String,?> flattenedMap)
Creates a JSON unflattener by given flattenedMap.- Parameters:
flattenedMap- a flattenedMap
-
-
Method Detail
-
unflatten
public static String unflatten(String json)
Returns a JSON string of nested objects by the given flattened JSON string.- Parameters:
json- a flattened JSON string- Returns:
- a JSON string of nested objects
-
unflatten
public static String unflatten(Map<String,?> flattenedMap)
Returns a JSON string of nested objects by the given flattened Map.- Parameters:
flattenedMap- a flattened Map- Returns:
- a JSON string of nested objects
-
unflattenAsMap
public static Map<String,Object> unflattenAsMap(String json)
Returns a Java Map of nested objects by the given flattened JSON string.- Parameters:
json- a flattened JSON string- Returns:
- a Java Map of nested objects
-
unflattenAsMap
public static Map<String,Object> unflattenAsMap(Map<String,?> flattenedMap)
Returns a Java Map of nested objects by the given flattened Map.- Parameters:
flattenedMap- a flattened Map- Returns:
- a Java Map of nested objects
-
withFlattenMode
public JsonUnflattener withFlattenMode(FlattenMode flattenMode)
A fluent setter to setup a mode of theJsonUnflattener.- Parameters:
flattenMode- aFlattenMode- Returns:
- this
JsonUnflattener
-
withSeparator
public JsonUnflattener withSeparator(char separator)
A fluent setter to setup the separator within a key in the flattened JSON. The default separator is a dot(.).- Parameters:
separator- any character- Returns:
- this
JsonUnflattener
-
withLeftAndRightBrackets
public JsonUnflattener withLeftAndRightBrackets(char leftBracket, char rightBracket)
A fluent setter to setup the left and right brackets within a key in the flattened JSON. The default left and right brackets are left square bracket([) and right square bracket(]).- Parameters:
leftBracket- any characterrightBracket- any character- Returns:
- this
JsonUnflattener
-
withPrintMode
public JsonUnflattener withPrintMode(PrintMode printMode)
A fluent setter to setup a print mode of theJsonUnflattener. The default print mode is minimal.- Parameters:
printMode- aPrintMode- Returns:
- this
JsonUnflattener
-
withKeyTransformer
public JsonUnflattener withKeyTransformer(KeyTransformer keyTrans)
A fluent setter to setup aKeyTransformerof theJsonUnflattener.- Parameters:
keyTrans- aKeyTransformer- Returns:
- this
JsonUnflattener
-
unflatten
public String unflatten()
Returns a JSON string of nested objects by the given flattened JSON string.- Returns:
- a JSON string of nested objects
-
unflattenAsMap
public Map<String,Object> unflattenAsMap()
Returns a Java Map of nested objects by the given flattened JSON string.- Returns:
- a Java Map of nested objects
-
-