1
22
23 package com.liferay.portlet.shopping.service.http;
24
25 import com.liferay.portal.kernel.json.JSONArray;
26 import com.liferay.portal.kernel.json.JSONFactoryUtil;
27 import com.liferay.portal.kernel.json.JSONObject;
28 import com.liferay.portal.kernel.util.StringPool;
29
30 import com.liferay.portlet.shopping.model.ShoppingItem;
31
32 import java.util.Date;
33 import java.util.List;
34
35
54 public class ShoppingItemJSONSerializer {
55 public static JSONObject toJSONObject(ShoppingItem model) {
56 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
57
58 jsonObj.put("itemId", model.getItemId());
59 jsonObj.put("companyId", model.getCompanyId());
60 jsonObj.put("userId", model.getUserId());
61 jsonObj.put("userName", model.getUserName());
62
63 Date createDate = model.getCreateDate();
64
65 String createDateJSON = StringPool.BLANK;
66
67 if (createDate != null) {
68 createDateJSON = String.valueOf(createDate.getTime());
69 }
70
71 jsonObj.put("createDate", createDateJSON);
72
73 Date modifiedDate = model.getModifiedDate();
74
75 String modifiedDateJSON = StringPool.BLANK;
76
77 if (modifiedDate != null) {
78 modifiedDateJSON = String.valueOf(modifiedDate.getTime());
79 }
80
81 jsonObj.put("modifiedDate", modifiedDateJSON);
82 jsonObj.put("categoryId", model.getCategoryId());
83 jsonObj.put("sku", model.getSku());
84 jsonObj.put("name", model.getName());
85 jsonObj.put("description", model.getDescription());
86 jsonObj.put("properties", model.getProperties());
87 jsonObj.put("fields", model.getFields());
88 jsonObj.put("fieldsQuantities", model.getFieldsQuantities());
89 jsonObj.put("minQuantity", model.getMinQuantity());
90 jsonObj.put("maxQuantity", model.getMaxQuantity());
91 jsonObj.put("price", model.getPrice());
92 jsonObj.put("discount", model.getDiscount());
93 jsonObj.put("taxable", model.getTaxable());
94 jsonObj.put("shipping", model.getShipping());
95 jsonObj.put("useShippingFormula", model.getUseShippingFormula());
96 jsonObj.put("requiresShipping", model.getRequiresShipping());
97 jsonObj.put("stockQuantity", model.getStockQuantity());
98 jsonObj.put("featured", model.getFeatured());
99 jsonObj.put("sale", model.getSale());
100 jsonObj.put("smallImage", model.getSmallImage());
101 jsonObj.put("smallImageId", model.getSmallImageId());
102 jsonObj.put("smallImageURL", model.getSmallImageURL());
103 jsonObj.put("mediumImage", model.getMediumImage());
104 jsonObj.put("mediumImageId", model.getMediumImageId());
105 jsonObj.put("mediumImageURL", model.getMediumImageURL());
106 jsonObj.put("largeImage", model.getLargeImage());
107 jsonObj.put("largeImageId", model.getLargeImageId());
108 jsonObj.put("largeImageURL", model.getLargeImageURL());
109
110 return jsonObj;
111 }
112
113 public static JSONArray toJSONArray(
114 List<com.liferay.portlet.shopping.model.ShoppingItem> models) {
115 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
116
117 for (ShoppingItem model : models) {
118 jsonArray.put(toJSONObject(model));
119 }
120
121 return jsonArray;
122 }
123 }