List of usage examples for com.badlogic.gdx.utils Json writeType
public void writeType(Class type)
From source file:com.vlaaad.dice.pvp.messaging.messages.Spawned.java
License:Open Source License
public static void register() { Config.json.addClassTag("spawned", Spawned.class); Config.json.setSerializer(Spawned.class, new Json.Serializer<Spawned>() { @Override//w w w .java 2s . com public void write(Json json, Spawned object, Class knownType) { json.writeObjectStart(); if (knownType == null) json.writeType(Spawned.class); json.writeValue("d", object.dice, Array.class); json.writeValue("p", object.potions, ObjectMap.class, Integer.class); json.writeValue("f", object.fraction.name, String.class); json.writeValue("packetIdx", object.packetIdx); json.writeObjectEnd(); } @SuppressWarnings("unchecked") @Override public Spawned read(Json json, JsonValue jsonData, Class type) { Array<PlacedCreature> dice = json.readValue(Array.class, PlacedCreature.class, jsonData.get("d")); ObjectMap potions = json.readValue(ObjectMap.class, Integer.class, jsonData.get("p")); Fraction fraction = Fraction.valueOf(jsonData.getString("f")); Spawned spawned = new Spawned(dice, potions, fraction); spawned.packetIdx = jsonData.getInt("packetIdx"); return spawned; } }); }
From source file:com.vlaaad.dice.pvp.messaging.messages.SpawnedToServer.java
License:Open Source License
public static void register() { Config.json.addClassTag("sts", SpawnedToServer.class); Config.json.setSerializer(SpawnedToServer.class, new Json.Serializer<SpawnedToServer>() { @Override/*from w w w . j a va 2 s . co m*/ public void write(Json json, SpawnedToServer object, Class knownType) { json.writeObjectStart(); if (knownType == null) json.writeType(SpawnedToServer.class); json.writeValue("d", object.dice, Array.class); json.writeValue("p", object.potions, ObjectMap.class, Integer.class); json.writeValue("packetIdx", object.packetIdx); json.writeObjectEnd(); } @SuppressWarnings("unchecked") @Override public SpawnedToServer read(Json json, JsonValue jsonData, Class type) { Array<PlacedCreature> dice = json.readValue(Array.class, PlacedCreature.class, jsonData.get("d")); ObjectMap potions = json.readValue(ObjectMap.class, Integer.class, jsonData.get("p")); SpawnedToServer spawnedToServer = new SpawnedToServer(dice, potions); spawnedToServer.packetIdx = jsonData.getInt("packetIdx"); return spawnedToServer; } }); }