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> T
convertValue(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.JsonNode
toNode(String json)
Parse the JSON string into aJsonNode
object.com.fasterxml.jackson.databind.JsonNode
toNode(String json, String field)
Parse the JSON string into aJsonNode
object 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
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 contentfield
- the field in the JSON to become the root- Returns:
- a
JsonNode
object with the specified field as root.
-
-