com.mindee.geometry.PolygonDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mindee-api-java Show documentation
Show all versions of mindee-api-java Show documentation
Java Library to call Mindee's Off-The-Shelf and Custom APIs
package com.mindee.geometry;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.fasterxml.jackson.databind.node.ArrayNode;
import java.io.IOException;
import java.util.List;
/**
* JSON deserializer for polygons.
*/
public class PolygonDeserializer extends StdDeserializer {
private static final ObjectMapper mapper = new ObjectMapper();
public PolygonDeserializer(Class> vc) {
super(vc);
}
public PolygonDeserializer() {
this(null);
}
@Override
public Polygon deserialize(
JsonParser jsonParser,
DeserializationContext deserializationContext
) throws IOException {
ArrayNode node = jsonParser.getCodec().readTree(jsonParser);
List> polygonList = mapper.readerFor(new TypeReference>>() {}).readValue(node);
return PolygonUtils.getFrom(polygonList);
}
}