Package nl.rrd.wool.json
Class JsonMapper
- java.lang.Object
-
- nl.rrd.wool.json.JsonMapper
-
public class JsonMapper extends Object
-
-
Constructor Summary
Constructors Constructor Description JsonMapper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tconvert(Object json, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)Converts the specified JSON object (the result of parsing JSON code to a basic Java type) to an object of the specified result type using the JacksonObjectMapper.static <T> Tconvert(Object json, Class<T> clazz)Converts the specified JSON object (the result of parsing JSON code to a basic Java type) to an object of the specified class using the JacksonObjectMapper.static Stringgenerate(Object obj)Generates a JSON string from the specified object.static <T> Tparse(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)Converts the specified JSON string to an object of the specified result type using the JacksonObjectMapper.static <T> Tparse(String json, Class<T> clazz)Converts the specified JSON string to an object of the specified class using the JacksonObjectMapper.
-
-
-
Method Detail
-
parse
public static <T> T parse(String json, Class<T> clazz) throws ParseException
Converts the specified JSON string to an object of the specified class using the JacksonObjectMapper.- Type Parameters:
T- the type of object to return- Parameters:
json- the JSON stringclazz- the result class- Returns:
- the result object
- Throws:
ParseException- if a JSON parsing error occurs
-
parse
public static <T> T parse(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) throws ParseException
Converts the specified JSON string to an object of the specified result type using the JacksonObjectMapper.- Type Parameters:
T- the type of object to return- Parameters:
json- the JSON stringtypeRef- the result type- Returns:
- the result object
- Throws:
ParseException- if a JSON parsing error occurs
-
convert
public static <T> T convert(Object json, Class<T> clazz) throws ParseException
Converts the specified JSON object (the result of parsing JSON code to a basic Java type) to an object of the specified class using the JacksonObjectMapper.- Type Parameters:
T- the type of object to return- Parameters:
json- the JSON objectclazz- the result class- Returns:
- the result object
- Throws:
ParseException- if the JSON object can't be converted to the specified class
-
convert
public static <T> T convert(Object json, com.fasterxml.jackson.core.type.TypeReference<T> typeRef) throws ParseException
Converts the specified JSON object (the result of parsing JSON code to a basic Java type) to an object of the specified result type using the JacksonObjectMapper.- Type Parameters:
T- the type of object to return- Parameters:
json- the JSON objecttypeRef- the result type- Returns:
- the result object
- Throws:
ParseException- if the JSON object can't be converted to the specified type
-
generate
public static String generate(Object obj)
Generates a JSON string from the specified object. If the object can't be converted to JSON, this method throws aRuntimeException.- Parameters:
obj- the object- Returns:
- the JSON string
-
-