com.googlecode.objectify.impl.conv
Interface Converter

All Known Implementing Classes:
ArrayConverter, BigDecimalLongConverter, BigMoneyStringConverter, BooleanConverter, CollectionConverter, DateTimeZoneConverter, EnumConverter, KeyConverter, LocalDateConverter, MoneyStringConverter, NumberConverter, ReadableInstantConverter, SqlDateConverter, StringConverter, TimeZoneConverter

public interface Converter

Interface for objects which know how to convert from POJO field types to whatever is necessary for native storage in the datastore. The datastore Entity has significant limits on what can be saved with setProperty() and inadvertently transmutes some values (eg Integer to Long). The converter knows how to make it all work.

Converters are assembled in a chain and each one is given a crack at the value. This is because some converters cover broad ranges of subclasses (eg, Enum) and a simple hashmap lookup is inadequate. The first converter that returns a non-null value "wins".

THIS API IS EXPERIMENTAL. It may change significantly in minor point releases.


Method Summary
 java.lang.Object forDatastore(java.lang.Object value, ConverterSaveContext ctx)
          Convert the value into an object suitable for storage in the datastore.
 java.lang.Object forPojo(java.lang.Object value, java.lang.Class<?> fieldType, ConverterLoadContext ctx, java.lang.Object onPojo)
          Convert the value into an object suitable for setting on a field with the specified type.
 

Method Detail

forDatastore

java.lang.Object forDatastore(java.lang.Object value,
                              ConverterSaveContext ctx)
Convert the value into an object suitable for storage in the datastore. The first thing converters should do is test whether they are appropriate for the input data; if not, return null.

Parameters:
value - will never be null
Returns:
null to indicate that this converter does nothing with the value

forPojo

java.lang.Object forPojo(java.lang.Object value,
                         java.lang.Class<?> fieldType,
                         ConverterLoadContext ctx,
                         java.lang.Object onPojo)
Convert the value into an object suitable for setting on a field with the specified type. The first thing converters should do is test whether they are appropriate for the input data; if not, return null.

Parameters:
value - will never be null
fieldType - is the type that the value should be converted to
onPojo - is the actual pojo object that this value will eventually be set upon
Returns:
null to indicate that this converter does nothing with the value


Copyright © 2011 Jeff Schnitzer and a gang of pirates. All Rights Reserved. Build version: 3.1