Skip to content

Instantly share code, notes, and snippets.

@Nava2
Last active May 19, 2017 04:24
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/83a6667a99018c56e506482da04ce509 to your computer and use it in GitHub Desktop.
Save Nava2/83a6667a99018c56e506482da04ce509 to your computer and use it in GitHub Desktop.
Used to describe a small example of Property values
public class Bar {
public String name;
public Bar(String name) {
this.name = name;
}
}
public class Foo {
private final ObjectProperty<Bar> bar;
public Foo(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, // ID property for the property value itself
"value": {
"@id": 2, // ID property added because it's required, not because it was specified,
// though this should respect @JsonIdentityInfo
"name": "bar" // Bar#name
}
},
{
"bar": {
"@id": 3,
"bound": 1, // states it was bound, not actually holding a value
}
}
]
@Test
public void test() throws Exception {
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.writeValueAsString(Arrays.asList(f1, f2));
List<Foo> fromJson = mapper.readValue(json, new TypeReference<List<Foo>>() {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment