Last active
May 19, 2017 04:24
-
-
Save Nava2/83a6667a99018c56e506482da04ce509 to your computer and use it in GitHub Desktop.
Used to describe a small example of Property values
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
public class Bar { | |
public String name; | |
public Bar(String name) { | |
this.name = name; | |
} | |
} |
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
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); | |
} | |
} |
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
[ | |
{ | |
"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 | |
} | |
} | |
] |
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
@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