在反序列化期间,Jackson在arrayList前面添加了空对象

时间:2017-09-26 09:39:15

标签: json spring jackson

我有一个简单的POJO(ProviderModel)。 当我反序列化这些对象的列表(请参阅代码:列表提供程序)时,会在JSON前面添加一个空对象。 我正在使用Jackson 1.9.13和Spring 3.0.7

@RequestMapping(value = "/provider/update", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
public List<ProviderModel> updateLongList(@RequestBody ArrayList<Map<String, Object>> models,
        HttpServletRequest request) {

    List<ProviderModel> providers = new ArrayList<ProviderModel>();

    for (Map<String, Object> model : models) {

        ProviderModel providerModel = new ProviderModel();
        providerModel.setId((int) model.get("id"));

        long rfpId = Long.parseLong((String) request.getSession().getAttribute("rfpId"));
        MYLOG.info("rfpId = " + rfpId);

        long listId = ProviderListLocalServiceUtil.findLongListforRfP(rfpId);
        User user = null;
        long userId = 0;

        try {
            user = OsdeUserUtil.getUserFromCookies(request);
            userId = user.getUserId();
        } catch (PortalException | SystemException | EncryptorException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        long providerId = providerModel.getId();            

        // add to LongList
        try {

            ProviderListEntryServiceUtil.addProviderListEntryByListId(listId, userId, providerId);
            providers.add(providerModel);

        } catch (SystemException | PortalException e) {

            // TODO Auto-generated catch block
            e.printStackTrace();

        }
        MYLOG.info("Provider hinzugefügt " + model.get("id") + "/" + model.get("name"));
    }

    return providers;
}

这就是回应:

{}
 && {
    "providerModelList": [{
            "id": 1502,
            "name": null,
            "location": null,
            "description": null,
            "imagePath": null,
            "detailUrl": null,
            "providerStatus": null
        }
    ]
}

任何想法或提示?

1 个答案:

答案 0 :(得分:0)

我发现了错误! 方法签名中缺少 @RespondBody

 @RequestMapping(value = "/provider/update", method = RequestMethod.POST)
    @ResponseStatus(HttpStatus.OK)
    public @RespondBody List<ProviderModel> updateLongList(@RequestBody ArrayList<Map<String, Object>> models,
            HttpServletRequest request) {...}