com.github.useful_solutions.tosamara_sdk.classifier.deserializer.GeoPointsDeserializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tosamara-sdk Show documentation
Show all versions of tosamara-sdk Show documentation
SDK for working with API of tosamara.ru on Java
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();
}
}
}