This repository has been archived by the owner on Dec 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
GenericTypes
pgn84 edited this page May 24, 2013
·
2 revisions
The TransformerRegistry is capable of creating new instances of ( and registering ) GenericTransformer -implementing Transformers with the Generic Types you specify. The requirement is that a GenericTransformer must be registered for the field or type before you do this, its generic types are however irrelevant ( as the transformer will be re-created with the generic types you provide to register() )
Observe the example below
// assume the field named "someScores" on the type ComplexObject is of type HashMap<String, Integer>
// register a GenericTransformer for HashMap
TransformerRegistry.getInstance().register(new MapTransformer<HashMap>(), HashMap.class);
// create and register a new instance of the above registered Transformer, but with the appropiate Generic Types..
TransformerRegistry.getInstance().register(new Class[]{String.class, Integer.class}, ComplexObject.class.getField("someScores"));
// note that this throws RegisteredSerialzierNotGenericException if there is no GenericTransformer registered for "someScores" type, HashMap ( and there is by default. )