I have two object of arraylist orderList
, productList
and one String arraylist customerIdList
.
I have ProductInfo
POJO to be mapped with orderList and productList where cuustomerId should match.
If I don't have order or productlist for given ProdId I should add standard Error and map to the ProductInfo Error.
Here is what I am doing ...
public class ProductInfo {
private List<ProductDetails> products;
private List<Error> errors;
private String customerId;
}
public class ProductDetails {
private String customerId;
private Order order;
private Product product;
private List<Error> errors;
}
Sample result ...
{
"productInfo": {
"customer_id": "123",
"product_details": [
{
"customer_id": "123",
"order_details": null,
"product_details": {
"customer_id": "123"
"product_id" : "2343"
"product_name": "XYZ",
"product_type": "PQR"
...
},
"errors": [
"error_code":"6001",
"error_desc":"Failure in getting Order information from Order Service"
]
},
{
"order_details": {
"customer_id":"123"
"order_id": "3543454",
"order_date":"2016-10-12",
"order_status":"ordered"
},
"product_details": null,
"errors": [
"error_code":"6001",
"error_desc":"Failure in getting Product information from Product Service"
]
}
],
"system_errors":[]
}
}
Looping over ArrayList and Mapping
for(String customerId : customerIdList) {
for(Product product: productList) {
for(SOrder ordr: orderList) {
if(customerId.equals(product.getCustomerId()) && customerId.equals(Order.getCustomerId()) ) {
ModelMapper mapper = new ModelMapper();
Order order = mapper.map(ordr, Order.class));
productDetails.setOrder(order);
//mapping to ProductInfo
productDetailsList.add(productDetails);
}
}
}
}
I want to know if there is any better way of doing this and also I am using ModelMapper
to map SOrder
to Order
POJO and
other POJOs would like to know if there is any other efficient model mapper available.
Thanks.