From e3635851d2c4d03f23e0caff395f888e160b7727 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Tue, 11 May 2021 06:13:38 +0200 Subject: [PATCH] feat: created deserializer for EntityIDs --- .../json/ingame/EntityIDDeserializer.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/EntityIDDeserializer.java diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/EntityIDDeserializer.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/EntityIDDeserializer.java new file mode 100644 index 0000000..4fcf3cf --- /dev/null +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/EntityIDDeserializer.java @@ -0,0 +1,25 @@ +package uulm.teamname.marvelous.gamelibrary.json.ingame; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import uulm.teamname.marvelous.gamelibrary.entities.EntityID; +import uulm.teamname.marvelous.gamelibrary.entities.EntityType; + +import java.io.IOException; + +public class EntityIDDeserializer extends JsonDeserializer { + @Override + public EntityID deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException { + ObjectCodec codec = p.getCodec(); + JsonNode node = codec.readTree(p); + + EntityType type = EntityType.valueOf(node.get("entityID").asText()); + int id = node.get("ID").asInt(); + + return new EntityID(type, id); + } +}