Skip to content
Geoffrey Wiseman edited this page Apr 2, 2014 · 1 revision

Moo v1.3 contained features and fixes for some long-standing issues, particularly around updating a large graph of nested objects. It was officially released on 29-Feb-2012, a leap day. The issues from the milestone contain additional details that are summarized below.

Moo prior to v1.3 could replace the contents of a collection, but not update it. This was in part because determining which source object to use to update which destination object in a collection was tricky at best, and the simplest solutions wouldn't do the job for the projects on which I was using Moo.

As of v1.3, Moo will update the items in a collection in iteration order (which is index order for a list) and via keys for a map unless you specify a collection matcher of your own.

You can tell Moo to ignore a method or property, to not treat it as a potential destination for translation. This can be useful when something looks like, but is not, a real property, or when you simply don't want to overwrite that value. It is configured with an @Ignore annotation on the field or property.

A way to tell Moo not to remove items from a collection on update if they're not present in the source; this is useful for appending new values from the source without removing anything from the destination. This is configured through a new remove=false attribute on the CollectionProperty annotation.

Optional properties allow you to inform Moo that while you'd be happy to accept values for these properties if they are present in the source object, you do not require the properties to be present. This can be useful when translating polymorphic values, or from multiple source object types. This is configured with the somewhat-verbose optionality=Optionality.OPTIONAL attribute on the Property or CollectionProperty annotation. I recommend a static import to cut that down to optionality=OPTIONAL, which is still a bit much, but definitely improved.

If your class doesn't normally have a no-argument constructor, I find it irritating to create one for the purposes of a framework. Moo doesn't yet support passing constructor arguments, but it now allows you to invoke a no-arg constructor that is private or protected, so that you don't have to publish the no-arg constructor as part of your class' interface.

Originally, Moo would ignore the translation expression if you were doing an update. Now, Moo uses the translation expression which can be configured in the Property or CollectionProperty annotations. This allows an update to source its information from a field with a different name than itself or even employ outside objects in doing some form of 'translation'.

Clone this wiki locally