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

com.targomo.client.api.json.DefaultSourceGeometriesMapDeserializer Maven / Gradle / Ivy

package com.targomo.client.api.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.targomo.client.api.geo.AbstractGeometry;
import com.targomo.client.api.geo.DefaultSourceGeometry;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author gideon
 */
public class DefaultSourceGeometriesMapDeserializer extends JsonDeserializer> {
    private ObjectMapper mapper = new ObjectMapper();

    public DefaultSourceGeometriesMapDeserializer() {}

    @Override
    public Map deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
            throws IOException {

        JsonNode polygonsArray = jsonParser.getCodec().readTree(jsonParser);

        Map polygons = new HashMap<>();

        for (JsonNode polygonNode : polygonsArray) {
            polygons.put(polygonNode.get("id").asText(),
                    mapper.readValue(polygonNode.toString(), DefaultSourceGeometry.class));
        }

        return polygons;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy