Created
August 1, 2015 04:29
-
-
Save jarcode-foss/0249f92477d51c1070e9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
gson = new GsonBuilder() | |
.registerTypeAdapter(ConsoleMeta.class, new JsonSerializer<ConsoleMeta>() { | |
@Override | |
public JsonElement serialize(ConsoleMeta consoleMeta, Type type, | |
JsonSerializationContext jsonSerializationContext) { | |
JsonObject object = new JsonObject(); | |
object.add("location", | |
locationTypeAdapter.serialize(consoleMeta.location, null, jsonSerializationContext)); | |
object.add("face", new JsonPrimitive(consoleMeta.face.name())); | |
object.add("w", new JsonPrimitive(consoleMeta.w)); | |
object.add("h", new JsonPrimitive(consoleMeta.h)); | |
return object; | |
} | |
}) | |
.registerTypeAdapter(ConsoleMeta.class, new JsonDeserializer<ConsoleMeta>() { | |
@Override | |
public ConsoleMeta deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException { | |
JsonObject object = jsonElement.getAsJsonObject(); | |
Location location = locationTypeAdapter.deserialize(object.get("location"), | |
null, jsonDeserializationContext); | |
BlockFace face = BlockFace.valueOf(object.get("face").getAsString()); | |
int w = object.get("w").getAsInt(); | |
int h = object.get("h").getAsInt(); | |
return new ConsoleMeta(location, face, w, h); | |
} | |
}) | |
.enableComplexMapKeySerialization() | |
.setPrettyPrinting() | |
.create(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment