[英]Class hierarchy in a REST method
在我的REST API中,我在POST請求中獲得了一個JSON對象@“ api / register”,可以是
{"role": "customer", "firstname": "something"}
要么
{"role": "dealer", "firstname": "something", "taxnumber": "1234"}
因此, Customer
是Dealer
的子集, Dealer
是特定的,並且包含Customer
擁有的每個屬性以及更多屬性。
我不知道類的層次結構。 通常,我只會執行以下操作:
class Dealer extends Customer
但這不適用於我的REST方法:
@POST
public Response create(Customer c)
我可以編寫一個都實現的接口,但這似乎是虛假的。 還有更好的主意嗎?
您的類層次結構很好。 我認為您需要調整API設計。 具有可以發布兩種資源的API端點令人困惑。
將類似api/customers
映射到:
@POST
public Response create(Customer c)
和api/dealers
映射到:
@POST
public Response create(Dealer d)
這更清晰,更靈活。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.