Closed GoogleCodeExporter closed 9 years ago
You can add a Converter for this:
{{{
ofyFactory.getConverters().add(new Converter() {
public Object forDatastore(Object value, ConverterSaveContext ctx) {
return ((CreditCard)value).getValue();
}
public Object forPojo(Object value, Class<?> fieldType, ConverterLoadContext ctx, Object onPojo) {
return new CreditCard(value.toString());
}
});
}}}
Is this an adequate solution?
Original comment by lhori...@gmail.com
on 4 Jun 2011 at 5:26
Doh! Ignore that last comment, this is the correct way to implement a
Converter:
ofyFactory.getConverters().add(new Converter() {
public Object forDatastore(Object value, ConverterSaveContext ctx) {
if (value instanceof CreditCard)
return ((CreditCard)value).getValue();
else
return null;
}
public Object forPojo(Object value, Class<?> fieldType, ConverterLoadContext ctx, Object onPojo) {
if (CreditCard.class.isAssignableFrom(fieldType))
return new CreditCard(value.toString());
else
return null;
}
});
Original comment by lhori...@gmail.com
on 4 Jun 2011 at 5:30
This is even easier now in Objectify4 with translators.
Original comment by lhori...@gmail.com
on 16 Dec 2011 at 2:32
Original issue reported on code.google.com by
axel.fontaine.business@gmail.com
on 4 Jun 2011 at 11:29