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

com.github.useful_solutions.tosamara_sdk.classifier.deserializer.GeoPointsDeserializer Maven / Gradle / Ivy

There is a newer version: 1.5
Show newest version
package com.github.useful_solutions.tosamara_sdk.classifier.deserializer;

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.github.useful_solutions.tosamara_sdk.api.record.pojo.GeoPoint;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class GeoPointsDeserializer extends JsonDeserializer> {

    @Override
    public List deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
        String value = jsonParser.getText();
        if (value != null) {
            String[] stringPoints = value.split(" ");
            List points = new ArrayList<>(stringPoints.length);
            for (String stringPoint : stringPoints) {
                String[] coords = stringPoint.split(",");
                Double latitude = Double.parseDouble(coords[0]);
                Double longitude = Double.parseDouble(coords[1]);
                points.add(new GeoPoint(latitude, longitude));
            }
            return points;
        } else {
            return Collections.emptyList();
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy