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); + } +}