Package rs.jackson

Class JsonUtils

java.lang.Object
rs.jackson.JsonUtils

public class JsonUtils extends Object
JSON utils for mapping back and forth
Author:
ralph
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    fromJson(File file, com.fasterxml.jackson.core.type.TypeReference<T> type)
    Convert from JSON to Object.
    static <T> T
    fromJson(File file, com.fasterxml.jackson.databind.JavaType type)
    Convert from JSON to Object.
    static <T> T
    fromJson(File file, Class<T> clazz)
    Convert from JSON to Object.
    static <T> T
    fromJson(InputStream stream, com.fasterxml.jackson.core.type.TypeReference<T> type)
    Convert from JSON to Object.
    static <T> T
    fromJson(InputStream stream, com.fasterxml.jackson.databind.JavaType type)
    Convert from JSON to Object.
    static <T> T
    fromJson(InputStream stream, Class<T> clazz)
    Convert from JSON to Object.
    static <T> T
    fromJson(Reader reader, com.fasterxml.jackson.core.type.TypeReference<T> type)
    Convert from JSON to Object.
    static <T> T
    fromJson(Reader reader, com.fasterxml.jackson.databind.JavaType type)
    Convert from JSON to Object.
    static <T> T
    fromJson(Reader reader, Class<T> clazz)
    Convert from JSON to Object.
    static <T> T
    fromJson(String json, com.fasterxml.jackson.core.type.TypeReference<T> type)
    Convert from JSON to Object.
    static <T> T
    fromJson(String json, com.fasterxml.jackson.databind.JavaType type)
    Convert from JSON to Object.
    static <T> T
    fromJson(String json, Class<T> clazz)
    Convert from JSON to Object.
    static com.fasterxml.jackson.databind.ObjectMapper
    Returns a configured JsonMapper object.
    static String
    Convert any object to its Json representation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JsonUtils

      public JsonUtils()
  • Method Details

    • toJson

      public static String toJson(Object o)
      Convert any object to its Json representation.
      Parameters:
      o - - the object to convert
      Returns:
      the JSON string
    • fromJson

      public static <T> T fromJson(String json, Class<T> clazz)
      Convert from JSON to Object.
      Type Parameters:
      T - Class type
      Parameters:
      json - JSON string
      clazz - Type Class
      Returns:
      the object
    • fromJson

      public static <T> T fromJson(String json, com.fasterxml.jackson.databind.JavaType type)
      Convert from JSON to Object.
      Type Parameters:
      T - Class type
      Parameters:
      json - JSON string
      type - Java type
      Returns:
      the object
    • fromJson

      public static <T> T fromJson(String json, com.fasterxml.jackson.core.type.TypeReference<T> type)
      Convert from JSON to Object.
      Type Parameters:
      T - Class type
      Parameters:
      json - JSON string
      type - Type reference
      Returns:
      the object
    • fromJson

      public static <T> T fromJson(File file, Class<T> clazz)
      Convert from JSON to Object.
      Type Parameters:
      T - Class type
      Parameters:
      file - JSON file
      clazz - Type Class
      Returns:
      the object
    • fromJson

      public static <T> T fromJson(File file, com.fasterxml.jackson.databind.JavaType type)
      Convert from JSON to Object.
      Type Parameters:
      T - Class type
      Parameters:
      file - JSON file
      type - Java type
      Returns:
      the object
    • fromJson

      public static <T> T fromJson(File file, com.fasterxml.jackson.core.type.TypeReference<T> type)
      Convert from JSON to Object.
      Type Parameters:
      T - Class type
      Parameters:
      file - JSON file
      type - Type reference
      Returns:
      the object
    • fromJson

      public static <T> T fromJson(InputStream stream, Class<T> clazz)
      Convert from JSON to Object.
      Type Parameters:
      T - Class type
      Parameters:
      stream - JSON input stream
      clazz - Type Class
      Returns:
      the object
    • fromJson

      public static <T> T fromJson(InputStream stream, com.fasterxml.jackson.databind.JavaType type)
      Convert from JSON to Object.
      Type Parameters:
      T - Class type
      Parameters:
      stream - JSON input stream
      type - Java type
      Returns:
      the object
    • fromJson

      public static <T> T fromJson(InputStream stream, com.fasterxml.jackson.core.type.TypeReference<T> type)
      Convert from JSON to Object.
      Type Parameters:
      T - Class type
      Parameters:
      stream - JSON input stream
      type - Type reference
      Returns:
      the object
    • fromJson

      public static <T> T fromJson(Reader reader, Class<T> clazz)
      Convert from JSON to Object.
      Type Parameters:
      T - Class type
      Parameters:
      reader - JSON reader
      clazz - Type Class
      Returns:
      the object
    • fromJson

      public static <T> T fromJson(Reader reader, com.fasterxml.jackson.databind.JavaType type)
      Convert from JSON to Object.
      Type Parameters:
      T - Class type
      Parameters:
      reader - JSON reader
      type - Java type
      Returns:
      the object
    • fromJson

      public static <T> T fromJson(Reader reader, com.fasterxml.jackson.core.type.TypeReference<T> type)
      Convert from JSON to Object.
      Type Parameters:
      T - Class type
      Parameters:
      reader - JSON reader
      type - Type reference
      Returns:
      the object
    • getJsonMapper

      public static com.fasterxml.jackson.databind.ObjectMapper getJsonMapper()
      Returns a configured JsonMapper object.
      Returns:
      the JsonMapper