public class JSONFormatterPdxToJsonConverter extends JacksonObjectToJsonConverter
ObjectToJsonConverter implementation using the Apache Geode JSONFormatter to convert
from a PdxInstance to a JSON String.JsonNode,
ObjectMapper,
ObjectNode,
JSONFormatter,
PdxInstance,
WritablePdxInstance,
ObjectToJsonConverter,
JacksonObjectToJsonConverter,
PdxInstanceBuilderAT_TYPE_METADATA_PROPERTY_NAME| Constructor and Description |
|---|
JSONFormatterPdxToJsonConverter() |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
convert(java.lang.Object source)
Converts the given
Object into JSON. |
protected java.lang.String |
convertPdxToJson(org.apache.geode.pdx.PdxInstance pdxInstance)
Converts the given
PDX to JSON. |
protected java.lang.String |
convertPojoToJson(java.lang.Object source)
Converts the given
Object to JSON. |
protected org.apache.geode.pdx.PdxInstance |
decorate(org.apache.geode.pdx.PdxInstance pdxInstance)
WARNING!!!
First, this method might be less than optimal and could lead to PDX type explosion!
Second, this
pdxInstance.createWriter().setField(AT_TYPE_METADATA_PROPERTY_NAME, className); ... |
protected java.lang.String |
decorate(org.apache.geode.pdx.PdxInstance pdxInstance,
java.lang.String json)
Decorates the given
JSON to include the @type metadata property in order to
indicate the type of the JSON object, which is required for deserialization back to PDX. |
convertObjectToJson, newObjectMapper@Nullable
public final java.lang.String convert(@Nullable
java.lang.Object source)
JacksonObjectToJsonConverterObject into JSON.convert in interface org.springframework.core.convert.converter.Converter<java.lang.Object,java.lang.String>convert in class JacksonObjectToJsonConvertersource - Object to convert into JSON.JSON generated from the given Object using Jackson's ObjectMapper.ObjectMapper,
JacksonObjectToJsonConverter.convertObjectToJson(Object)@Nullable protected java.lang.String convertPojoToJson(java.lang.Object source)
Object to JSON.source - Object to convert to JSON.Object.JacksonObjectToJsonConverter.convert(Object)@NonNull
protected java.lang.String convertPdxToJson(@NonNull
org.apache.geode.pdx.PdxInstance pdxInstance)
PDX to JSON.pdxInstance - PdxInstance to convert to JSON; must not be null.PdxInstance.JSONFormatter.toJSON(PdxInstance),
PdxInstance,
jsonFormatterToJson(PdxInstance)@NonNull
protected org.apache.geode.pdx.PdxInstance decorate(@NonNull
org.apache.geode.pdx.PdxInstance pdxInstance)
pdxInstance.createWriter().setField(AT_TYPE_METADATA_PROPERTY_NAME, className); ...
Throws:
org.apache.geode.pdx.PdxFieldDoesNotExistException: A field named @type does not exist on ...
PdxType[dsid=0,typenum=7232261,name=example.app.crm.model.Customer,fields=[id:long:identity:0:idx0(relativeOffset)=0:idx1(vlfOffsetIndex)=0, name:String:1:idx0(relativeOffset)=8:idx1(vlfOffsetIndex)=-1,]]
at org.apache.geode.pdx.internal.WritablePdxInstanceImpl.setField(WritablePdxInstanceImpl.java:119)
...
This code needs to create a new PdxInstance from an existing PdxInstance
or add the new (PDX) field to the PDX type metadata using PdxType.addField(:PdxField) before
setting the new field on the PdxInstance using the WritablePdxInstance. Unfortunately,
PdxType is part of the internal API and updating and ditributing a PdxType is complicated,
requiring a Distributed Lock, among other responsibilities.@NonNull
protected java.lang.String decorate(@NonNull
org.apache.geode.pdx.PdxInstance pdxInstance,
@NonNull
java.lang.String json)
JSON to include the @type metadata property in order to
indicate the type of the JSON object, which is required for deserialization back to PDX.
If an JsonProcessingException is thrown during this operation and if the PdxInstance
has a valid class name, then an attempt is made to serialize
the object instance of the PdxInstance to JSON
using Jackson's ObjectMapper.pdxInstance - required PdxInstance from which the JSON was serialized;
must not be null.json - JSON generated from the serialization of the PdxInstance;
must not be null.JSON including the @type metadata property.org.springframework.dao.DataRetrievalFailureException - if JSON cannot be decorated with type metadata
and the PdxInstance is not based on a valid Class type.JacksonObjectToJsonConverter.convert(Object),
PdxInstance,
JacksonObjectToJsonConverter.newObjectMapper(Object)