Collecting unmapped fields with Object Mapper

Jackson is a popular Java library to convert JSON to Java Object. It maps JSON field with object field by name or mapping provided by @JsonProperty.

Jackson provides @JsonAnySetter for collecting unmapped or unrecognized fields.

class Profile {

  String name;
  Map<String, String> unmappedFields = new HashMap<>();

  public void setName(String name) { = name;

  // for collecting unmapped field
  public void unmappedFields(String key, String value){
    // ... Do what you want
    unmappedFields.put(key, value);

In action

/* Consider JSON
  "name": "m8ty",
  "handler": "@DM8tyProgrammer"
Profile p =, Profile.class);

// print "m8ty"

// print "{handler=@DM8tyProgrammer}"

Be Updated

Only articles are shared on Medium

This site uses third-party cookies to gather website usage and performance data.