Class JSONPropertyWriter
- java.lang.Object
-
- org.nuxeo.ecm.automation.core.util.JSONPropertyWriter
-
public class JSONPropertyWriter extends Object
Helper to marshaling properties into JSON.- Since:
- 7.1
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceJSONPropertyWriter.PropertyConsumer
-
Field Summary
Fields Modifier and Type Field Description protected DateTimeFormatdateTimeFormatThe date time format.protected StringfilesBaseUrlThe baseUrl that can be used to locate blob content.protected StringprefixThe prefix to append to field name.protected booleanwriteEmptyWhether or not this writer write empty list or object.protected booleanwriteNullWhether or not this writer write null values.
-
Constructor Summary
Constructors Modifier Constructor Description protectedJSONPropertyWriter()Instantiate a JSONPropertyWriter.protectedJSONPropertyWriter(JSONPropertyWriter writer)Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JSONPropertyWritercreate()JSONPropertyWriterdateTimeFormat(DateTimeFormat dateTimeFormat)JSONPropertyWriterfilesBaseUrl(String filesBaseUrl)JSONPropertyWriterprefix(String prefix)protected voidwriteBlobProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter)JSONPropertyWriterwriteEmpty(boolean writeEmpty)protected voidwriteListProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter)protected voidwriteMapProperty(com.fasterxml.jackson.core.JsonGenerator jg, ComplexProperty prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter)JSONPropertyWriterwriteNull(boolean writeNull)voidwriteProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop)Converts the value of the given core property to JSON.protected voidwriteProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter)Converts the value of the given core property to JSON.static voidwritePropertyValue(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, DateTimeFormat dateTimeFormat, String filesBaseUrl)Converts the value of the given core property to JSON.protected voidwriteScalarProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter)
-
-
-
Field Detail
-
dateTimeFormat
protected DateTimeFormat dateTimeFormat
The date time format.- Since:
- 9.1
-
filesBaseUrl
protected String filesBaseUrl
The baseUrl that can be used to locate blob content.- Since:
- 9.1
-
prefix
protected String prefix
The prefix to append to field name.- Since:
- 9.1
-
writeNull
protected boolean writeNull
Whether or not this writer write null values.- Since:
- 9.1
-
writeEmpty
protected boolean writeEmpty
Whether or not this writer write empty list or object.- Since:
- 9.1
-
-
Constructor Detail
-
JSONPropertyWriter
protected JSONPropertyWriter()
Instantiate a JSONPropertyWriter.
-
JSONPropertyWriter
protected JSONPropertyWriter(JSONPropertyWriter writer)
Copy constructor.- Since:
- 9.1
-
-
Method Detail
-
create
public static JSONPropertyWriter create()
- Returns:
- a
JSONPropertyWriterinstance withDateTimeFormat.W3Cas date time formatter. - Since:
- 9.1
-
dateTimeFormat
public JSONPropertyWriter dateTimeFormat(DateTimeFormat dateTimeFormat)
- Returns:
- this
JSONPropertyWriterfilled with the previous configuration and the input dateTimeFormat. - Since:
- 9.1
-
filesBaseUrl
public JSONPropertyWriter filesBaseUrl(String filesBaseUrl)
- Parameters:
filesBaseUrl- the baseUrl that can be used to locate blob content- Returns:
- this
JSONPropertyWriterfilled with the previous configuration and the input filesBaseUrl. - Since:
- 9.1
-
prefix
public JSONPropertyWriter prefix(String prefix)
- Parameters:
prefix- the prefix to append for each property- Returns:
- this
JSONPropertyWriterfilled with the previous configuration and the input prefix. - Since:
- 9.1
-
writeNull
public JSONPropertyWriter writeNull(boolean writeNull)
- Parameters:
writeNull- whether or not this writer might write null values- Returns:
- this
JSONPropertyWriterfilled with the previous configuration and the input writeNull value. - Since:
- 9.1
-
writeEmpty
public JSONPropertyWriter writeEmpty(boolean writeEmpty)
- Parameters:
writeEmpty- whether or not this writer might write empty array/list/object- Returns:
- this
JSONPropertyWriterfilled with the previous configuration and the input writeEmpty value. - Since:
- 9.1
-
writeProperty
public void writeProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop) throws PropertyException, IOExceptionConverts the value of the given core property to JSON.- Throws:
PropertyExceptionIOException- Since:
- 9.1
- Implementation Note:
- CAUTION: this method will write the field name to
JsonGeneratorwith its prefix without writing the start and the end of object.
-
writeProperty
protected void writeProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter) throws PropertyException, IOExceptionConverts the value of the given core property to JSON.- Parameters:
fieldNameWriter- the field name writer is used to write the field name depending on writer configuration, this parameter also allows us to handle different cases: field with prefix, field under complex property, or nothing for arrays and lists- Throws:
PropertyExceptionIOException
-
writeScalarProperty
protected void writeScalarProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter) throws PropertyException, IOException- Throws:
PropertyExceptionIOException
-
writeListProperty
protected void writeListProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter) throws PropertyException, IOException- Throws:
PropertyExceptionIOException
-
writeMapProperty
protected void writeMapProperty(com.fasterxml.jackson.core.JsonGenerator jg, ComplexProperty prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter) throws PropertyException, IOException- Throws:
PropertyExceptionIOException
-
writeBlobProperty
protected void writeBlobProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter) throws PropertyException, IOException- Throws:
PropertyExceptionIOException
-
writePropertyValue
public static void writePropertyValue(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, DateTimeFormat dateTimeFormat, String filesBaseUrl) throws PropertyException, IOExceptionConverts the value of the given core property to JSON. The given filesBaseUrl is the baseUrl that can be used to locate blob content and is useful to generate blob URLs.- Throws:
PropertyExceptionIOException
-
-