com.scaleset.geo.geojson.EnvelopeDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scaleset-geo Show documentation
Show all versions of scaleset-geo Show documentation
Simple framework for dealing with GeoJson and similar data formats
The newest version!
package com.scaleset.geo.geojson;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.vividsolutions.jts.geom.Envelope;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class EnvelopeDeserializer extends JsonDeserializer {
@Override
public Envelope deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
// current token is "["
List values = new ArrayList();
while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
Double value = jsonParser.getDoubleValue();
values.add(value);
}
Envelope result = null;
if (values.size() == 4) {
result = new Envelope(values.get(0), values.get(2), values.get(1), values.get(3));
}
return result;
}
}