【发布时间】:2016-01-24 18:55:54
【问题描述】:
我使用 http://www.jsonschema2pojo.org/ 从 json 模板创建了一个类,并使用 Genson 将我的 json 映射到基于 Jersey 的 WS。 这是我的“json 类”的第一行:
@JsonPropertyOrder({
"public_key",
"template",
"signature",
"due_date",
"fulfillment_date",
"template_lang_code",
"clients_id",
"electronic_invoice",
"is_draft",
"recurring_time",
"comment",
"currency",
"items",
"payment_method",
"ts"
})
public class CreateInvoiceBean {
...
...
我的班级也有 getter 和 setter。
我创建了一个 restfull Ws 来处理 post 请求,我尝试使用 firefox RESTClinent 插件发送 jsons 对象。
这是我尝试发送的 json 对象的第一行:
{
"public_key": "7f566499549fc9e6d9cc69ca3b10d5f5",
"template": "billingo",
"signature": "9273882e8b3bc7f57e1ef3bc10041bc4bf9d835c152a1e0b810b77b3d51864ad",
"due_date": "2015-10-30",
...
...}
我的 WS Post 处理程序方法如下所示:
@POST
@Path("/invoice")
@Consumes("application/json")
@Produces("application/json")
public String createInvoice(CreateInvoiceBean newBillingoInvoice) {
LOG.info("invoicenum:. " + newBillingoInvoice.getDueDate());
return newBillingoInvoice.getDueDate();
}
我的请求到达,并调用了 createInvoice() 方法,但如果我调用 newBillingoInvoice.getDueDate() 它返回 null,但是当我调用 newBillingoInvoice.getSignature() 它返回的值是我在请求 json 中发送的值......等等。 . 如果我调用newBillingoInvoice.getXY(); 返回null 并且如果我调用newBillingoInvoice.getOtherSomething(); 返回值.. 等等..
我的问题是,一个属性是null 而另一个属性不是null 怎么会发生在同一个对象中?当我创建请求时,我设置了所有属性,其中没有一个是 null。
请帮帮我! 谢谢!
【问题讨论】:
标签: java json web-services genson