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 interface
JSONPropertyWriter.PropertyConsumer
-
Field Summary
Fields Modifier and Type Field Description protected DateTimeFormat
dateTimeFormat
The date time format.protected String
filesBaseUrl
The baseUrl that can be used to locate blob content.protected String
prefix
The prefix to append to field name.protected boolean
writeEmpty
Whether or not this writer write empty list or object.protected boolean
writeNull
Whether or not this writer write null values.
-
Constructor Summary
Constructors Modifier Constructor Description protected
JSONPropertyWriter()
Instantiate a JSONPropertyWriter.protected
JSONPropertyWriter(JSONPropertyWriter writer)
Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JSONPropertyWriter
create()
JSONPropertyWriter
dateTimeFormat(DateTimeFormat dateTimeFormat)
JSONPropertyWriter
filesBaseUrl(String filesBaseUrl)
JSONPropertyWriter
prefix(String prefix)
protected void
writeBlobProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter)
JSONPropertyWriter
writeEmpty(boolean writeEmpty)
protected void
writeListProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter)
protected void
writeMapProperty(com.fasterxml.jackson.core.JsonGenerator jg, ComplexProperty prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter)
JSONPropertyWriter
writeNull(boolean writeNull)
void
writeProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop)
Converts the value of the given core property to JSON.protected void
writeProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter)
Converts the value of the given core property to JSON.static void
writePropertyValue(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, DateTimeFormat dateTimeFormat, String filesBaseUrl)
Converts the value of the given core property to JSON.protected void
writeScalarProperty(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
JSONPropertyWriter
instance withDateTimeFormat.W3C
as date time formatter. - Since:
- 9.1
-
dateTimeFormat
public JSONPropertyWriter dateTimeFormat(DateTimeFormat dateTimeFormat)
- Returns:
- this
JSONPropertyWriter
filled 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
JSONPropertyWriter
filled 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
JSONPropertyWriter
filled 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
JSONPropertyWriter
filled 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
JSONPropertyWriter
filled 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, IOException
Converts the value of the given core property to JSON.- Throws:
PropertyException
IOException
- Since:
- 9.1
- Implementation Note:
- CAUTION: this method will write the field name to
JsonGenerator
with 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, IOException
Converts 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:
PropertyException
IOException
-
writeScalarProperty
protected void writeScalarProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter) throws PropertyException, IOException
- Throws:
PropertyException
IOException
-
writeListProperty
protected void writeListProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter) throws PropertyException, IOException
- Throws:
PropertyException
IOException
-
writeMapProperty
protected void writeMapProperty(com.fasterxml.jackson.core.JsonGenerator jg, ComplexProperty prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter) throws PropertyException, IOException
- Throws:
PropertyException
IOException
-
writeBlobProperty
protected void writeBlobProperty(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, JSONPropertyWriter.PropertyConsumer fieldNameWriter) throws PropertyException, IOException
- Throws:
PropertyException
IOException
-
writePropertyValue
public static void writePropertyValue(com.fasterxml.jackson.core.JsonGenerator jg, Property prop, DateTimeFormat dateTimeFormat, String filesBaseUrl) throws PropertyException, IOException
Converts 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:
PropertyException
IOException
-
-