Jackson ライブラリを使用してGeoJSON JSON オブジェクトを逆シリアル化する必要があります。この json オブジェクトには、これが適用される場所があります
。
"type" : "name"
次の json オブジェクトは 1 つのタイプです。たとえば、次のように言います。
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
一方、もしあれば
"type": "link"
次の json オブジェクトは別の型です。たとえば、次のように言います。
"properties": {
"href": "http://example.com/crs/42",
"type": "proj4"
}
これで、次を含む PropertiesPOJO が作成されました。
private String name;
private String href;
private String type;
現在のソリューションでは、オブジェクトのタイプを確認する必要があるため、PropertiesPOJO のどの部分を考慮する必要があるかがわかります。これは良い習慣ではありません。NamePropertiesPOJO または LinkPropertiesPOJO に直接逆シリアル化するカスタム デシリアライザーを使用してこれを行うことをお勧めします。私が持っていた1つのアイデアは、配置することです
@JsonDeserialize(using=PropertiesDeserializer.class)
@JsonProperty("properties")
NamePropertiesPOJO namePropertiesPOJO = null;
@JsonDeserialize(using=PropertiesDeserializer.class)
@JsonProperty("properties")
LinkPropertiesPOJO linkPropertiesPOJO = null;
しかし、私は
JsonMappingException が発生しました: プロパティ "properties" を表す複数のフィールド:
それで、ジャクソンの注釈を使用してこれをもっとオブジェクト指向にする方法は他にありますか?
敬具、
デスポット