Skip to content

Instantly share code, notes, and snippets.

@whaley
Created February 25, 2014 14:03
Show Gist options
  • Save whaley/9209359 to your computer and use it in GitHub Desktop.
Save whaley/9209359 to your computer and use it in GitHub Desktop.
package eat.me;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JacksonTest {
private static final String EXAMPLE = "{\"email\": {\"addr\":\"e@example.com\"}}";
public static void main(String[] args) throws Exception {
ObjectMapper mapper = new ObjectMapper();
Foo foo = mapper.readValue(EXAMPLE,Foo.class);
System.out.println(foo.email); //e@examle.com
}
private static class Foo {
String email;
@JsonSetter("email")
private void setEmail(JsonNode node) {
email = node.path("addr").asText();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment