I have a pojo that has a field of type CurrencyUnit
from the javamoney library. When I marshall this pojo Jackson throws an exception. I remember this exception when I did not define any default constructor. But in this case I can not maintain the CurrencyUnit
class since it's coming from a dependency. How can I still make this work?
Exception:
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `javax.money.CurrencyUnit` (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information\n at
You should write a custom serialiser/deserialiser for each type from
javax.money
package you want to use or register already created module. For example: jackson-datatype-money.You need to add dependency:
Simple example how to use:
above code prints: