johnzon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexander Falb (JIRA)" <>
Subject [jira] [Created] (JOHNZON-200) ConstructorProperties with custom-named fields (JohnzonProperty)
Date Mon, 11 Feb 2019 07:43:00 GMT
Alexander Falb created JOHNZON-200:

             Summary: ConstructorProperties with custom-named fields (JohnzonProperty)
                 Key: JOHNZON-200
             Project: Johnzon
          Issue Type: Bug
          Components: Mapper
    Affects Versions: 1.1.11
            Reporter: Alexander Falb

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:
{quote}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).

This message was sent by Atlassian JIRA

View raw message