我正在尝试使用Navitia API,并且当前我遇到了一个奇怪的问题,即位置嵌入类型的反序列化。
为了简单起见,我有以下JSON片段:
"embedded_type": "stop_area",
"stop_area": {
"codes": [{
"type": "CR-CI-CH",
"value": "0085-011205-00"
}, {
"type": "CR-CI-CH",
"value": "0085-011205-00"
}, {
"type": "UIC8",
"value": "85011205"
}, {
"type": "external_code",
"value": "OCE85011205"
}],
"name": "Lausanne",
"links": [],
"coord": {
"lat": "46.517297",
"lon": "6.629229"
},
"label": "Lausanne (Lausanne)",
"timezone": "Europe\/Paris",
"id": "stop_area:OCE:SA:85011205"
},
"quality": 0,
"name": "Lausanne (Lausanne)",
"id": "stop_area:OCE:SA:85011205"
我试图放在这个班上
public class Place extends Named {
public int quality;
public String id;
public String name;
public PlaceEmbeddedType embedded_type;
}
使用PlaceEmbeddedType
定义了以下方式
@JsonTypeInfo(use = Id.NAME, include = As.EXTERNAL_PROPERTY)
@JsonSubTypes({
@JsonSubTypes.Type(value = StopArea.class, name = "stop_area"),
@JsonSubTypes.Type(value = StopPoint.class, name = "stop_point"),
@JsonSubTypes.Type(value = Address.class, name = "address"),
@JsonSubTypes.Type(value = POI.class, name = "poi"),
@JsonSubTypes.Type(value = AdministrativeRegion.class, name = "administrative_region")
})
public interface PlaceEmbeddedType {
}
我本以为@JsonTypeInfo(use = Id.NAME, include = As.WRAPPER_OBJECT)
是正确的映射,但是当我使用它时,我得到了
[INFO] com.fasterxml.jackson.databind.exc.MismatchedInputException: Unexpected token (VALUE_STRING), expected START_OBJECT: need JSON Object to contain As.WRAPPER_OBJECT type information for class com.github.jenkinsx.quickstarts.vertx.rest.prometheus.navitia.PlaceEmbeddedType
[INFO] at [Source: (okhttp3.ResponseBody$BomAwareReader); line: 1, column: 2527] (through reference chain: com.github.jenkinsx.quickstarts.vertx.rest.prometheus.navitia.LinesList["lines"]->java.util.ArrayList[0]->com.github.jenkinsx.quickstarts.vertx.rest.prometheus.navitia.Line["routes"]->java.util.ArrayList[0]->com.github.jenkinsx.quickstarts.vertx.rest.prometheus.navitia.Route["direction"]->com.github.jenkinsx.quickstarts.vertx.rest.prometheus.navitia.Place["embedded_type"])
因此,我正在寻找一种方法,将WRAPPER_TYPE
策略用于具有现有字段的对象。我该怎么办?