001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
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.ShoppingItem;
023    
024    import java.util.Date;
025    import java.util.List;
026    
027    /**
028     * @author    Brian Wing Shun Chan
029     * @generated
030     */
031    public class ShoppingItemJSONSerializer {
032            public static JSONObject toJSONObject(ShoppingItem model) {
033                    JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034    
035                    jsonObj.put("itemId", model.getItemId());
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("categoryId", model.getCategoryId());
061                    jsonObj.put("sku", model.getSku());
062                    jsonObj.put("name", model.getName());
063                    jsonObj.put("description", model.getDescription());
064                    jsonObj.put("properties", model.getProperties());
065                    jsonObj.put("fields", model.getFields());
066                    jsonObj.put("fieldsQuantities", model.getFieldsQuantities());
067                    jsonObj.put("minQuantity", model.getMinQuantity());
068                    jsonObj.put("maxQuantity", model.getMaxQuantity());
069                    jsonObj.put("price", model.getPrice());
070                    jsonObj.put("discount", model.getDiscount());
071                    jsonObj.put("taxable", model.getTaxable());
072                    jsonObj.put("shipping", model.getShipping());
073                    jsonObj.put("useShippingFormula", model.getUseShippingFormula());
074                    jsonObj.put("requiresShipping", model.getRequiresShipping());
075                    jsonObj.put("stockQuantity", model.getStockQuantity());
076                    jsonObj.put("featured", model.getFeatured());
077                    jsonObj.put("sale", model.getSale());
078                    jsonObj.put("smallImage", model.getSmallImage());
079                    jsonObj.put("smallImageId", model.getSmallImageId());
080                    jsonObj.put("smallImageURL", model.getSmallImageURL());
081                    jsonObj.put("mediumImage", model.getMediumImage());
082                    jsonObj.put("mediumImageId", model.getMediumImageId());
083                    jsonObj.put("mediumImageURL", model.getMediumImageURL());
084                    jsonObj.put("largeImage", model.getLargeImage());
085                    jsonObj.put("largeImageId", model.getLargeImageId());
086                    jsonObj.put("largeImageURL", model.getLargeImageURL());
087    
088                    return jsonObj;
089            }
090    
091            public static JSONArray toJSONArray(
092                    com.liferay.portlet.shopping.model.ShoppingItem[] models) {
093                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
094    
095                    for (ShoppingItem model : models) {
096                            jsonArray.put(toJSONObject(model));
097                    }
098    
099                    return jsonArray;
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(toJSONArray(model));
108                    }
109    
110                    return jsonArray;
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    }