Skip to content

Instantly share code, notes, and snippets.

@coopernurse
Created May 22, 2017 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coopernurse/639e91b34b51bee736e29d12812ecf24 to your computer and use it in GitHub Desktop.
Save coopernurse/639e91b34b51bee736e29d12812ecf24 to your computer and use it in GitHub Desktop.
import com.fasterxml.jackson.databind.ObjectMapper;
public class MyData {
public static void main(String argv[]) throws Exception {
String json = "{\"name\": \"foo\", \"age\": 30 }";
MyData d = new ObjectMapper().readValue(json, MyData.class);
System.out.println(" json: " + json);
System.out.println("deserialized: " + d);
}
private String name;
private int age;
public String getName() {
return name;
}
public int getAge() {
return age;
}
@Override
public String toString() {
return "MyData{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
@coopernurse
Copy link
Author

this prints:

        json: {"name": "foo", "age": 30 }
deserialized: MyData{name='foo', age=30}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment