Skip to content

Translating to Value Types

Geoffrey Wiseman edited this page May 15, 2014 · 2 revisions

Normally, the destination of a translation would be another mutable object that Moo can create with a NoArgument Constructor (see Constructors) and then modify during the translation process.

This doesn't work with value types, which are typically simple and immutable.

Moo doesn't have full support for value types yet, but there was one kind of value type that seemed more important than the others, one whose value type translation has been built into the Java class hierarchy from Object on down: java.lang.String.

As of Moo v2.0, Moo can translate to String types using the Object's own implementation of toString().

This has been implemented with a ValueTypeTranslator interface and a StringValueTypeTranslator implementation.

Using this is very simple: use a String as a destination, a non-string as the source and specify translate=true

@Property(translate=true)
String summary;

(see #90, #91)