On Wed, Dec 14, 2022 at 5:36 PM Senthil Nathan <senthil...@gmail.com> wrote: > > Hi, > > Rather updating all the properties, I want to update the values for only null > fields using readerForUpdating. > > Class: > @Getter > @Setter > public class Record { > public String source; > public String resource; > } > > Record record = new Record(); > record.setSource("sourceFromObject"); > record.setResource(null); > > Json: > > String json = {"source": "sourceFromJson", "resource":"resourceFromJson"} > > When I do, > ObjectMapper objectMapper = new ObjectMapper(); > objectMapper.readerForUpdating(record).readValue(json); > > am getting the result as [Record: source = " sourceFromJson ", resource = > "resourceFromJson" ] but > I want the result to be [Record: source = "sourceFromObject", resource = > "resourceFromJson" ] > > Could anyone please help on this.
There is no out of the box functionality for this, although it would theoretically be doable with custom deserializer. However, I suspect that it'd be easier to implement by reader json as `JsonNode`, serializing record as JsonNode, and modifying former with latter (leaving only properties for which there are no non-null values), and then deserializing as record. -+ Tatu +- > > Regards, > Senthil > > > > -- > You received this message because you are subscribed to the Google Groups > "jackson-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to jackson-user+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jackson-user/a7cc274e-bab2-405a-bbcb-4afdfc011e29n%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CAGrxA24oNSjN4tiYE0CCHvRnNE%3DL1HSuy_BaCUQf_WAL399MSA%40mail.gmail.com.