public final class JsonExport
extends java.lang.Object
Runtime support is partial at this time; not all modes and features are supported.
Modifier and Type | Class and Description |
---|---|
private static interface |
JsonExport.ThrowingConsumer
A consumer which accepts one value and throws IOException, to avoid having to handle this
exception in every defined lambda expression.
|
Modifier and Type | Field and Description |
---|---|
private java.util.Map<java.lang.Class<? extends BaseDataType>,JsonExport.ThrowingConsumer> |
fnMap
Map of data types to functions which write JSON values
|
private static java.util.logging.Logger |
LOG
Logger
|
Constructor and Description |
---|
JsonExport() |
Modifier and Type | Method and Description |
---|---|
private void |
addPropertyToJson(JsonObject dest,
TempTableSchema.Column column,
BaseDataType datum)
Adds a value as a new property to a JSON object.
|
private void |
addPropertyToJsonArray(JsonArray dest,
TempTableSchema.Column column,
BaseDataType datum)
Adds a value as a new indexed property in JSON array object.
|
private object<? extends JsonObject> |
asJsonObject(TempRecord dmo,
TempTableSchema schema)
Creates a new JSON Object starting from the information which can be found in the buffer sent as
parameter.
|
private boolean |
checkSupportedTypes(TempTableSchema schema)
Checks supported data types.
|
private void |
clearObject(JsonConstruct json)
Resets a
JsonConstruct object by dropping all its properties or elements. |
void |
exportDataSet(DataSet dataSet,
boolean noInit,
boolean noOuter,
boolean beforeImage,
JsonStructureCallback json)
Constructor specific to DATASET serialization.
|
boolean |
exportDataSet(DataSet dataSet,
TargetData target,
boolean pretty,
com.fasterxml.jackson.core.JsonEncoding encoding,
boolean noInit,
boolean noOuter,
boolean beforeImage)
Constructor specific to DATASET serialization.
|
boolean |
exportRecord(BufferImpl bufferImpl,
TargetData targetData,
boolean formatted,
com.fasterxml.jackson.core.JsonEncoding jsonEncoding,
boolean omitInitial,
boolean omitOuter)
Exports a single record in JSON format.
|
void |
exportTempBuffer(TemporaryBuffer buffer,
logical omitInitialValues,
logical omitOuterObject,
JsonStructureCallback json)
Serializes TEMP-TABLE to json.
|
boolean |
exportTempBuffer(TemporaryBuffer buffer,
TargetData target,
logical formatted,
com.fasterxml.jackson.core.JsonEncoding encoding,
logical omitInitialValues,
logical omitOuterObject)
Serializes TEMP-TABLE to json.
|
static com.fasterxml.jackson.core.JsonEncoding |
parseEncoding(character encoding)
Encoding for JSON string
|
void |
serializeDataSet(JsonStructureCallback json,
DataSet dataSet,
boolean noInit,
boolean noOuter,
boolean beforeImage)
Constructor specific to DATASET serialization in a JSON Object.
|
static object<? extends JsonObject> |
serializeError(object<? extends LegacyError> _poError)
Serialize 4GL legacy error as Json object.
|
boolean |
serializeRecord(JsonStructureCallback json,
TemporaryBuffer buffer,
boolean noInit)
Actual implementation of a temp-table buffer serialization into a JsonArray (only current row).
|
private boolean |
serializeTempTable(JsonStructureCallback json,
DataRelation relation,
TemporaryBuffer buffer,
java.lang.String overrideBeforeName,
boolean noInit,
boolean omitOuter,
boolean hiddenFields,
boolean dsFlags,
boolean dsBeforeImage)
Actual implementation of a table serialization.
|
boolean |
serializeTempTable(JsonStructureCallback json,
TemporaryBuffer buffer,
boolean omitOuter,
boolean noInit)
Actual implementation of a table serialization into a JsonArray (only rows).
|
private boolean |
writeDatasetToJson(DataSet dataSet,
TargetData target)
Write the content of the whole dataset to the destination JSON object found in target.
|
private boolean |
writeDatum(JsonStructureCallback json,
TempTableSchema.Column column,
Record dmo,
java.lang.Integer index)
Write a single data value to the JSON generator's output stream, according to the
instructions stored in the temp-table schema.
|
private void |
writeRecord(JsonStructureCallback json,
TemporaryBuffer buffer,
TempRecord dmo,
TempTableSchema schema,
java.lang.String rowName,
boolean hiddenFields,
boolean dsFlags,
boolean skipCreateFields,
boolean dsBeforeImage,
boolean noInit)
Serialize a single record to the JSON output.
|
private boolean |
writeRecord(JsonStructureCallback json,
TempRecord dmo,
TempTableSchema schema,
boolean hiddenFields,
boolean noInit)
Serialize a single buffer record to the JSON output.
|
private boolean |
writeRecordToJson(BufferImpl buffer,
TargetData target,
TempTableSchema schema)
Populate the JSON object target with data from the buffer.
|
private void |
writeRowid(JsonStructureCallback json,
java.lang.String name,
java.lang.Long rowidAsLong)
Write a single data value of type
rowid passed as a long value, along with its field
name. |
private boolean |
writeTableToJson(TemporaryBuffer buffer,
TargetData target)
Write the content of the whole table to the destination JSON object found in target.
|
private static final java.util.logging.Logger LOG
private final java.util.Map<java.lang.Class<? extends BaseDataType>,JsonExport.ThrowingConsumer> fnMap
public static com.fasterxml.jackson.core.JsonEncoding parseEncoding(character encoding)
public boolean exportDataSet(DataSet dataSet, TargetData target, boolean pretty, com.fasterxml.jackson.core.JsonEncoding encoding, boolean noInit, boolean noOuter, boolean beforeImage) throws PersistenceException
dataSet
- The target object to be serialized.target
- Data target.pretty
- True
to format the JSON to make it more readable; false
to write it
as unformatted text.encoding
- The encoding to use.noInit
- True
to omit data for fields whose values match their initial values.noOuter
- True
to omit data for the outermost object from the output.beforeImage
- True
to write before-image data and error information, else false
.true
on success and false
otherwise.PersistenceException
- On persistence issues.public void exportDataSet(DataSet dataSet, boolean noInit, boolean noOuter, boolean beforeImage, JsonStructureCallback json) throws PersistenceException
dataSet
- The target object to be serialized.noInit
- True
to omit data for fields whose values match their initial values.noOuter
- True
to omit data for the outermost object from the output.beforeImage
- True
to write before-image data and error information, else false
.json
- This is the target for the deserialized json data.PersistenceException
- On persistence issues.public boolean exportTempBuffer(TemporaryBuffer buffer, TargetData target, logical formatted, com.fasterxml.jackson.core.JsonEncoding encoding, logical omitInitialValues, logical omitOuterObject) throws PersistenceException
buffer
- Temp-table buffer in which data is stored.target
- Data target.formatted
- True
to format the JSON to make it more readable; false
to write it
as unformatted text. Unknown value is treated as false
.encoding
- The JSON encoding to use.omitInitialValues
- True
to omit data for fields whose values match their initial values.omitOuterObject
- True
to omit data for the outermost object from the output.true
on success.PersistenceException
- On persistence issues.public void exportTempBuffer(TemporaryBuffer buffer, logical omitInitialValues, logical omitOuterObject, JsonStructureCallback json) throws PersistenceException
buffer
- Temp-table buffer in which data is stored.omitInitialValues
- True
to omit data for fields whose values match their initial values.omitOuterObject
- True
to omit data for the outermost object from the output.json
- This is the target for the deserialized json data.PersistenceException
- On persistence issues.public boolean exportRecord(BufferImpl bufferImpl, TargetData targetData, boolean formatted, com.fasterxml.jackson.core.JsonEncoding jsonEncoding, boolean omitInitial, boolean omitOuter)
bufferImpl
- The buffer holding the record to be exported.targetData
- The output structure.formatted
- Use true
to have a pretty output. Otherwise, the output is generated on a single line.jsonEncoding
- The encoding to be used.omitInitial
- If true
the initial/default values are skipped.omitOuter
- Omit outer values.private boolean writeRecordToJson(BufferImpl buffer, TargetData target, TempTableSchema schema)
buffer
- The buffer containing data.target
- The object containing JSON target.schema
- The schema used for operation.true
if the operation is successful.private void clearObject(JsonConstruct json)
JsonConstruct
object by dropping all its properties or elements.
TODO: optimize this by providing a method to clear the [properties]/[elements] member of the [json]
json
- The object to be reset.private boolean writeTableToJson(TemporaryBuffer buffer, TargetData target)
buffer
- The buffer whose table is to be saved to JSON object.target
- The target which contains the destination object.true
on success.private object<? extends JsonObject> asJsonObject(TempRecord dmo, TempTableSchema schema)
dmo
- The record which contains the data to be used for creating the object to be returned.schema
- Metadata information about the structure of the record.null
on error.private void addPropertyToJson(JsonObject dest, TempTableSchema.Column column, BaseDataType datum)
dest
- The destination JSON object.column
- The column which provides the type and name of the property.datum
- The actual data to be set as property's value.private void addPropertyToJsonArray(JsonArray dest, TempTableSchema.Column column, BaseDataType datum)
dest
- The destination JSON array object.column
- The column which provides the type of the property.datum
- The actual data to be set as property's value.private boolean writeDatasetToJson(DataSet dataSet, TargetData target)
dataSet
- The buffer whose table is to be saved to JSON object.target
- The target which contains the destination object.true
on success.private boolean serializeTempTable(JsonStructureCallback json, DataRelation relation, TemporaryBuffer buffer, java.lang.String overrideBeforeName, boolean noInit, boolean omitOuter, boolean hiddenFields, boolean dsFlags, boolean dsBeforeImage) throws java.io.IOException
json
- The target of the deserialized json data.relation
- The relation on which this buffer is a child of.buffer
- A buffer of the temp-table to be serialized.overrideBeforeName
- Overrides the name of the table. The BEFORE-TABLE data is serialized under the name
of the main (AFTER) buffer.noInit
- Skip the initial values.omitOuter
- True
to omit data for the outermost object from the output.hiddenFields
- true
to add the internal flags specific to BEFORE-BUFFER records.dsFlags
- true
to add the internal flags specific to DataSet TempTable records.dsBeforeImage
- true
to write the before-image if available.true
if everything went fine, and false
if a non-fatal error was encounteredjava.io.IOException
- If exceptions occur during the serialization.public boolean serializeTempTable(JsonStructureCallback json, TemporaryBuffer buffer, boolean omitOuter, boolean noInit) throws java.io.IOException
json
- The target of the deserialized json data.buffer
- A buffer of the temp-table to be serialized.omitOuter
- True
to omit data for the outermost object from the output.noInit
- Skip the initial values.java.io.IOException
- If exceptions occur during the serialization.public boolean serializeRecord(JsonStructureCallback json, TemporaryBuffer buffer, boolean noInit) throws java.io.IOException
json
- The target of the deserialized json data.buffer
- A buffer record to be serialized.noInit
- Skip the initial values.java.io.IOException
- If exceptions occur during the serialization.public void serializeDataSet(JsonStructureCallback json, DataSet dataSet, boolean noInit, boolean noOuter, boolean beforeImage) throws java.io.IOException
json
- This is the target for the deserialized json data.dataSet
- The target object to be serialized.noInit
- True
to omit data for fields whose values match their initial values.noOuter
- True
to omit data for the outermost object from the output.beforeImage
- True
to write before-image data and error information, else false
.PersistenceException
- On persistence issues.java.io.IOException
private void writeRecord(JsonStructureCallback json, TemporaryBuffer buffer, TempRecord dmo, TempTableSchema schema, java.lang.String rowName, boolean hiddenFields, boolean dsFlags, boolean skipCreateFields, boolean dsBeforeImage, boolean noInit)
json
- Target of the deserialized json data.buffer
- The buffer to which the DMO belongs.dmo
- DMO representing the record.schema
- The temp-table schema.hiddenFields
- Write the hidden fields (__ERROR_FLAG__
, __ORIGIN_ROWID__
,
__ERROR_STRING__
, __AFTER_ROWID__
, __ROW_STATE__
).dsFlags
- true
to add the internal flags specific to DataSet TempTable records.skipCreateFields
- true
to skip CREATED records in before table.dsBeforeImage
- true
to write the before-image if available.noInit
- Flag indicating the initial values are to be omitted.private boolean writeRecord(JsonStructureCallback json, TempRecord dmo, TempTableSchema schema, boolean hiddenFields, boolean noInit) throws java.io.IOException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException
json
- Target of the deserialized json data.dmo
- DMO representing the record.schema
- The temp-table schema.hiddenFields
- Write the hidden fields (__ERROR_FLAG__
, __ORIGIN_ROWID__
,
__ERROR_STRING__
, __AFTER_ROWID__
, __ROW_STATE__
).noInit
- Flag indicating the initial values are to be omitted.java.io.IOException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
private boolean checkSupportedTypes(TempTableSchema schema)
Util.checkSupportedTypes()
.
The method returns true
and prints an error messages is unsupported types are detected.true
if a type problem was discovered.private boolean writeDatum(JsonStructureCallback json, TempTableSchema.Column column, Record dmo, java.lang.Integer index) throws java.io.IOException, java.lang.IllegalAccessException, java.lang.IllegalArgumentException, java.lang.reflect.InvocationTargetException
json
- Target of the deserialized json data.column
- Temp-table column schema information.dmo
- DMO containing datum associated with the specified column.index
- Zero-based index of an extent field element. Should be null
for a scalar field.false
on errors. The error was already reported through ErrorManager
.java.io.IOException
- if the JSON generator cannot write data.java.lang.reflect.InvocationTargetException
- if the method invoked to get the data from the DMO fails.java.lang.IllegalArgumentException
- if an argument passed to a DMO getter is invalid.java.lang.IllegalAccessException
- if there is an access/security problem.private void writeRowid(JsonStructureCallback json, java.lang.String name, java.lang.Long rowidAsLong) throws java.io.IOException
rowid
passed as a long value, along with its field
name.json
- Target of the deserialized json data.name
- The name of the field.rowidAsLong
- The rowid
value as Long
.java.io.IOException
public static object<? extends JsonObject> serializeError(object<? extends LegacyError> _poError)
_poError
- The 4GL legacy error.