You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@johnzon.apache.org by "Alexander Falb (JIRA)" <ji...@apache.org> on 2019/02/19 14:05:00 UTC
[jira] [Created] (JOHNZON-202) org.apache.johnzon.mapper.Adapter
JavaDoc wrong and IllegalArgumentException-message from
org.apache.johnzon.mapper.Mappings misleading
Alexander Falb created JOHNZON-202:
--------------------------------------
Summary: org.apache.johnzon.mapper.Adapter JavaDoc wrong and IllegalArgumentException-message from org.apache.johnzon.mapper.Mappings misleading
Key: JOHNZON-202
URL: https://issues.apache.org/jira/browse/JOHNZON-202
Project: Johnzon
Issue Type: Improvement
Components: Mapper
Affects Versions: 1.1.11
Reporter: Alexander Falb
Attachments: image-2019-02-19-14-59-17-119.png
{{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:
{code:java}
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){code}
While debugging this problem I found the following:
(my custom adapers are highlighted - it looks like I implemented them the wrong way)
!image-2019-02-19-14-59-17-119.png!
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?
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)