Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for @JsonMerge to allow "deep update" #1399

Closed
cowtowncoder opened this issue Oct 5, 2016 · 5 comments
Closed

Add support for @JsonMerge to allow "deep update" #1399

cowtowncoder opened this issue Oct 5, 2016 · 5 comments
Milestone

Comments

@cowtowncoder
Copy link
Member

Currently existing values of properties are not taken into consideration, with the rare case of "setterless-getters" where this is done for Collection types if no setter exists.
But it would be useful to allow this for Maps and POJOs as well.

Proposed mechanism is to allow use of:

public class POJO {
    @JsonSetter(merge=OptBoolean.TRUE)
    public List<String> names = new ArrayList<>();
    {
         names.add("first");
    }

In addition to per-property annotation, it should also be possible to specify "config overrides" using:

objectMapper.configOverrides(MyPOJO.class)
     .setter(JsonSetter.Value.from(.....));

which would specify default merge/no-merge settings for properties of specified type.
It would probably also make sense to allow setting fully global default, similar to ability to set "serializationInclusion" global defaults (with JsonInclude.Value).

@cowtowncoder
Copy link
Member Author

Initial implementation now exists, supporting POJOs, Collections, Maps, reference types.

@heruan
Copy link

heruan commented Jan 3, 2017

Any docs on how to test this?

@cowtowncoder
Copy link
Member Author

@heruan at this point the best way I think is to search for unit tests with @JsonSetter(merge=.

@Tetradeus
Copy link

Wouldn't it be nice to have an option to enable setting null values at merge path ? Ref #1437

    // Also: nulls better not override
    public void testBeanMergingWithNull() throws Exception
    {
        Config config = MAPPER.readerForUpdating(new Config(5, 7))
                .readValue(aposToQuotes("{'loc':null}"));
        assertNotNull(config.loc);
        assertEquals(5, config.loc.a);
        assertEquals(7, config.loc.b);
    }

What if I really want to be able to set null for loc ? assertNull(config.loc);

Thanks for your reply.

@cowtowncoder
Copy link
Member Author

@Tetradeus Please file a new issue; this one is closed. We can discuss details as part of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants