私は抽象クラス車持っている:私は車を拡張カー 1つのクラスを持ってジャクソンフィルタおよび多型
@JsonFilter('Vehicle_Filter')
public abstract class Vehicle {
private String brand;
private int nbOfWheels;
//Other attributes, constructor & methods
}
を:
@JsonFilter('Car_Filter')
public class Car extends Vehicle {
private int nbOfDoors;
private boolean isElectric;
//Other attributes, constructor & methods
}
そして、私は持っていますもう1つの子クラス自転車車延長:
@JsonFilter('Bike_Filter')
public class Bike extends Vehicle {
private double tirePressure;
private boolean isAllTerrain;
//Other attributes, constructor & methods
}
01私はfasterXMLからジャクソンを(使用して、それをシリアル化します、そのために @JsonFilter('VehicleCollection_Filter')
public abstract class VehicleCollection {
private List<Vehicle> vehicles;
//Other attributes, constructor & methods
}
:
のは、私はHTMLページに表示したいと思う車のリストを表すクラスVehicleCollectionを持っているとしましょう)。 各車両の一部の属性のみを表示したいとします。 FilterProviderインターフェイスを使用します。
質問は次のとおりです。車の属性をフィルタリングするときは、自転車か車かを区別したくありません。重要なのは、それがビークルだということです。私はフィルタリングするとき、私はそれを考え出すことができると思った:
FilterProvider filterProvider = new SimpleFilterProvider()
.addFilter("VehicleCollection_Filter", SimpleBeanPropertyFilter.filterOutAllExcept("vehicles"))
.addFilter("Vehicle_Filter", SimpleBeanPropertyFilter.filterOutAllExcept("brand", "nbOfDoors", "isElectric"));
を...しかし、ライターを呼び出すときに、このエラーがスローされます。Could not find filter with id: 'Car_Filter'
。ジャクソンは多型について聞きたくないと思われます...
誰も同じ問題がありましたか?はいの場合、それを克服するためのヒントはありますか?もしそうでなければ、なぜジャクソンが継承を扱うことができないのかについての何らかのドキュメンテーションや暗黙の説明がありますか?
重要なのは、なぜそれが車両なのですか?あなたは '@JsonFilter( 'Car_Filter')'を持っていますか?と '@JsonFilter( 'Bike_Filter')'? – Oleg
アプリケーションの他の部分では、車とバイクを個別に表示する必要があるので、 –