Spring Boot for VMware GemFire
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:
-
JsonNodeObjectMapperObjectNodeJSONFormatterPdxInstanceWritablePdxInstanceObjectToJsonConverterJacksonObjectToJsonConverterPdxInstanceBuilder
-
Field Summary
Fields inherited from class org.springframework.geode.data.json.converter.support.JacksonObjectToJsonConverter
AT_TYPE_METADATA_PROPERTY_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal Stringprotected StringconvertPdxToJson(org.apache.geode.pdx.PdxInstance pdxInstance) Converts the givenPDXtoJSON.protected StringconvertPojoToJson(Object source) Converts the givenObjectto JSON.protected org.apache.geode.pdx.PdxInstancedecorate(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 StringDecorates the givenJSONto 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, newObjectMapperMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.core.convert.converter.Converter
andThen
-
Constructor Details
-
JSONFormatterPdxToJsonConverter
public JSONFormatterPdxToJsonConverter()
-
-
Method Details
-
convert
-
convertPojoToJson
Converts the givenObjectto JSON. -
convertPdxToJson
Converts the givenPDXtoJSON.- Parameters:
pdxInstance-PdxInstanceto convert to JSON; must not be null.- Returns:
- JSON generated from the given
PdxInstance. - See Also:
-
JSONFormatter.toJSON(PdxInstance)PdxInstancejsonFormatterToJson(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 newPdxInstancefrom an existingPdxInstanceor add the new (PDX) field to the PDX type metadata usingPdxType.addField(:PdxField)before setting the new field on thePdxInstanceusing theWritablePdxInstance. Unfortunately,PdxTypeis part of the internal API and updating and ditributing aPdxTypeis 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 givenJSONto include the @type metadata property in order to indicate the type of the JSON object, which is required for deserialization back to PDX. If anJsonProcessingExceptionis thrown during this operation and if thePdxInstancehas avalid class name, then an attempt is made to serialize theobject instanceof thePdxInstancetoJSONusing Jackson'sObjectMapper.- Parameters:
pdxInstance- requiredPdxInstancefrom which theJSONwas serialized; must not be null.json-JSONgenerated from the serialization of thePdxInstance; must not be null.- Returns:
- the decorated
JSONincluding the @type metadata property. - Throws:
org.springframework.dao.DataRetrievalFailureException- ifJSONcannot be decorated with type metadata and thePdxInstanceis not based on a validClasstype.- See Also:
-