Skip to content

@JsonProperty(access=READ_ONLY) unxepected behaviour with Collections #1382

@hexfaker

Description

@hexfaker

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 .

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions