0
我想創建RestEasy的客戶端RestEasy的REST服務,提供這種實體:RestEasy客戶端:如何換行列表元素?
@SuppressWarnings("serial")
@Entity @Table(name="product")
@XmlRootElement(name="product")
public class Product implements Serializable, IHasTraits {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(columnDefinition = "INT UNSIGNED")
private Long id;
結果是
[{"id":1,"name":"FOO","note":null,...}]
然後我試圖通過一個接口來讀取它。 我期望可以使用相同的模型類。
@Path("/")
public interface RestClient {
@GET
@Path("/products")
@Produces("application/json")
public List<Product> getProducts();
使用
RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
this.client = ProxyFactory.create(RestClient.class, "http://localhost:8080/essc-portal/rest");
但客戶端拋出:
造成的:javax.xml.bind.UnmarshalException - 帶鏈接的異常:
[com.sun.istack .SAXParseException2; columnNumber:0;意外元素(uri:「」,local:「id」)。預計元素< {}產品>]
我試圖添加
@XmlElementWrapper(name="product")
或
@XmlElement(type = Product.class, name = "product")
或
@org.jboss.resteasy.annotations.providers.jaxb.Wrapped(element = "product")
但也沒有幫助。
我應該如何解決這個問題?我不想創建額外的bean類。