Class JsonConverter


  • public class JsonConverter
    extends Object

    Class which encapsulates methods for converting JSON.

    Since:
    0.1.0
    • Constructor Detail

      • JsonConverter

        public JsonConverter()

        Default constructor. Initializes the ObjectMapper needed for converting objects.

    • Method Detail

      • convertValue

        public <T> T convertValue​(Object fromValue,
                                  Class<T> toValueType)

        Converts the specified object to the specified class.

        Type Parameters:
        T - the data type of the list
        Parameters:
        fromValue - the object to convert
        toValueType - the class to convert to
        Returns:
        a converted object
      • toListOf

        public <T> List<T> toListOf​(String json,
                                    Class<T> clazz)

        Converts the JSON string into a list of the specified class.

        Type Parameters:
        T - the data type of the list
        Parameters:
        json - the JSON string to convert
        clazz - the class to convert each JSON entry to
        Returns:
        a list of elements, which type is the specified class. Each element represents the corresponding entry in the JSON
      • toNode

        public com.fasterxml.jackson.databind.JsonNode toNode​(String json)

        Parse the JSON string into a JsonNode object.

        Parameters:
        json - the JSON content
        Returns:
        a JsonNode object
      • toNode

        public com.fasterxml.jackson.databind.JsonNode toNode​(String json,
                                                              String field)

        Parse the JSON string into a JsonNode object with the specified field as root field.

        Parameters:
        json - the JSON content
        field - the field in the JSON to become the root
        Returns:
        a JsonNode object with the specified field as root.