把对象转换为json,在postman传递请求

    public static void main(String[] args) {
        PackSaveTimeReq packSaveTimeReq = new PackSaveTimeReq();
        packSaveTimeReq.setType(ThirdPartyOperationTypeEnum.WORK_START);
        packSaveTimeReq.setOperationTime(LocalDateTime.now());
        packSaveTimeReq.setLotTracingHistoryId(1L);
        packSaveTimeReq.setProductionBatchNo("TESTGD951515");
        String jsonStr = JacksonUtils.toJsonStr(packSaveTimeReq);
        String json = JacksonUtils.toJsonStr(jsonStr);
        System.out.println("json = " + json);
    }

postman请求

{ 
    "bizCode":"command.pack.discharge.time.save",
    "json":"{\"type\":20,\"productionBatchNo\":\"TESTGD951515\",\"operationTime\":\"2024-10-21 15:53:28\",\"lotTracingHistoryId\":\"1\"}"
}

使用的是JacksonUtils.toJsonStr方法

posted @ 2024-10-21 16:18  多多指教~  阅读(7)  评论(0编辑  收藏  举报