Skip to content

Instantly share code, notes, and snippets.

@Nava2
Last active May 23, 2017 22:10
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 Nava2/c166524b17a51a617da90263d53924f0 to your computer and use it in GitHub Desktop.
Save Nava2/c166524b17a51a617da90263d53924f0 to your computer and use it in GitHub Desktop.
Simple examples used in FasterXML/jackson-modules-java8#1
public class Bar {
public String name;
public Bar(@JsonProperty("name") String name) {
this.name = name;
}
}
public class Foo {
private final ObjectProperty<Bar> bar;
@JsonCreator
public Foo(@JsonProperty("bar") Bar bar) {
this.bar = new SimpleObjectProperty<>(this, "bar", bar);
}
public Bar getBar() {
return bar.get();
}
public ObjectProperty<Bar> barProperty() {
return bar;
}
public void setBar(Bar bar) {
this.bar.set(bar);
}
}
[
{
"bar" : {
"@id" : 1,
"name" : "bar",
"value" : {
"name" : "bar"
}
}
}, {
"bar" : {
"@id" : 2,
"name" : "bar",
"bound" : true,
"value" : 1
}
}
]
Foo f1 = new Foo(null);
Foo f2 = new Foo(null);
Bar bar = new Bar("bar");
f1.barProperty().setValue(bar);
f2.barProperty().bind(f1.barProperty());
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaFXModule());
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(Arrays.asList(f1, f2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment