Skip to content

Instantly share code, notes, and snippets.

@nhojpatrick
Created September 11, 2020 18:54
Show Gist options
  • Save nhojpatrick/dd48121d4ad02919e5067c388616905e to your computer and use it in GitHub Desktop.
Save nhojpatrick/dd48121d4ad02919e5067c388616905e to your computer and use it in GitHub Desktop.
FB Json Example
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
public class Example {
public static void main(final String[] args)
throws Exception {
final String json = "{\"AnArrayOfObject\":[{},{},{}],\"AnObject\":{\"Var1\":1,\"Var2\":2},\"Var\":\"string\"}";
final ObjectMapper objectMapper = new ObjectMapper();
final Example1 example1 = objectMapper.readValue(json, Example1.class);
System.out.println("AnArrayOfObject size=" + example1.getAnArrayOfObject().size());
System.out.println("var1=" + example1.getAnObject().getVar1());
System.out.println("var2=" + example1.getAnObject().getVar2());
System.out.println("var=" + example1.getVar());
}
public static class Example1 {
@JsonProperty("AnArrayOfObject")
private List<Example2> anArrayOfObject;
@JsonProperty("AnObject")
public Example3 anObject;
@JsonProperty("Var")
private String var;
public Example1() {
}
public List<Example2> getAnArrayOfObject() {
return this.anArrayOfObject;
}
public Example3 getAnObject() {
return this.anObject;
}
public String getVar() {
return this.var;
}
}
public static class Example2 {
public Example2() {
}
}
public static class Example3 {
@JsonProperty("Var1")
private Integer var1;
@JsonProperty("Var2")
private Integer var2;
public Example3() {
}
public Integer getVar1() {
return this.var1;
}
public Integer getVar2() {
return this.var2;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment