public class JsonConverter extends Object
Class which encapsulates methods for converting JSON.
| Constructor and Description |
|---|
JsonConverter()
Default constructor.
|
| Modifier and Type | Method and 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 a
JsonNode object. |
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. |
public JsonConverter()
Default constructor. Initializes the
ObjectMapper needed for
converting objects.
public <T> T convertValue(Object fromValue, Class<T> toValueType)
Converts the specified object to the specified class.
T - the data type of the listfromValue - the object to converttoValueType - the class to convert topublic <T> List<T> toListOf(String json, Class<T> clazz)
Converts the JSON string into a list of the specified class.
T - the data type of the listjson - the JSON string to convertclazz - the class to convert each JSON entry topublic com.fasterxml.jackson.databind.JsonNode toNode(String json)
Parse the JSON string into a JsonNode object.
json - the JSON contentJsonNode objectpublic 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.
json - the JSON contentfield - the field in the JSON to become the rootJsonNode object with the specified field as root.Copyright © 2019. All rights reserved.