Class JSON


  • public class JSON
    extends Object
    The primary class that should be used for performing any JSON serialization/deserialization. This class is built on top of Jackson's ObjectMapper and thus honors standard Jackson annotations to control serialization/deserialization. In addition, this class searches for types registered via TypeResolutionProvider.
    • Constructor Detail

      • JSON

        public JSON()
        Create a new JSON instance.
    • Method Detail

      • relaxStandard

        public void relaxStandard()
        Relax the JSON standard while parsing. Allow unquoted field names and single quotes around values.
      • parse

        public <T> T parse​(Reader src,
                           Class<T> asClass)
        Parses the given reader as a JSON object of the given type
        Type Parameters:
        T - the type to parse as
        Parameters:
        src - the reader
        asClass - the type to parse as
        Returns:
        an object of the requested type
      • parse

        public <T> T parse​(String json,
                           Class<T> asClass)
        Parses the given string as a JSON object of the given type
        Type Parameters:
        T - the type to parse as
        Parameters:
        json - the string
        asClass - the type to parse as
        Returns:
        an object of the requested type
      • format

        public String format​(Object obj)
        Formats the object as JSON
        Parameters:
        obj - the object to format
        Returns:
        the object, formatted as JSON
      • prettyPrint

        public String prettyPrint​(Object obj)
        Pretty-prints the object as JSON
        Parameters:
        obj - the object to format
        Returns:
        the object, formatted as JSON