question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Same properties are parsed multiple times when variable name is capitalized and JsonProperty annotated

See original GitHub issue

I have created a repo for this bug. See here: https://github.com/dentych/jackson-bug

In short terms, the issue is that variables in caps (e.g. MAT) that is annotated with JsonProperty(“MAT”) will be in the serialized JSON string twice.

The example output from my reproduction: The POJO “MyCollection”:

class MyCollection {
    @JsonProperty("MAT")
    private MAT MAT = null;
    @JsonProperty("DAR")
    private DAR DAR = null;
    @JsonProperty("someString")
    private String someString = null;

    public MAT getMAT() {
        return MAT;
    }

    public void setMAT(MAT MAT) {
        this.MAT = MAT;
    }

    public DAR getDAR() {
        return DAR;
    }

    public void setDAR(DAR DAR) {
        this.DAR = DAR;
    }

    public String getSomeString() {
        return someString;
    }

    public void setSomeString(String someString) {
        this.someString = someString;
    }
}

MAT and DAR are two simple POJOs that includes a propery “String name”. Each have getter and setters for the string.

When parsed, the following is output:

value =
{
  "mat": {
    "name": "MAT object"
  },
  "dar": {
    "name": "DAR object"
  },
  "MAT": {
    "name": "MAT object"
  },
  "DAR": {
    "name": "DAR object"
  },
  "requestedBFE": "101262"
}

As you can see, MAT and DAR are both present as they should, but there’s also a mat and a dar that should not be present.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
cowtowncodercommented, Aug 3, 2017

@dentych Thank you for verifying. This is the recommended way to deal with this situation then – for Jackson 3.0 we can and will change the defaults as well, to avoid having to configure mapper this way.

0reactions
dentychcommented, Jul 27, 2017

@cowtowncoder Using MapperFeature.USE_STD_BEAN_NAMING made it output the correct values and only once each.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does Jackson 2 not recognize the first capital letter if the ...
The problem you are seeing is due to the fact that Jackson uses Java Bean naming conventions to figure out the the Json...
Read more >
More Jackson Annotations - Baeldung
This article covers some lesser-known JSON processing annotations ... All name elements, including the first one, start with a capitalized ...
Read more >
Definitive Guide to Jackson ObjectMapper - Serialize and ...
In this detailed guide - learn everything you need to know about ObjectMapper. Convert JSON to and from Java POJOs, implement custom ...
Read more >
Solving the XML Problem with Jackson - Stackify
Looking for a mature, flexible way of working with both JSON and XML for the same data? Read how the Jackson XML module...
Read more >
picocli - a mighty tiny command line interface
Picocli has separate annotations for options and positional parameters. 3.1. Options. An option must have one or more names . Picocli lets you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found