Simple Object Assembler release update
There have been a couple of releases of the Simple Object Assembler in quick succession over the last week. These changes are all in aid of simplifying it’s use and can dramatically reduce the number of converters required in some projects due to enhancements to the auto-mapping capabilities. One project i’m using it on saw the converters drop from 34 to 14!
A summary of the release notes from the last week are below:
0.4.1
- Changed the return type of the alwaysIgnoreFields() method on a converter from a HashSet<String> to an internally defined IgnoreSet which has a string varargs constructor and is chainable. This makes for simpler implementation as you can simply do this… return new IgnoreSet("field1", "field2", "fieldN").
- Removed the return type on the overridable convert(...) method of a converter as it was unnecessary. This method is now void.
- Change all converters that implement the convert(...) method to return void instead of the destination object.
- Change all converters that implement the alwaysIgnoreProperties() method to return an IgnoreSet.
0.4.0
- You no longer need to implement the methods getSourceObjectClass() and getDestinationObjectClass() as these are inferred via generics.
- You can now set the object assembler to attempt to convert objects automatically if no converter is explicitly registered for the source / destination classes. This is very convenient for basic situations where there are no special rules for the conversion as no converter needs to be written.
- As an extension to the auto-mapping described above, you can also inject an EntityDao? for looking up JPA / Hibernate mapped entities by id when converting to an entity mapped using the javax.persistence.Entity annotation. Basic Hibernate and JPA implementations have been provided but you can plug-in your own as required. While I haven’t tested it with anything other than Hibernate, it’s highly likely that this will work with any JPA implementation but you’ll need to inject your own. One caveat with this however is that in order to look up the entity using the supplied EntityDao, SimpleObjectAssembler needs to know what field in your dto holds the id of the entity to fetch. To achieve this, annotate your dto with the EntityDto annotation supplying the field to get the entity id from. Eg. @EntityDto(id = “id”)
- Fixed problem where source objects must have a property for every method prefixed with ‘get’. This meant that methods that did things like combine other properties or perform calculations would cause the assembler to fail. These ‘computed’ getters can now be mapped directly to destination objects.
- Added default converters for mapping strings and numbers.