org.opentripplanner.api.json.FeedScopedIdDeserializer Maven / Gradle / Ivy
package org.opentripplanner.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 org.opentripplanner.model.FeedScopedId;
import java.io.IOException;
public class FeedScopedIdDeserializer extends JsonDeserializer {
public static final String SEPARATOR = ":";
@Override
public FeedScopedId deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
String string = jp.getValueAsString();
String[] parts = string.split(SEPARATOR, 2);
return new FeedScopedId(parts[0], parts[1]);
}
// Gets around type erasure, allowing
// module.addSerializer(new ThingSerializer()) to correctly associate
// this serializer with the proper type.
@Override
public Class handledType() {
return FeedScopedId.class;
}
}