Всем привет.
Есть исходный List:
Order.java
package main.java;
import java.util.ArrayList;
import java.util.List;
public class Order {
private String date;
private String docTypesName;
private String docId;
private String image;
private String name;
private double price;
private int quantity;
private int removed;
public Order(String date, String docTypesName, String docId, String image, String name, double price, int quantity, int removed) {
this.date = date;
this.docTypesName = docTypesName;
this.docId = docId;
this.image = image;
this.name = name;
this.price = price;
this.quantity = quantity;
this.removed = removed;
}
@Override
public String toString() {
return "Order{" +
"date='" + date + '\'' +
", docTypesName='" + docTypesName + '\'' +
", docId=" + docId +
", image='" + image + '\'' +
", name='" + name + '\'' +
", price=" + price +
", quantity=" + quantity +
", removed=" + removed +
'}';
}
}
class Test2 {
public static void main(String[] args) {
Order order = new Order("2017-10-16 12:07:07",
"Приход",
"564564867361367",
"https://www.komus.ru/medias/sys_master/root/hd3/h93/9286922043422.jpg",
"Молочный Изюм 100",
102,
45,
0);
Order order2 = new Order("2017-10-16 12:07:07",
"Приход",
"564564867361367",
"https://mariupolcena.com/files/products/9ff44136e6ccb0afb404ad26f727e67d.jpeg",
"Русская картошка чедар 50",
46.3,
45,
0);
Order order3 = new Order("2017-10-16 12:07:07",
"Расход",
"564564867361367",
"https://mariupolcena.com/files/products/9ff44136e6ccb0afb404ad26f727e67d.jpeg",
"Русская картошка чедар 50",
46.3,
45,
0);
Order order4 = new Order("2017-11-29 17:26:57",
"Расход",
"564564867361365",
"https://www.komus.ru/medias/sys_master/root/hd3/h93/9286922043422.jpg",
"Молочный Изюм 100",
102,
6,
0);
List<Order> orderList = new ArrayList<>();
orderList.add(order);
orderList.add(order2);
orderList.add(order3);
orderList.add(order4);
System.out.println(orderList);
}
}
Его JSON представление:
[
{
"date": "2017-10-16 12:07:07",
"docTypesName": "Приход",
"docId": 564564867361367,
"image": "https://www.komus.ru/medias/sys_master/root/hd3/h93/9286922043422.jpg",
"name": "Молочный Изюм 100",
"price": 102,
"quantity": 45,
"removed": 0
},
{
"date": "2017-10-16 12:07:07",
"docTypesName": "Приход",
"docId": 564564867361367,
"image": "https://mariupolcena.com/files/products/9ff44136e6ccb0afb404ad26f727e67d.jpeg",
"name": "Русская картошка чедар 50",
"price": 46.3,
"quantity": 45,
"removed": 0
},
{
"date": "2017-10-16 12:07:07",
"docTypesName": "Расход",
"docId": 564564867361367,
"image": "https://mariupolcena.com/files/products/9ff44136e6ccb0afb404ad26f727e67d.jpeg",
"name": "Русская картошка чедар 50",
"price": 46.3,
"quantity": 45,
"removed": 0
},
{
"date": "2017-11-29 17:26:57",
"docTypesName": "Расход",
"docId": 564564867361365,
"image": "https://www.komus.ru/medias/sys_master/root/hd3/h93/9286922043422.jpg",
"name": "Молочный Изюм 100",
"price": 102,
"quantity": 6,
"removed": 0
},
]
Структура, которую нужно получить (JSON представление):
[
{
"date": "2017-10-16",
documents: [
{
date: "2017-10-16 12:07:07",
docId: "564564867361367",
docTypesName: "Приход",
products: [
{
"image": "https://www.komus.ru/medias/sys_master/root/hd3/h93/9286922043422.jpg",
"name": "Молочный Изюм 100",
"price": 102,
"quantity": 45,
},
{
"image": "https://mariupolcena.com/files/products/9ff44136e6ccb0afb404ad26f727e67d.jpeg",
"name": "Русская картошка чедар 50",
"price": 46.3,
"quantity": 45,
}
]
},
{
"date": "2017-10-16 12:07:07",
"docId": 564564867361367,
"docTypesName": 'Расход',
"products": [
{
"image": "https://mariupolcena.com/files/products/9ff44136e6ccb0afb404ad26f727e67d.jpeg",
"name": "Русская картошка чедар 50",
"price": 46.3,
"quantity": 45,
}
]
}
]
},
{
"date": "2017-11-29",
"documents": [
{
"date": "2017-11-29 17:26:57",
"docId": 564564867361365,
"docTypesName": 'Расход',
"products": [
{
"image": "https://www.komus.ru/medias/sys_master/root/hd3/h93/9286922043422.jpg",
"name": "Молочный Изюм 100",
"price": 102,
"quantity": 6,
}
]
}
]
}
]
Подскажите пожалуйста, как сделать данное преобразование?