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

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

There is a newer version: 0.39.0
Show newest version
package com.targomo.client.api.json;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
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.Coordinate;
import com.targomo.client.api.geo.DefaultTargetCoordinate;

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

/**
 * Created by gerb on 01/02/2017.
 */

public class DefaultTargetCoordinateMapDeserializer extends JsonDeserializer> {

    private ObjectMapper mapper = new ObjectMapper();

    public DefaultTargetCoordinateMapDeserializer() {}

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

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

        Map coordinates = new HashMap<>();

        for (JsonNode coordinateNode : coordinatesArray) {
            coordinates.put(coordinateNode.get("id").asText(),
                    mapper.readValue(coordinateNode.toString(), DefaultTargetCoordinate.class));
        }

        return coordinates;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy