Created
February 25, 2014 14:03
-
-
Save whaley/9209359 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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