タイトルが正しいことを願ってい@Path
ますが、エンティティ パラメーターに基づいて、JAX-RS アノテーションを使用してリクエストをさまざまなメソッドにマップしようとしています。
サンプルコードで簡単になると思います:
スーパークラス:
public class Geothing {
private int thingId;
private String status;
// Ctor, getters and setters
}
PolygonGeothing は Geothing を拡張します。
@XmlRootElement
public class PolygonGeothing extends Geothing {
private Coordinates coordinates;
// Ctor, getters and setters
}
CircleGeothing は Geothing を拡張します。
@XmlRootElement
public class CircleGeothing extends Geothing {
private Coordinate center;
private int radius;
// Ctor, getters and setters
}
サービス インターフェイス:
@Path("/geothing/{id}")
public interface GeothingService extends CoService {
@POST
Response createGeothing(@PathParam("{id}") Long id, PolygonGeothing geothing);
@POST
Response createGeothing(@PathParam("{id}") Long id, CircleGeothing geothing);
}
PolygonGeothing または CircleGeothing の XML を POST した場合、それが機能することを期待していました。ただし、PolygonGeothing XML を POST した場合にのみ機能し、CircleGeothing XML を POST すると JAXBException が発生します。
JAXBException occurred : unexpected element (uri:"", local:"circleGeothing"). Expected elements are <{}polygonGeothing>.
CircleGeothing と PolygonGeothing に別の URI パスを指定しなくても、これを正しくマッピングすることは可能ですか? さらに、スーパークラスをパラメータとして使用できる次のようなインターフェースを持つことは可能ですか? 返されるタイプ Geothing をテストしました。PolygonGeothing または CircleGeothing を作成して返すと、正常に動作します...ただし、パラメータ タイプが Geothing であるパラメータとして PolygonGeothing または CircleGeothing を渡そうとすると、うまくいきません。
@Path("/geothing/{id}")
public interface GeothingService extends CoService {
@POST
Response createGeothing(@PathParam("{id}") Long id, Geothing geothing);
}