public class JsonTemplateMapper extends 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,
Class<T> templateClass)
Deserializes a JSON object from a JSON byte array.
|
static <T extends JsonTemplate> |
readJson(String jsonString,
Class<T> templateClass)
Deserializes a JSON object from a JSON string.
|
static <T extends JsonTemplate> |
readJsonFromFile(Path jsonFile,
Class<T> templateClass)
Deserializes a JSON file via a JSON object template.
|
static <T extends JsonTemplate> |
readJsonFromFileWithLock(Path jsonFile,
Class<T> templateClass)
Deserializes a JSON file via a JSON object template with a shared lock on the file
|
static <T extends JsonTemplate> |
readListOfJson(String jsonString,
Class<T> templateClass)
Deserializes a JSON object list from a JSON string.
|
static byte[] |
toByteArray(JsonTemplate template) |
static byte[] |
toByteArray(List<? extends JsonTemplate> templates) |
static String |
toUtf8String(JsonTemplate template) |
static String |
toUtf8String(List<? extends JsonTemplate> templates) |
static void |
writeTo(JsonTemplate template,
OutputStream out) |
static void |
writeTo(List<? extends JsonTemplate> templates,
OutputStream out) |
public static <T extends JsonTemplate> T readJsonFromFile(Path jsonFile, Class<T> templateClass) throws IOException
T - child type of JsonTemplatejsonFile - a file containing a JSON stringtemplateClass - the template to deserialize the string tojsonFileIOException - if an error occurred during reading the file or parsing the JSONpublic static <T extends JsonTemplate> T readJsonFromFileWithLock(Path jsonFile, Class<T> templateClass) throws IOException
T - child type of JsonTemplatejsonFile - a file containing a JSON stringtemplateClass - the template to deserialize the string tojsonFileIOException - if an error occurred during reading the file or parsing the JSONpublic static <T extends JsonTemplate> T readJson(String jsonString, Class<T> templateClass) throws IOException
T - child type of JsonTemplatejsonString - a JSON stringtemplateClass - the template to deserialize the string tojsonStringIOException - if an error occurred during parsing the JSONpublic static <T extends JsonTemplate> T readJson(byte[] jsonBytes, Class<T> templateClass) throws IOException
T - child type of JsonTemplatejsonBytes - a JSON byte arraytemplateClass - the template to deserialize the string tojsonBytesIOException - if an error occurred during parsing the JSONpublic static <T extends JsonTemplate> List<T> readListOfJson(String jsonString, Class<T> templateClass) throws IOException
T - child type of JsonTemplatejsonString - a JSON stringtemplateClass - the template to deserialize the string tojsonStringIOException - if an error occurred during parsing the JSONpublic static String toUtf8String(JsonTemplate template) throws IOException
IOExceptionpublic static String toUtf8String(List<? extends JsonTemplate> templates) throws IOException
IOExceptionpublic static byte[] toByteArray(JsonTemplate template) throws IOException
IOExceptionpublic static byte[] toByteArray(List<? extends JsonTemplate> templates) throws IOException
IOExceptionpublic static void writeTo(JsonTemplate template, OutputStream out) throws IOException
IOExceptionpublic static void writeTo(List<? extends JsonTemplate> templates, OutputStream out) throws IOException
IOExceptionCopyright © 2019. All rights reserved.