1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.shopping.service.http;
16  
17  import com.liferay.portal.kernel.json.JSONArray;
18  import com.liferay.portal.kernel.json.JSONFactoryUtil;
19  import com.liferay.portal.kernel.json.JSONObject;
20  import com.liferay.portal.kernel.util.StringPool;
21  
22  import com.liferay.portlet.shopping.model.ShoppingItem;
23  
24  import java.util.Date;
25  import java.util.List;
26  
27  /**
28   * <a href="ShoppingItemJSONSerializer.java.html"><b><i>View Source</i></b></a>
29   *
30   * <p>
31   * ServiceBuilder generated this class. Modifications in this class will be
32   * overwritten the next time is generated.
33   * </p>
34   *
35   * <p>
36   * This class is used by {@link ShoppingItemServiceJSON} to translate objects.
37   * </p>
38   *
39   * @author    Brian Wing Shun Chan
40   * @see       com.liferay.portlet.shopping.service.http.ShoppingItemServiceJSON
41   * @generated
42   */
43  public class ShoppingItemJSONSerializer {
44      public static JSONObject toJSONObject(ShoppingItem model) {
45          JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
46  
47          jsonObj.put("itemId", model.getItemId());
48          jsonObj.put("companyId", model.getCompanyId());
49          jsonObj.put("userId", model.getUserId());
50          jsonObj.put("userName", model.getUserName());
51  
52          Date createDate = model.getCreateDate();
53  
54          String createDateJSON = StringPool.BLANK;
55  
56          if (createDate != null) {
57              createDateJSON = String.valueOf(createDate.getTime());
58          }
59  
60          jsonObj.put("createDate", createDateJSON);
61  
62          Date modifiedDate = model.getModifiedDate();
63  
64          String modifiedDateJSON = StringPool.BLANK;
65  
66          if (modifiedDate != null) {
67              modifiedDateJSON = String.valueOf(modifiedDate.getTime());
68          }
69  
70          jsonObj.put("modifiedDate", modifiedDateJSON);
71          jsonObj.put("categoryId", model.getCategoryId());
72          jsonObj.put("sku", model.getSku());
73          jsonObj.put("name", model.getName());
74          jsonObj.put("description", model.getDescription());
75          jsonObj.put("properties", model.getProperties());
76          jsonObj.put("fields", model.getFields());
77          jsonObj.put("fieldsQuantities", model.getFieldsQuantities());
78          jsonObj.put("minQuantity", model.getMinQuantity());
79          jsonObj.put("maxQuantity", model.getMaxQuantity());
80          jsonObj.put("price", model.getPrice());
81          jsonObj.put("discount", model.getDiscount());
82          jsonObj.put("taxable", model.getTaxable());
83          jsonObj.put("shipping", model.getShipping());
84          jsonObj.put("useShippingFormula", model.getUseShippingFormula());
85          jsonObj.put("requiresShipping", model.getRequiresShipping());
86          jsonObj.put("stockQuantity", model.getStockQuantity());
87          jsonObj.put("featured", model.getFeatured());
88          jsonObj.put("sale", model.getSale());
89          jsonObj.put("smallImage", model.getSmallImage());
90          jsonObj.put("smallImageId", model.getSmallImageId());
91          jsonObj.put("smallImageURL", model.getSmallImageURL());
92          jsonObj.put("mediumImage", model.getMediumImage());
93          jsonObj.put("mediumImageId", model.getMediumImageId());
94          jsonObj.put("mediumImageURL", model.getMediumImageURL());
95          jsonObj.put("largeImage", model.getLargeImage());
96          jsonObj.put("largeImageId", model.getLargeImageId());
97          jsonObj.put("largeImageURL", model.getLargeImageURL());
98  
99          return jsonObj;
100     }
101 
102     public static JSONArray toJSONArray(
103         com.liferay.portlet.shopping.model.ShoppingItem[] models) {
104         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
105 
106         for (ShoppingItem model : models) {
107             jsonArray.put(toJSONObject(model));
108         }
109 
110         return jsonArray;
111     }
112 
113     public static JSONArray toJSONArray(
114         com.liferay.portlet.shopping.model.ShoppingItem[][] models) {
115         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
116 
117         for (ShoppingItem[] model : models) {
118             jsonArray.put(toJSONArray(model));
119         }
120 
121         return jsonArray;
122     }
123 
124     public static JSONArray toJSONArray(
125         List<com.liferay.portlet.shopping.model.ShoppingItem> models) {
126         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
127 
128         for (ShoppingItem model : models) {
129             jsonArray.put(toJSONObject(model));
130         }
131 
132         return jsonArray;
133     }
134 }