java - 将泛型类型的Json转换为特定的Json格式

标签 java json

我正在使用 Java 8,并且尝试使用“Collectors.groupingBy”,但尚未获得所需的格式

public class ConsigneeLoadDetails {

    private Integer tripID;
    private String consignor;
    private String consignee;
    private String city;
    private Double distanceToNext;
    private Double load;
    private Integer cap;
    private Integer vehicleCapacity;
    private Double cLoad;
    private Integer truckUtilisation;
    private Double latitude;
    private Double longitude;  

    // getter , setter of all parameters 
}



List<ConsigneeLoadDetails> listConsigneeLoadDetails = new ArrayList();

// loop to add ConsigneeLoadDetails

listConsigneeLoadDetails.add(consigneeLoadDetails);

我的 API 响应低于 Json

enter image description here

我想要以下格式的回复

enter image description here

最佳答案

为什么不重新安排你的 POJO 类,就像这样

public class ConsigneeLoadDetails {

    private Integer tripID;
    private String consignor;
    private Integer vehicleCapacity;
    private Double cLoad;
    private Integer truckUtilisation;
    private List<consigneeDetails> consigneeDetails    
    private Double latitude;
    private Double longitude;  

    // getter , setter of all parameters 
}

public class ConsigneeDetails {

    private String consignee;
    private String city;
    private Double distanceToNext;
    private Double load;
    private Integer cap;

    // getter , setter of all parameters 
}

关于java - 将泛型类型的Json转换为特定的Json格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58023274/

相关文章:

Java字符数组转二进制字符串

java - Hibernate setMaxResult 导致异常

java - 使矩形透明

php - 使用未知键通过 PHP 将关联数组插入 MySQL

java - Elasticsearch 匹配完整的术语数组

java - swing Jform 创建

jquery - Rails,发送 json 参数

c# - System.Text.Json 中 Newtonsoft.Json 的 JsonProperty 属性的等效项是什么?

Android facebook 登录小部件 : org. json.JSONException

javascript - 具有多个值的 Mongo $addToSet 语法正确