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.announcements.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.announcements.model.AnnouncementsEntry;
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 AnnouncementsEntryJSONSerializer {
032            public static JSONObject toJSONObject(AnnouncementsEntry model) {
033                    JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034    
035                    jsonObj.put("uuid", model.getUuid());
036                    jsonObj.put("entryId", model.getEntryId());
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("classNameId", model.getClassNameId());
061                    jsonObj.put("classPK", model.getClassPK());
062                    jsonObj.put("title", model.getTitle());
063                    jsonObj.put("content", model.getContent());
064                    jsonObj.put("url", model.getUrl());
065                    jsonObj.put("type", model.getType());
066    
067                    Date displayDate = model.getDisplayDate();
068    
069                    String displayDateJSON = StringPool.BLANK;
070    
071                    if (displayDate != null) {
072                            displayDateJSON = String.valueOf(displayDate.getTime());
073                    }
074    
075                    jsonObj.put("displayDate", displayDateJSON);
076    
077                    Date expirationDate = model.getExpirationDate();
078    
079                    String expirationDateJSON = StringPool.BLANK;
080    
081                    if (expirationDate != null) {
082                            expirationDateJSON = String.valueOf(expirationDate.getTime());
083                    }
084    
085                    jsonObj.put("expirationDate", expirationDateJSON);
086                    jsonObj.put("priority", model.getPriority());
087                    jsonObj.put("alert", model.getAlert());
088    
089                    return jsonObj;
090            }
091    
092            public static JSONArray toJSONArray(
093                    com.liferay.portlet.announcements.model.AnnouncementsEntry[] models) {
094                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
095    
096                    for (AnnouncementsEntry model : models) {
097                            jsonArray.put(toJSONObject(model));
098                    }
099    
100                    return jsonArray;
101            }
102    
103            public static JSONArray toJSONArray(
104                    com.liferay.portlet.announcements.model.AnnouncementsEntry[][] models) {
105                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
106    
107                    for (AnnouncementsEntry[] model : models) {
108                            jsonArray.put(toJSONArray(model));
109                    }
110    
111                    return jsonArray;
112            }
113    
114            public static JSONArray toJSONArray(
115                    List<com.liferay.portlet.announcements.model.AnnouncementsEntry> models) {
116                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
117    
118                    for (AnnouncementsEntry model : models) {
119                            jsonArray.put(toJSONObject(model));
120                    }
121    
122                    return jsonArray;
123            }
124    }