public class JsonTemplateMapper
extends java.lang.Object
The interface uses Jackson as the JSON parser. Some useful annotations to include on classes used as templates for JSON are:
@JsonInclude(JsonInclude.Include.NON_NULL)
null
.
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
Modifier and Type | Method and Description |
---|---|
static <T extends JsonTemplate> |
readJson(byte[] jsonBytes,
java.lang.Class<T> templateClass)
Deserializes a JSON object from a JSON byte array.
|
static <T extends JsonTemplate> |
readJson(java.io.InputStream jsonStream,
java.lang.Class<T> templateClass)
Deserializes a JSON object from a JSON input stream.
|
static <T extends JsonTemplate> |
readJson(java.lang.String jsonString,
java.lang.Class<T> templateClass)
Deserializes a JSON object from a JSON string.
|
static <T extends JsonTemplate> |
readJsonFromFile(java.nio.file.Path jsonFile,
java.lang.Class<T> templateClass)
Deserializes a JSON file via a JSON object template.
|
static <T extends JsonTemplate> |
readJsonFromFileWithLock(java.nio.file.Path jsonFile,
java.lang.Class<T> templateClass)
Deserializes a JSON file via a JSON object template with a shared lock on the file
|
static <T extends JsonTemplate> |
readListOfJson(java.lang.String jsonString,
java.lang.Class<T> templateClass)
Deserializes a JSON object list from a JSON string.
|
static byte[] |
toByteArray(JsonTemplate template) |
static byte[] |
toByteArray(java.util.List<? extends JsonTemplate> templates) |
static java.lang.String |
toUtf8String(JsonTemplate template) |
static java.lang.String |
toUtf8String(java.util.List<? extends JsonTemplate> templates) |
static void |
writeTo(JsonTemplate template,
java.io.OutputStream out) |
static void |
writeTo(java.util.List<? extends JsonTemplate> templates,
java.io.OutputStream out) |
public static <T extends JsonTemplate> T readJsonFromFile(java.nio.file.Path jsonFile, java.lang.Class<T> templateClass) throws java.io.IOException
T
- child type of JsonTemplate
jsonFile
- a file containing a JSON stringtemplateClass
- the template to deserialize the string tojsonFile
java.io.IOException
- if an error occurred during reading the file or parsing the JSONpublic static <T extends JsonTemplate> T readJsonFromFileWithLock(java.nio.file.Path jsonFile, java.lang.Class<T> templateClass) throws java.io.IOException
T
- child type of JsonTemplate
jsonFile
- a file containing a JSON stringtemplateClass
- the template to deserialize the string tojsonFile
java.io.IOException
- if an error occurred during reading the file or parsing the JSONpublic static <T extends JsonTemplate> T readJson(java.io.InputStream jsonStream, java.lang.Class<T> templateClass) throws java.io.IOException
T
- child type of JsonTemplate
jsonStream
- input streamtemplateClass
- the template to deserialize the string tojsonString
java.io.IOException
- if an error occurred during parsing the JSONpublic static <T extends JsonTemplate> T readJson(java.lang.String jsonString, java.lang.Class<T> templateClass) throws java.io.IOException
T
- child type of JsonTemplate
jsonString
- a JSON stringtemplateClass
- the template to deserialize the string tojsonString
java.io.IOException
- if an error occurred during parsing the JSONpublic static <T extends JsonTemplate> T readJson(byte[] jsonBytes, java.lang.Class<T> templateClass) throws java.io.IOException
T
- child type of JsonTemplate
jsonBytes
- a JSON byte arraytemplateClass
- the template to deserialize the string tojsonBytes
java.io.IOException
- if an error occurred during parsing the JSONpublic static <T extends JsonTemplate> java.util.List<T> readListOfJson(java.lang.String jsonString, java.lang.Class<T> templateClass) throws java.io.IOException
T
- child type of JsonTemplate
jsonString
- a JSON stringtemplateClass
- the template to deserialize the string tojsonString
java.io.IOException
- if an error occurred during parsing the JSONpublic static java.lang.String toUtf8String(JsonTemplate template) throws java.io.IOException
java.io.IOException
public static java.lang.String toUtf8String(java.util.List<? extends JsonTemplate> templates) throws java.io.IOException
java.io.IOException
public static byte[] toByteArray(JsonTemplate template) throws java.io.IOException
java.io.IOException
public static byte[] toByteArray(java.util.List<? extends JsonTemplate> templates) throws java.io.IOException
java.io.IOException
public static void writeTo(JsonTemplate template, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static void writeTo(java.util.List<? extends JsonTemplate> templates, java.io.OutputStream out) throws java.io.IOException
java.io.IOException