2

I have a problem: 3 つの子クラス Student、Teacher、Parent があります。

public class Person implements Serializable{

private String name;

private String address;}

学生:

public class Student extends Person {

private String cardNo;

}

スプリングレスト :

@RequestMapping(method = RequestMethod.POST, value = "/create")
@ResponseBody
public CemeteryRestResponse<Boolean> create(
        @RequestBody Person person) throws Exception {.....}

この 3 つの役割を作成するには、one rest メソッドを使用したいと考えています。しかし、クライアント ポスト Student as JSON では、例外がスローされます。

org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "cardNo"

前もって感謝します!

4

1 に答える 1

1

Jackson ライブラリは、多態的な型の処理をサポートしています。探している特定の注釈は@JsonTypeInfo注釈であり、それを基本クラス (Personクラス) に適用する必要があります。

この機能はバージョン 1.5 で追加されました。

于 2013-04-22T02:56:20.387 に答える