Class JSONFormatterPdxToJsonConverter
java.lang.Object
org.springframework.geode.data.json.converter.support.JacksonObjectToJsonConverter
org.springframework.geode.data.json.converter.support.JSONFormatterPdxToJsonConverter
- All Implemented Interfaces:
org.springframework.core.convert.converter.Converter<Object,
,String> ObjectToJsonConverter
An
ObjectToJsonConverter
implementation using the Apache Geode JSONFormatter
to convert
from a PdxInstance
to a JSON String
.- Since:
- 1.3.0
- See Also:
-
JsonNode
ObjectMapper
ObjectNode
JSONFormatter
PdxInstance
WritablePdxInstance
ObjectToJsonConverter
JacksonObjectToJsonConverter
PdxInstanceBuilder
-
Field Summary
Fields inherited from class org.springframework.geode.data.json.converter.support.JacksonObjectToJsonConverter
AT_TYPE_METADATA_PROPERTY_NAME
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal String
protected String
convertPdxToJson
(org.apache.geode.pdx.PdxInstance pdxInstance) Converts the givenPDX
toJSON
.protected String
convertPojoToJson
(Object source) Converts the givenObject
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, thispdxInstance.createWriter().setField(AT_TYPE_METADATA_PROPERTY_NAME, className);
...protected String
Decorates the givenJSON
to include the @type metadata property in order to indicate the type of the JSON object, which is required for deserialization back to PDX.Methods inherited from class org.springframework.geode.data.json.converter.support.JacksonObjectToJsonConverter
convertObjectToJson, newObjectMapper
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.core.convert.converter.Converter
andThen
-
Constructor Details
-
JSONFormatterPdxToJsonConverter
public JSONFormatterPdxToJsonConverter()
-
-
Method Details
-
convert
Description copied from class:JacksonObjectToJsonConverter
-
convertPojoToJson
Converts the givenObject
to JSON. -
convertPdxToJson
Converts the givenPDX
toJSON
.- Parameters:
pdxInstance
-PdxInstance
to convert to JSON; must not be null.- Returns:
- JSON generated from the given
PdxInstance
. - See Also:
-
JSONFormatter.toJSON(PdxInstance)
PdxInstance
jsonFormatterToJson(PdxInstance)
-
decorate
@NonNull protected org.apache.geode.pdx.PdxInstance decorate(@NonNull org.apache.geode.pdx.PdxInstance pdxInstance) WARNING!!! First, this method might be less than optimal and could lead to PDX type explosion! Second, thispdxInstance.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 newPdxInstance
from an existingPdxInstance
or add the new (PDX) field to the PDX type metadata usingPdxType.addField(:PdxField)
before setting the new field on thePdxInstance
using theWritablePdxInstance
. Unfortunately,PdxType
is part of the internal API and updating and ditributing aPdxType
is complicated, requiring a Distributed Lock, among other responsibilities. -
decorate
@NonNull protected String decorate(@NonNull org.apache.geode.pdx.PdxInstance pdxInstance, @NonNull String json) Decorates the givenJSON
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 anJsonProcessingException
is thrown during this operation and if thePdxInstance
has avalid class name
, then an attempt is made to serialize theobject instance
of thePdxInstance
toJSON
using Jackson'sObjectMapper
.- Parameters:
pdxInstance
- requiredPdxInstance
from which theJSON
was serialized; must not be null.json
-JSON
generated from the serialization of thePdxInstance
; must not be null.- Returns:
- the decorated
JSON
including the @type metadata property. - Throws:
org.springframework.dao.DataRetrievalFailureException
- ifJSON
cannot be decorated with type metadata and thePdxInstance
is not based on a validClass
type.- See Also:
-