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

ConstructorProperties with custom-named fields (JohnzonProperty)

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Not A Problem
    • 1.1.11
    • None
    • Mapper
    • None

    Description

      I'm not sure if this is a bug or just unexpected behaviour:

      When I map a JSON field named "$version" to a Java field named "version" and this field is mandatory/final I have to annotate the constuctor like this:

      public static class MyBean {
          @JohnzonProperty("$version") private final int version;
      
          @ConstructorProperties("$version") public MyBean(int version) {
              this.version = version;
          }
      ...

      I would expect the value of ConstructorProperties to be version (without the dollar $ sign), because the documentation of ConstructorProperties says:

      An annotation on a constructor that shows how the parameters of
      that constructor correspond to the constructed object's getter
      methods. [...]

      but is actually has to be the JSON field name.

      In my optinion this is quite unexpected and also from a maintainability point of view I think declaring the custom naming twice is bad. - I think the ConstructorProperties should the the Java field names and not the JSON name (or for backward compatability maybe both).

      Attachments

        Activity

          People

            Unassigned Unassigned
            elexx Alexander Falb
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: