java org.json_java – 无法编写JSON:没有为类org.json.JSONO...

我已经将响应设置为JSON但是得到了这个

Could not write JSON: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)

@RequestMapping(value = "/customerlist", method = RequestMethod.POST)

public ResponseGenerator getCustomerList() {

ResponseGenerator responseGenerator = new ResponseGenerator();

try {

responseGenerator.setCode(StatusCode.SUCCESS.code);

responseGenerator.setMessage(StatusCode.SUCCESS.message);

responseGenerator.setStatus(ResponseStatus.SUCCESS);

JSONObject data = userService.getUserList();

responseGenerator.setJSONData(data);

return responseGenerator; //error here

} catch (Exception e) {

logger.error("Error while getting Customer List : ", e);

e.printStackTrace();

responseGenerator.setCode(StatusCode.GENERAL_ERROR.code);

responseGenerator.setMessage(StatusCode.GENERAL_ERROR.message);

responseGenerator.setStatus(ResponseStatus.FAIL);

return responseGenerator;

}

}

userService.getUserList():

public JSONObject jsonResp;

public JSONObject getUserList() throws Exception{

jsonResp =new JSONObject();

//List customers = new ArrayList();

JSONObject jsonResponse = erpNextAPIClientService.getCustomerList();

//ObjectMapper objectMapper = new ObjectMapper();

//objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);

//JSONArray jsonArray = objectMapper.convertValue(jsonResponse.get("data"), JSONArray.class);

JSONArray jsonArray = jsonResponse.getJSONArray("data");

//JSONArray jsonArray =new Gson().fromJson(jsonResponse.get("data").toString(),JSONArray.class);

for (int i = 0; i < jsonArray.length(); i++) {

JSONObject cust = erpNextAPIClientService.getUser(jsonArray.getJSONObject(i).get("name").toString());

JSONObject custAddress =erpNextAPIClientService.getCustomerAddress(jsonArray.getJSONObject(i).get("name").toString());

JSONObject custData = new JSONObject(cust.getString("data"));

JSONObject custAddressData = new JSONObject(custAddress.getString("data"));

custData.accumulate("bill_to_address_line_one",custAddressData.get("address_line1"));

custData.accumulate("bill_to_address_line_two",custAddressData.get("address_line2"));

custData.accumulate("bill_to_city",custAddressData.get("city"));

custData.accumulate("bill_to_state",custAddressData.get("state"));

custData.accumulate("bill_to_zip",custAddressData.get("pincode"));

custData.accumulate("bill_to_country",custAddressData.get("country"));

jsonResp.put("data",custData);

System.out.println(custData.toString());

//customers.add(custData);

}

return jsonResp;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值