org.opentripplanner.model.json_serialization.EncodedPolylineJSONSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.model.json_serialization;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.opentripplanner.util.PolylineEncoder;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
public class EncodedPolylineJSONSerializer extends JsonSerializer {
@Override
public void serialize(Geometry arg, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonProcessingException {
if (arg == null) {
jgen.writeNull();
}
Coordinate[] lineCoords = arg.getCoordinates();
List coords = Arrays.asList(lineCoords);
jgen.writeObject(PolylineEncoder.createEncodings(coords).getPoints());
}
@Override
public Class handledType() {
return Geometry.class;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy