我用http://www.jsonschema2pojo.org/从json模板创建了一个类,并使用Genson将我的json映射为基于泽西岛的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来处理post请求,并且我尝试用火狐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。
请帮帮我!谢谢!
发布于 2015-10-25 21:18:52
这是我想的名字造成的。在您的json中,我们可以看到在单词边界处使用大写的下划线insead。比如due_date而不是dueDate。我假设代码中的属性遵循通常的java命名方式,并以大写字母表示。
一种解决方案是使用@JsonProperty对这些集合进行注释,并获得将名称从"dueDate“更改为"due_date”的方法。
顺便说一下,生成的代码不是Genson的,JsonPropertyOrder不是Genson注释。
https://stackoverflow.com/questions/33332813
复制相似问题