ColorSaver implements ElementTypeAdapter<Color> { @Override public JsonElement serialize(Color src, JsonSerializationContext context) { return context.serialize(FxUtils.toHexString(src)); }  @Override JsonElement serialize(Color src, JsonSerializationContext context); @Override Color deserialize(JsonElement json, JsonDeserializationContext context);  }
@Test public void testSerialize() throws Exception { String colorString = "#12345678"; Color color = Color.web(colorString); String json = gson.toJson(color); assertEquals('"' + colorString + '"', json); }