Description
org.apache.johnzon.mapper.Adapter<A, B> states, that A is taken from JSON and converted to B to store in the POJO. Following this, I implemented 3 adapter for java.time.* classes. When calling Mapper#writeObjectAsString(Object) the following exception is thrown:
java.lang.IllegalArgumentException: Ambiguous adapter for org.apache.johnzon.mapper.access.FieldAccessMode$FieldReader@5e265ba4
at org.apache.johnzon.mapper.Mappings.findConverter(Mappings.java:593)
at org.apache.johnzon.mapper.Mappings.addGetterIfNeeded(Mappings.java:494)
at org.apache.johnzon.mapper.Mappings.createClassMapping(Mappings.java:412)
at org.apache.johnzon.mapper.Mappings.findOrCreateClassMapping(Mappings.java:361)
at org.apache.johnzon.mapper.Mapper.isDeduplicateObjects(Mapper.java:141)
at org.apache.johnzon.mapper.Mapper.writeObject(Mapper.java:134)
at org.apache.johnzon.mapper.Mapper.writeObjectAsString(Mapper.java:178)
at JohnzonTestMain.main(JohnzonTestMain.java:27)
While debugging this problem I found the following:
(my custom adapers are highlighted - it looks like I implemented them the wrong way)
I think the JavaDoc of Adapter is wrong. The A to(B b); method is ment to convert from a JSON-value to a Java-value and B from(A a); from a Java-value to a JSON-value (A is the Javatype and B the JSONtype)?
Also the exception is kind of misleading. Getting the actually ambiguous key would have been helpful.
If you are interested I can provide a PR on GitHub, fixing the JavaDoc and changing the exception message?