Last active
July 11, 2017 18:03
-
-
Save fuxingloh/586305abad870ac19951 to your computer and use it in GitHub Desktop.
Jackson
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
ObjectMapper mapper = new ObjectMapper() | |
// Via class | |
Hey hey = mapper.readValue("{name:\"hey\"}", Hey.class); | |
System.out.println(hey.name); | |
// Via dynamic | |
JsonNode node = mapper.readTree("{name:\"hey\"}"); | |
// With null safety, allows chaining | |
String name = node.path("name").asText(); | |
// With no null safety | |
name = node.get("name").asText(); | |
// Json Express | |
name = node.at("/name").asText(); | |
System.out.println(name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment