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(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 Blob |
toBlob(JsonTemplate template)
Convert a
JsonTemplate to a Blob of the JSON string. |
static Blob |
toBlob(List<? extends JsonTemplate> templates)
Convert a list of
JsonTemplate to a Blob of the JSON string. |
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> 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 Blob toBlob(JsonTemplate template)
JsonTemplate to a Blob of the JSON string.template - the JSON template to convertBlob of the JSON stringpublic static Blob toBlob(List<? extends JsonTemplate> templates)
JsonTemplate to a Blob of the JSON string.templates - the list of JSON templates to convertBlob of the JSON stringCopyright © 2019. All rights reserved.