{"id":15175223,"url":"https://github.com/joffrey-bion/fx-gson","last_synced_at":"2025-10-28T13:20:02.829Z","repository":{"id":41443348,"uuid":"58500511","full_name":"joffrey-bion/fx-gson","owner":"joffrey-bion","description":"A set of type adapters for Google Gson to make JavaFX properties serialization more natural","archived":false,"fork":false,"pushed_at":"2024-03-11T13:38:47.000Z","size":488,"stargazers_count":53,"open_issues_count":3,"forks_count":6,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-07T18:52:12.012Z","etag":null,"topics":["fx-gson","gson","javafx","json","serialize-javafx-properties"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joffrey-bion.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"joffrey-bion","custom":"https://paypal.me/joffreybion"}},"created_at":"2016-05-10T23:48:42.000Z","updated_at":"2024-12-07T13:22:30.000Z","dependencies_parsed_at":"2025-02-11T20:31:35.612Z","dependency_job_id":null,"html_url":"https://github.com/joffrey-bion/fx-gson","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/joffrey-bion/fx-gson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joffrey-bion%2Ffx-gson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joffrey-bion%2Ffx-gson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joffrey-bion%2Ffx-gson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joffrey-bion%2Ffx-gson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joffrey-bion","download_url":"https://codeload.github.com/joffrey-bion/fx-gson/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joffrey-bion%2Ffx-gson/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263996015,"owners_count":23541396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fx-gson","gson","javafx","json","serialize-javafx-properties"],"created_at":"2024-09-27T12:04:52.967Z","updated_at":"2025-10-28T13:19:57.763Z","avatar_url":"https://github.com/joffrey-bion.png","language":"Java","funding_links":["https://github.com/sponsors/joffrey-bion","https://paypal.me/joffreybion"],"categories":[],"sub_categories":[],"readme":"# FX Gson\n\n[![Maven central version](https://img.shields.io/maven-central/v/org.hildan.fxgson/fx-gson.svg)](http://mvnrepository.com/artifact/org.hildan.fxgson/fx-gson)\n[![Build Status](https://github.com/joffrey-bion/fx-gson/actions/workflows/build.yml/badge.svg)](https://github.com/joffrey-bion/fx-gson/actions/workflows/build.yml)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/joffrey-bion/fx-gson/blob/master/LICENSE)\n\nFX Gson is a set of type adapters for [Google Gson](https://github.com/google/gson) to serialize JavaFX properties as \ntheir values, and deserialize values into properties.\n\nFX Gson simply removes the property \"wrapping\" and delegates the serialization of the value to the Gson. This means that \nany configuration you add to Gson regarding a type will be taken into account when serializing a property of that type. \nThis is true for objects and primitives.\n\n## Why use FX Gson?\n\nIn JavaFX, POJOs usually contain `Property` objects instead of primitives. When serialized, we usually don't want to\nsee the internals of such `Property` objects in the produced JSON, but rather the actual value held by the property.\n\nFor instance, suppose the `Person` class is defined like this:\n\n```java\npublic class Person {\n    private final StringProperty firstName;\n    private final StringProperty lastName;\n\n    public Person(String firstName, String lastName) {\n        this.firstName = new SimpleStringProperty(firstName);\n        this.lastName = new SimpleStringProperty(lastName);\n    }\n    \n    // getters, setters, and property getters are omitted for brevity\n}\n```\n    \nHere is how `new Person(\"Hans\", \"Muster\")` is serialized:\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003cth\u003eWith vanilla Gson\u003c/th\u003e\n        \u003cth\u003eWith FxGson-configured Gson\u003c/th\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\n        \u003cpre\u003e{\n    \"firstName\": {\n        \"name\": \"\",\n        \"value\": \"Hans\",\n        \"valid\": true,\n        \"helper\": {\n            \"observable\": {}\n        }\n    },\n    \"lastName\": {\n        \"name\": \"\",\n        \"value\": \"Muster\",\n        \"valid\": true,\n        \"helper\": {\n            \"observable\": {}\n        }\n    }\n}\u003c/pre\u003e\n        \u003c/td\u003e\n        \u003ctd\u003e\n            \u003cpre\u003e{\n    \"firstName\": \"Hans\",\n    \"lastName\": \"Muster\"\n}\u003c/pre\u003e\n        \u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\nThis produces a more human-readable output, and make manual modifications of the JSON easier.\n\n## Usage\n\nAll you need to know is [in the wiki](https://github.com/joffrey-bion/fx-gson/wiki/Basic-FX-Gson-usage), but here is a \nquick overview.\n\nYou can use FX Gson in multiple ways depending on the degree of customization you need:\n- directly [create a ready-to-go `Gson`](https://github.com/joffrey-bion/fx-gson/wiki/Basic-FX-Gson-usage#simple-ways-matter) able to serialize JavaFX properties\n\n    ```java\n    // to handle only Properties and Observable collections\n    Gson fxGson = FxGson.create();\n    \n    // to also handle the Color \u0026 Font classes\n    Gson fxGsonWithExtras = FxGson.createWithExtras();\n    ```\n\n- [create a pre-configured `GsonBuilder`](https://github.com/joffrey-bion/fx-gson/wiki/Basic-FX-Gson-usage#using-pre-configured-gsonbuilders) that you can further configure yourself\n\n    ```java\n    Gson fxGson = FxGson.coreBuilder()\n                        .registerTypeAdapterFactory(new MyFactory())\n                        .disableHtmlEscaping()\n                        .create();\n    \n    Gson fxGsonWithExtras = FxGson.fullBuilder()\n                                  .registerTypeAdapter(Pattern.class, new PatternSerializer())\n                                  .setPrettyPrinting()\n                                  .create();\n    ```\n\n- [add JavaFX configuration to an existing `GsonBuilder`](https://github.com/joffrey-bion/fx-gson/wiki/Basic-FX-Gson-usage#adding-javafx-support-to-an-existing-gsonbuilder)\n\n    ```java\n    GsonBuilder builder = MyLib.getBuilder();\n    Gson gson = FxGson.addFxSupport(builder).create();\n    ```\n\n- [cherry-pick some pieces of FX Gson configuration](https://github.com/joffrey-bion/fx-gson/wiki/Customize-FX-Gson) and customize it to fit your needs\n\n## Java version compatiblity\n\nThere are different JRE requirements depending on the version of FX Gson:\n\n| FX Gson version | JRE requirement      |\n|-----------------|----------------------|\n| 3.x.x           | 8                    |\n| 4.x.x           | 9+ (JPMS compatible) |\n| 5.x.x           | 8+ (JPMS compatible) |\n\nStarting from FX Gson 4.0.0, the library has a `module-info.java` for compatibility with Jigsaw (Java 9+).\n\nStarting from FX Gson 5.0.0, the library still has `module-info.java` compiled with Java 9, but all other class files\nhave bytecode level 8, so it can still be used in Java 8. Thanks to [@Glavo](https://github.com/Glavo) for the contribution!\n\n## Setup - adding the dependency\n\n### Manual download\n \nYou may manually download the JAR from \n[Maven Central](https://repo1.maven.org/maven2/org/hildan/fxgson/fx-gson/), although I recommend\nusing a build tool such as [Gradle](https://gradle.org/).\n \n### Gradle\n\n```kotlin\ncompile(\"org.hildan.fxgson:fx-gson:$VERSION\")\n```\n\n### Maven\n\n```xml\n\u003cdependency\u003e\n   \u003cgroupId\u003eorg.hildan.fxgson\u003c/groupId\u003e\n   \u003cartifactId\u003efx-gson\u003c/artifactId\u003e\n   \u003cversion\u003e$VERSION\u003c/version\u003e \u003c!-- replace with latest version --\u003e\n   \u003ctype\u003epom\u003c/type\u003e\n\u003c/dependency\u003e\n```    \n## License\n\nCode released under [the MIT license](https://github.com/joffrey-bion/io-utils/blob/master/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoffrey-bion%2Ffx-gson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoffrey-bion%2Ffx-gson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoffrey-bion%2Ffx-gson/lists"}