Class DefaultMapper

java.lang.Object
com.studerw.tda.parse.DefaultMapper

public class DefaultMapper extends Object
Convert between Java pojos and JSON. This class is thread safe.
  • Constructor Details

    • DefaultMapper

      public DefaultMapper()
  • Method Details

    • toJson

      public static String toJson(Object object)
      Convert object to JSON string. Use Utils.prettyFormat(String) to pretty format the returned JSON string.
      Parameters:
      object - Java POJO to serialize into JSON
      Returns:
      JSON representation of the object
    • fromJson

      public static <T> T fromJson(String json, Class<T> clazz)
      Convert object from JSON to POJO
      Type Parameters:
      T - the type to marshall
      Parameters:
      json - string of json
      clazz - the class type
      Returns:
      a deserialized java POJO
    • fromJson

      public static <T> T fromJson(InputStream in, Class<T> clazz)
      Convert object from JSON to POJO.
      Type Parameters:
      T - the type to marshall
      Parameters:
      in - InputStream of json, guaranteed to be closed upon return.
      clazz - the class type
      Returns:
      a deserialized java POJO
    • fromJson

      public static <T> T fromJson(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
      Convert object from JSON to POJO.
      Type Parameters:
      T - the type to marshall
      Parameters:
      in - InputStream of json, guaranteed to be closed upon return.
      typeReference - Jackson TypeReference of the pojo to map
      Returns:
      a deserialized java POJO