|Pivotal GemFire||6.6.2 or later|
Beginning with GemFire 6.6.2, the Portable Data eXchange (PDX) ReflectionBasedAutoSerializer can be extended to convert ("transform") the type of field variables of domain objects. A useful example of this, given in the User's Guide, is to convert a BigDecimal field to a String field. This article explains how to query objects in which some of the fields have been converted by such an extended ReflectionBasedAutoSerializer.
To understand the issue, suppose that you want to query objects that contain a field whose type has been converted from BigDecimal to String while it is serialized. The original type of the field is BigDecimal, so you might write a query with a WHERE condition like the following (where the type of the field "bigDecimal" is originally, before conversion, BigDecimal):
SELECT * FROM /MyRegion WHERE bigDecimal = 2001.03
However, this query may fail to return any results, because the WHERE condition is applied to the serialized object directly and the converted field type is, thus, a String.
In the above case, the type of the target field was converted from BigDecimal to String. Hence, you should deal with the field as a String using a query like the following:
SELECT * FROM /MyRegion WHERE bigDecimal = '2001.03'
If, however, you want to deal with the field using the original type in the WHERE condition, you should implement a public method in your domain class to return the original field type and query using that method, as shown in the following (where the method getBigDecimalValue returns the field value with a BigDecimal type):
SELECT * FROM /MyRegion mr WHERE mr.getBigDecimalValue = 2001.03
Please note that that this approach will cause the objects to be deserialized in order to call the method, so the domain class must be available in the CLASSPATH.
For information on writing a custom PDX ReflectionBasedAutoSerializer, please refer to the following document: