使用jackson将包含整数时间戳的json转换为'java.util.Date'并启用默认类型

时间:2013-12-21 12:09:28

标签: java jackson

我在尝试转换my java对象中的JSON对象时遇到了困难。我从服务器得到以下响应(我无法修改服务器端的东西):

["com.transer.money.MyResponse",
  {
    movements:
      ["java.util.ArrayList",
        [
          ["com.transer.money.Movement",
            {
              threshold:
                ["com.transer.money.Amount",
                  {
                    value:["java.math.BigDecimal",4.],
                    currencyCode:"USD"
                  }
                ],
              minAmount:null,
              ,
              sourceBalance:
                ["com.transer.money.Issuer",
                  {
                    Id:"EAA063862",
                    currencyCode:"USD
                  }
                ],
              sourceEndpoint:
                ["com.transer.money.BusinessEndpoint",
                  {
                    currencyCode:"USD",
                    clientId:"1",
                    appId:"62"
                  }
                ],
              destinationEndpoint:
                ["com.transer.money.BankEndpoint",
                  {
                    currencyCode:"USD",
                    customerId:"A06P3BKSNFY",
                    Id:"4cfbbd47"
                  }
                ]
            }
          ]
        ]
      ],
    transactionId:"A82319",
    created:355643314
  }
]

反序列化时我收到错误:

Unexpected token (VALUE_NUMBER_INT), expected START_ARRAY: need JSON Array to contain As.WRAPPER_ARRAY type information for class java.util.Date

我的代码如下:

ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping(org.codehaus.jackson.map.ObjectMapper.DefaultTyping.NON_FINAL);
com.transer.money.MyResponse.resp = mapper.readValue(jsonString, com.transer.money.MyResponse.class);

如果我省略了行mapper.enableDefaultTyping(org.codehaus.jackson.map.ObjectMapper.DefaultTyping.NON_FINAL);,我会收到错误 Cannot deserialize instance of com.transfer.money.MyResponse out of START_ARRAY token at [Source: N/A; line: -1, column: -1]

我会非常感谢这里的任何回复,因为我已经尝试了各种各样的事情,但似乎没有任何事情与日期有关。

由于

0 个答案:

没有答案