Skip to content

Instantly share code, notes, and snippets.

@vicly
Last active December 16, 2019 21:47
Show Gist options
  • Save vicly/2ee48ea3e48c6bc7b567a9542513175c to your computer and use it in GitHub Desktop.
Save vicly/2ee48ea3e48c6bc7b567a9542513175c to your computer and use it in GitHub Desktop.
[Jackson Misc] #Java #Json #Jackson

Problem

Multiple setter cause deserialization failure.

class MandrillMessage
	public void setTags(List<String> tags)
	public void setTags(final String... tags)

Solution

  public static class MandrillMessageMixIn extends MandrillMessage {
    @Override
    @JsonProperty("tags")
    public void setTags(List<String> tags) {
      super.setTags(tags);
    }
  }

  
  ObjectMapper mapper = new ObjectMapper();
  mapper.addMixIn(MandrillMessage.class, MandrillMessageMixIn.class);
  MandrillMessage message = mapper.readValue(a-json-string, MandrillMessage.class);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment