Jackson-databind: `@JsonProperty(access=READ_ONLY)` unxepected behaviour with `Collections`

Created on 22 Sep 2016  路  2Comments  路  Source: FasterXML/jackson-databind

I encountered problem same to #935, but it also affects 2.8.3, and related to collection properties deserialization.
Here reproducing test case, and it fails:

public class JacksonBugReproduction {
    private static class Foo {
        @JsonProperty(access = READ_ONLY)
        private List<Long> list = new ArrayList<>();

        List<Long> getList() {
            return list;
        }

        public Foo setList(List<Long> list) {
            this.list = list;
            return this;
        }
    }

    @Test
    public void shouldNotDeserializeList() throws Exception {
        String payload = "{\"list\":[1,2,3,4]}";
        ObjectMapper mapper = new ObjectMapper();

        Foo foo = mapper.readValue(payload, Foo.class);

        Assert.assertTrue("List should be empty", foo.getList().isEmpty());
    }
}

Full project project available here .

Most helpful comment

@hexfaker That sounds like a bug to me: READ_ONLY should mean that no deserialization would be done. getters-as-setters feature itself is.... gnarly.... but it's due to JAXB legacy, where that's how all Collections are handled; and it usually should only occur if no real setter exists (and only for collections and maps). This should not, still, be a back door.

So, thank you for reporting this: as I said it looks like a bug to me.

All 2 comments

OK, I disabled USE_GETTERS_AS_SETTERS feature, and now it works as expected. But I think this behavior is at least subject to discuss, if not wrong at all.

@hexfaker That sounds like a bug to me: READ_ONLY should mean that no deserialization would be done. getters-as-setters feature itself is.... gnarly.... but it's due to JAXB legacy, where that's how all Collections are handled; and it usually should only occur if no real setter exists (and only for collections and maps). This should not, still, be a back door.

So, thank you for reporting this: as I said it looks like a bug to me.

Was this page helpful?
0 / 5 - 0 ratings