fr.ght1pc9kc.entity.jackson.serializer.EntityDeserializer Maven / Gradle / Ivy
package fr.ght1pc9kc.entity.jackson.serializer;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import fr.ght1pc9kc.entity.api.Entity;
import fr.ght1pc9kc.entity.api.TypedMeta;
import fr.ght1pc9kc.entity.api.impl.BasicEntity;
import fr.ght1pc9kc.entity.api.impl.ExtendedEntity;
import fr.ght1pc9kc.entity.jackson.ex.EntityDeserializationException;
import java.io.IOException;
import java.util.EnumMap;
import java.util.Optional;
/**
* Manage the {@link Entity}, {@link BasicEntity} and {@link ExtendedEntity} deserialization.
* All field starting with "{@code _}" are considered as meta data and will be used for Entity,
* all other fields are considered to belong to the self object
*
* {@link Entity} and {@link BasicEntity} are always deserialize as {@link BasicEntity}. To get a
* {@link ExtendedEntity} with meta it is necessary to explicitly specify
* {@code
* ObjectMapper mapper = new ObjectMapper();
* Entity entity = mapper.readValue(json, new TypeReference>() {});
* }
*
* @param The type of {@code self} object in {@link Entity}
*/
public class EntityDeserializer extends JsonDeserializer> {
private final JsonDeserializer