java.lang.Object
com.github.wnameless.json.unflattener.JsonUnflattener

public final class JsonUnflattener extends Object
JsonUnflattener provides a static unflatten(String) method to unflatten any flattened JSON string back to nested one.
Author:
Wei-Ming Wu
  • Field Details

  • Constructor Details

    • 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 given JsonCore and JSON string.
      Parameters:
      jsonCore - a JsonCore
      json - 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 IOException
      Creates a JSON unflattener by given JsonCore and JSON string reader.
      Parameters:
      jsonCore - a JsonCore
      jsonReader - a JSON reader
      Throws:
      IOException - if the jsonReader cannot be read
    • JsonUnflattener

      public JsonUnflattener(Map<String,?> flattenedMap)
      Creates a JSON unflattener by given flattened Map.
      Parameters:
      flattenedMap - a flattened Map
    • JsonUnflattener

      public JsonUnflattener(com.github.wnameless.json.base.JsonCore<?> jsonCore, Map<String,?> flattenedMap)
      Creates a JSON unflattener by given JsonCore and flattened Map.
      Parameters:
      jsonCore - a JsonCore
      flattenedMap - a flattened Map
  • Method Details

    • 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 the JsonUnflattener.
      Parameters:
      flattenMode - a FlattenMode
      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 character
      rightBracket - any character
      Returns:
      this JsonUnflattener
    • withPrintMode

      public JsonUnflattener withPrintMode(PrintMode printMode)
      A fluent setter to setup a print mode of the JsonUnflattener. The default print mode is minimal.
      Parameters:
      printMode - a PrintMode
      Returns:
      this JsonUnflattener
    • withKeyTransformer

      public JsonUnflattener withKeyTransformer(KeyTransformer keyTrans)
      A fluent setter to setup a KeyTransformer of the JsonUnflattener.
      Parameters:
      keyTrans - a KeyTransformer
      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
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object