Class JsonConverter
- java.lang.Object
-
- com.github.dannil.scbjavaclient.format.json.JsonConverter
-
public class JsonConverter extends Object
Class which encapsulates methods for converting JSON.
- Since:
- 0.1.0
-
-
Constructor Summary
Constructors Constructor Description JsonConverter()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> TconvertValue(Object fromValue, Class<T> toValueType)Converts the specified object to the specified class.<T> List<T>toListOf(String json, Class<T> clazz)Converts the JSON string into a list of the specified class.com.fasterxml.jackson.databind.JsonNodetoNode(String json)Parse the JSON string into aJsonNodeobject.com.fasterxml.jackson.databind.JsonNodetoNode(String json, String field)Parse the JSON string into aJsonNodeobject with the specified field as root field.
-
-
-
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 converttoValueType- 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 convertclazz- 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
JsonNodeobject.- Parameters:
json- the JSON content- Returns:
- a
JsonNodeobject
-
toNode
public com.fasterxml.jackson.databind.JsonNode toNode(String json, String field)
Parse the JSON string into a
JsonNodeobject with the specified field as root field.- Parameters:
json- the JSON contentfield- the field in the JSON to become the root- Returns:
- a
JsonNodeobject with the specified field as root.
-
-