如何在 REST Web 服务中发送 JSON 数据?
我有一个 json 对象,其中包含产品 Id、商店 Id、价格、产品单位、数量
值。这里除产品单位值外,所有值均为整数。
现在,我想将这些值发送到其余的 Web 服务中。
能否请您提供一些样品或任何宝贵的建议?
您的 JSON 输入:
{
"productId": "p123",
"storeId": "s456",
"price": 12.34,
"productUnit": "u789",
"quantity": 42
}
JAXB 类:
@XmlRootElement
public class MyJaxbBean {
public String productId;
public String storeId;
public double price;
public String productUnit;
public int quantity;
public MyJaxbBean() {} // JAXB needs this
public MyJaxbBean(String productId, String storeId, double price, String productUnit, int quantity) {
// set members
}
}
JAX-RS 方法。
@PUT
@Consumes("application/json")
public Response putMyBean(MyJaxbBean theInput) {
// Do something with theInput
return Response.created().build();
}
See 泽西岛的文档 https://jersey.java.net/documentation/latest/media.html#json(JAX-RS 的 RI)了解详细信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)