【发布时间】:2015-10-21 11:13:07
【问题描述】:
我正在开发网络 API。 (使用java,jersey)(数据格式json)
以下是示例数据格式。
customerID
customerName
customerCity
products
product1 quantity1
product2 quantity2
product3 quantity3
正如您在上面的数据中看到的,产品是一个数组(产品和数量)。
为了提供这些数据(json 格式),我使用了 POJO:
public class CustomerOrder
{
private String customerID;
private String customerName;
private String customerCity;
private ArrayList<Product> products;
//getters & setters for above 4 variables
public CustomerOrder() {} //Constructor without parameter
public CustomerOrder(....) {....} //Constructor with above 4 parameter
public class Product
{
private String product;
private int quantity;
//getters & setters for above 2 variables
}
}
使用上面的 POJO:
ArrayList<CustomerOrder> customerOrderList = new ArrayList<CustomerOrder>();
ArrayList<Product> customerOrderProductList = new ArrayList<Product>();
//statements to add data in customerOrderProductList
//add data in customerOrderList
customerOrderList.add(
customerID,
customerName,
customerCity,
customerOrderProductList
);
我的问题是,这是处理上述数据格式的最佳(标准)方法吗?或者有没有更好的方法?
【问题讨论】: