Pivotal Knowledge Base

Follow

Cannot convert PdxInstance with a field of type "Date" into JSON document

Environment 

Pivotal GemFire 7.0.2.x or later (observed with GemFire 8.2.x)

Overview

This article provides a resolution for the issue when you try to convert a PdxInstance into a JSON document, when one of the field's type is "Date", using a JSONFormatter.

Symptom

When attempting this conversion, you may see the following exception and fail to get a JSON document:

Log Message:

Could not create JSON document from PdxInstance 
com.gemstone.gemfire.pdx.JSONFormatterException: Could not create JSON document from PdxInstance
at com.gemstone.gemfire.pdx.JSONFormatter.toJSON(JSONFormatter.java:103)
:
Caused by: java.lang.IllegalStateException: PdxInstance returns unknwon pdxfield approvedOn for type Tue May 23 10:20:55 JST 2017
at com.gemstone.gemfire.pdx.internal.json.PdxToJSON.writeValue(PdxToJSON.java:173)
:

Cause

GemFire's JSONFormatter uses the jackson-core library internally to convert data between JSON documents and actual PdxInstances.  However, the jackson-core library does not support the "Date" type.

Resolution

You should change the "Date" type field of the PdxInstance into another type supported by jackson-core, such as a "Long" with timestamp expression.

Comments

Powered by Zendesk