Uploaded image for project: 'Johnzon'
  1. Johnzon
  2. JOHNZON-202

org.apache.johnzon.mapper.Adapter JavaDoc wrong and IllegalArgumentException-message from org.apache.johnzon.mapper.Mappings misleading

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1.11
    • 1.1.13
    • Mapper
    • None

    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?

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            struberg Mark Struberg
            elexx Alexander Falb
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment