Class JSONCoder

java.lang.Object
xal.tools.coding.json.JSONCoder
All Implemented Interfaces:
Coder

public class JSONCoder extends Object implements Coder
encode and decode objects with JSON
  • Method Details

    • getInstance

      public static JSONCoder getInstance()
      get a new JSON Coder only if you need to customize it, otherwise use the static methods to encode/decode
    • getDefaultTypes

      public static List<String> getDefaultTypes()
      Get a list of types (including JSON standard types plus default extensions) which are supported for coding and decoding
    • getStandardTypes

      public static List<String> getStandardTypes()
      Get a list of the standard types encoded directly into JSON
    • isStandardType

      public static boolean isStandardType(String type)
      Determine whether the specified type is a standard JSON type
    • getSupportedTypes

      public List<String> getSupportedTypes()
      Get a list of all types which are supported for coding and decoding
      Specified by:
      getSupportedTypes in interface Coder
    • getExtendedTypes

      public List<String> getExtendedTypes()
      Get a list of types which extend beyond the JSON standard types
    • registerType

      public <C, R> void registerType(Class<C> type, ConversionAdaptor<C,R> adaptor)
      Register the custom type by class and its associated adaptor
      Specified by:
      registerType in interface Coder
      Parameters:
      type - type to identify and process for encoding and decoding
      adaptor - translator between the custom type and representation JSON constructs
    • getConversionAdaptor

      protected ConversionAdaptor<?,?> getConversionAdaptor(String valueType)
      Get the conversion adaptor for the given value
    • defaultDecode

      public static Object defaultDecode(String archive)
      Decode the JSON string using the default coder
      Parameters:
      archive - JSON string representation of an object
      Returns:
      an object with the data described in the archive
    • decode

      public Object decode(String archive)
      Decode the JSON string
      Specified by:
      decode in interface Coder
      Parameters:
      archive - JSON string representation of an object
      Returns:
      an object with the data described in the archive
    • defaultEncode

      public static String defaultEncode(Object value)
      Encode the object as a JSON string using the default encoder
      Parameters:
      value - the object to encode
      Returns:
      a JSON string representing the value
    • encode

      public String encode(Object value)
      Encode the object as a JSON string
      Specified by:
      encode in interface Coder
      Parameters:
      value - the object to encode
      Returns:
      a JSON string representing the value