feat: created deserializer for EntityIDs

This commit is contained in:
Yannik Bretschneider 2021-05-11 06:13:38 +02:00
parent 734445275d
commit e3635851d2

View File

@ -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<EntityID> {
@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);
}
}