001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.ratings.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.ratings.model.RatingsEntry;
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 RatingsEntryJSONSerializer {
032            public static JSONObject toJSONObject(RatingsEntry model) {
033                    JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034    
035                    jsonObj.put("entryId", model.getEntryId());
036                    jsonObj.put("companyId", model.getCompanyId());
037                    jsonObj.put("userId", model.getUserId());
038                    jsonObj.put("userName", model.getUserName());
039    
040                    Date createDate = model.getCreateDate();
041    
042                    String createDateJSON = StringPool.BLANK;
043    
044                    if (createDate != null) {
045                            createDateJSON = String.valueOf(createDate.getTime());
046                    }
047    
048                    jsonObj.put("createDate", createDateJSON);
049    
050                    Date modifiedDate = model.getModifiedDate();
051    
052                    String modifiedDateJSON = StringPool.BLANK;
053    
054                    if (modifiedDate != null) {
055                            modifiedDateJSON = String.valueOf(modifiedDate.getTime());
056                    }
057    
058                    jsonObj.put("modifiedDate", modifiedDateJSON);
059                    jsonObj.put("classNameId", model.getClassNameId());
060                    jsonObj.put("classPK", model.getClassPK());
061                    jsonObj.put("score", model.getScore());
062    
063                    return jsonObj;
064            }
065    
066            public static JSONArray toJSONArray(
067                    com.liferay.portlet.ratings.model.RatingsEntry[] models) {
068                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
069    
070                    for (RatingsEntry model : models) {
071                            jsonArray.put(toJSONObject(model));
072                    }
073    
074                    return jsonArray;
075            }
076    
077            public static JSONArray toJSONArray(
078                    com.liferay.portlet.ratings.model.RatingsEntry[][] models) {
079                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
080    
081                    for (RatingsEntry[] model : models) {
082                            jsonArray.put(toJSONArray(model));
083                    }
084    
085                    return jsonArray;
086            }
087    
088            public static JSONArray toJSONArray(
089                    List<com.liferay.portlet.ratings.model.RatingsEntry> models) {
090                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
091    
092                    for (RatingsEntry model : models) {
093                            jsonArray.put(toJSONObject(model));
094                    }
095    
096                    return jsonArray;
097            }
098    }