Object Suppliers
Mapping to destination classes without a no arg constructor.
Last updated
Was this helpful?
Mapping to destination classes without a no arg constructor.
Last updated
Was this helpful?
Due to the fact that ShapeShift uses reflection behind the scenes, destination classes need a no arg constructor. But in some cases you have no control over the destination classes and cannot modify them to add a no arg constructor. This is where Object Suppliers comes into play, you can register object suppliers to the ShapeShift instance to add your own logic for instance generation.
We have two classes, the source class SimpleEntity
and the destination class SimpleEntityDisplay
.
The destination class does not have a no arg constructor.
To solve this issue we need to either use or add an object supplier for the class.
Adding object suppliers is available through the ShapeShiftBuilder
class. Object suppliers can be added inline or as a separate class.
To create an object supplier class implement the Supplier
interface.
And register it to the ShapeShift
instance.
It is also possible to add the object supplier logic inline.
Now that we added an object supplier for the SimpleEntityDisplay
class we can map to it as if it has a no arg constructor.