All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scaleset.geo.geojson.EnvelopeDeserializer Maven / Gradle / Ivy

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;

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy