Class JsonMapper


  • public class JsonMapper
    extends Object
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonMapper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T convert​(Object json, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
      Converts the specified JSON object (the result of parsing JSON code to a basic Java type) to an object of the specified result type using the Jackson ObjectMapper.
      static <T> T convert​(Object json, Class<T> clazz)
      Converts the specified JSON object (the result of parsing JSON code to a basic Java type) to an object of the specified class using the Jackson ObjectMapper.
      static String generate​(Object obj)
      Generates a JSON string from the specified object.
      static <T> T parse​(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
      Converts the specified JSON string to an object of the specified result type using the Jackson ObjectMapper.
      static <T> T parse​(String json, Class<T> clazz)
      Converts the specified JSON string to an object of the specified class using the Jackson ObjectMapper.
    • Constructor Detail

      • JsonMapper

        public JsonMapper()
    • Method Detail

      • parse

        public static <T> T parse​(String json,
                                  Class<T> clazz)
                           throws ParseException
        Converts the specified JSON string to an object of the specified class using the Jackson ObjectMapper.
        Type Parameters:
        T - the type of object to return
        Parameters:
        json - the JSON string
        clazz - the result class
        Returns:
        the result object
        Throws:
        ParseException - if a JSON parsing error occurs
      • parse

        public static <T> T parse​(String json,
                                  com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
                           throws ParseException
        Converts the specified JSON string to an object of the specified result type using the Jackson ObjectMapper.
        Type Parameters:
        T - the type of object to return
        Parameters:
        json - the JSON string
        typeRef - the result type
        Returns:
        the result object
        Throws:
        ParseException - if a JSON parsing error occurs
      • convert

        public static <T> T convert​(Object json,
                                    Class<T> clazz)
                             throws ParseException
        Converts the specified JSON object (the result of parsing JSON code to a basic Java type) to an object of the specified class using the Jackson ObjectMapper.
        Type Parameters:
        T - the type of object to return
        Parameters:
        json - the JSON object
        clazz - the result class
        Returns:
        the result object
        Throws:
        ParseException - if the JSON object can't be converted to the specified class
      • convert

        public static <T> T convert​(Object json,
                                    com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
                             throws ParseException
        Converts the specified JSON object (the result of parsing JSON code to a basic Java type) to an object of the specified result type using the Jackson ObjectMapper.
        Type Parameters:
        T - the type of object to return
        Parameters:
        json - the JSON object
        typeRef - the result type
        Returns:
        the result object
        Throws:
        ParseException - if the JSON object can't be converted to the specified type
      • generate

        public static String generate​(Object obj)
        Generates a JSON string from the specified object. If the object can't be converted to JSON, this method throws a RuntimeException.
        Parameters:
        obj - the object
        Returns:
        the JSON string