001
014
015 package com.liferay.portlet.shopping.service.http;
016
017 import com.liferay.portal.kernel.json.JSONArray;
018 import com.liferay.portal.kernel.json.JSONFactoryUtil;
019 import com.liferay.portal.kernel.json.JSONObject;
020 import com.liferay.portal.kernel.util.StringPool;
021
022 import com.liferay.portlet.shopping.model.ShoppingCoupon;
023
024 import java.util.Date;
025 import java.util.List;
026
027
031 public class ShoppingCouponJSONSerializer {
032 public static JSONObject toJSONObject(ShoppingCoupon model) {
033 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034
035 jsonObj.put("couponId", model.getCouponId());
036 jsonObj.put("groupId", model.getGroupId());
037 jsonObj.put("companyId", model.getCompanyId());
038 jsonObj.put("userId", model.getUserId());
039 jsonObj.put("userName", model.getUserName());
040
041 Date createDate = model.getCreateDate();
042
043 String createDateJSON = StringPool.BLANK;
044
045 if (createDate != null) {
046 createDateJSON = String.valueOf(createDate.getTime());
047 }
048
049 jsonObj.put("createDate", createDateJSON);
050
051 Date modifiedDate = model.getModifiedDate();
052
053 String modifiedDateJSON = StringPool.BLANK;
054
055 if (modifiedDate != null) {
056 modifiedDateJSON = String.valueOf(modifiedDate.getTime());
057 }
058
059 jsonObj.put("modifiedDate", modifiedDateJSON);
060 jsonObj.put("code", model.getCode());
061 jsonObj.put("name", model.getName());
062 jsonObj.put("description", model.getDescription());
063
064 Date startDate = model.getStartDate();
065
066 String startDateJSON = StringPool.BLANK;
067
068 if (startDate != null) {
069 startDateJSON = String.valueOf(startDate.getTime());
070 }
071
072 jsonObj.put("startDate", startDateJSON);
073
074 Date endDate = model.getEndDate();
075
076 String endDateJSON = StringPool.BLANK;
077
078 if (endDate != null) {
079 endDateJSON = String.valueOf(endDate.getTime());
080 }
081
082 jsonObj.put("endDate", endDateJSON);
083 jsonObj.put("active", model.getActive());
084 jsonObj.put("limitCategories", model.getLimitCategories());
085 jsonObj.put("limitSkus", model.getLimitSkus());
086 jsonObj.put("minOrder", model.getMinOrder());
087 jsonObj.put("discount", model.getDiscount());
088 jsonObj.put("discountType", model.getDiscountType());
089
090 return jsonObj;
091 }
092
093 public static JSONArray toJSONArray(
094 com.liferay.portlet.shopping.model.ShoppingCoupon[] models) {
095 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
096
097 for (ShoppingCoupon model : models) {
098 jsonArray.put(toJSONObject(model));
099 }
100
101 return jsonArray;
102 }
103
104 public static JSONArray toJSONArray(
105 com.liferay.portlet.shopping.model.ShoppingCoupon[][] models) {
106 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
107
108 for (ShoppingCoupon[] model : models) {
109 jsonArray.put(toJSONArray(model));
110 }
111
112 return jsonArray;
113 }
114
115 public static JSONArray toJSONArray(
116 List<com.liferay.portlet.shopping.model.ShoppingCoupon> models) {
117 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
118
119 for (ShoppingCoupon model : models) {
120 jsonArray.put(toJSONObject(model));
121 }
122
123 return jsonArray;
124 }
125 }