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(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 Blob |
toBlob(JsonTemplate template)
Convert a
JsonTemplate to a Blob of the JSON string. |
static Blob |
toBlob(java.util.List<? extends JsonTemplate> templates)
Convert a list of
JsonTemplate to a Blob of the JSON string. |
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.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> 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 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(java.util.List<? extends JsonTemplate> templates)
JsonTemplate
to a Blob
of the JSON string.templates
- the list of JSON templates to convertBlob
of the JSON string