fastjson中JSONObject对象中的LocalDateTime属性值在远程调用过程中转为ArrayList类型的问题

非必要不要用JSONObject作为对象远程传输

服务A调用服务B,参数用JSONObject对象传输
服务A中设值LocalDateTime类型
服务B中取值ArrayList类型

//A
JSONObject jsonObject = new JSONObject();
jsonObject.put("now",LocalDateTime.now());

//B
JSONArray jsonArray = jsonObject.getJSONArray("now");
for (int i = 0; i < 6 - localDateTime.size(); i++) {
    // 秒没0
    localDateTime.add(0);
}
LocalDateTime ldt = LocalDateTime.of(localDateTime.getIntValue(0), localDateTime.getIntValue(1), localDateTime.getIntValue(2), localDateTime.getIntValue(3), localDateTime.getIntValue(4), localDateTime.getIntValue(5));

在取值的时候,如果正好秒为0,那JSONArray长度为5,有越界问题。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容