Skip to content
Joffrey Bion edited this page Oct 25, 2016 · 9 revisions

Welcome to the fx-gson wiki!

Why use FX Gson?

In JavaFX, POJOs usually contain Property objects instead of primitives. When serialized with Gson, we don't want to see the internals of such Property objects in the produced JSON, but rather the actual value held by the property.

For instance, if I have a class like this:

public class Person {
    private final StringProperty firstName;
    private final StringProperty lastName;

    public Person(String firstName, String lastName) {
        this.firstName = new SimpleStringProperty(firstName);
        this.lastName = new SimpleStringProperty(lastName);
    }
    
    // getters / setters / prop getters
}

Here is how it is serialized:

With Gson With FxGson
{
    "firstName": {
        "name": "",
        "value": "Hans",
        "valid": true,
        "helper": {
            "observable": {}
        }
    },
    "lastName": {
        "name": "",
        "value": "Muster",
        "valid": true,
        "helper": {
            "observable": {}
        }
    }
}
{
    "firstName": "Hans",
    "lastName": "Muster"
}
Clone this wiki locally