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

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

The newest version!
package com.targomo.client.api.json;

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

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

/**
 * Created by Gideon Cohen
 */

public abstract class AbstractLocationMapDeserializer extends JsonDeserializer> {

    private static final ObjectMapper mapper = new ObjectMapper();
    
    public Map deserialize(String key, JsonParser jsonParser, Class deserializationClass)
            throws IOException {
        
        JsonNode locationArray = jsonParser.getCodec().readTree(jsonParser);

        Map locations = new HashMap<>();

        for (JsonNode coordinateNode : locationArray) {
            locations.put(coordinateNode.get(key).asText(),
                mapper.readValue(coordinateNode.toString(), deserializationClass));
        }

        return locations;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy