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.messageboards.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.messageboards.model.MBMessage;
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 MBMessageJSONSerializer {
032            public static JSONObject toJSONObject(MBMessage model) {
033                    JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034    
035                    jsonObj.put("uuid", model.getUuid());
036                    jsonObj.put("messageId", model.getMessageId());
037                    jsonObj.put("groupId", model.getGroupId());
038                    jsonObj.put("companyId", model.getCompanyId());
039                    jsonObj.put("userId", model.getUserId());
040                    jsonObj.put("userName", model.getUserName());
041    
042                    Date createDate = model.getCreateDate();
043    
044                    String createDateJSON = StringPool.BLANK;
045    
046                    if (createDate != null) {
047                            createDateJSON = String.valueOf(createDate.getTime());
048                    }
049    
050                    jsonObj.put("createDate", createDateJSON);
051    
052                    Date modifiedDate = model.getModifiedDate();
053    
054                    String modifiedDateJSON = StringPool.BLANK;
055    
056                    if (modifiedDate != null) {
057                            modifiedDateJSON = String.valueOf(modifiedDate.getTime());
058                    }
059    
060                    jsonObj.put("modifiedDate", modifiedDateJSON);
061                    jsonObj.put("classNameId", model.getClassNameId());
062                    jsonObj.put("classPK", model.getClassPK());
063                    jsonObj.put("categoryId", model.getCategoryId());
064                    jsonObj.put("threadId", model.getThreadId());
065                    jsonObj.put("rootMessageId", model.getRootMessageId());
066                    jsonObj.put("parentMessageId", model.getParentMessageId());
067                    jsonObj.put("subject", model.getSubject());
068                    jsonObj.put("body", model.getBody());
069                    jsonObj.put("attachments", model.getAttachments());
070                    jsonObj.put("anonymous", model.getAnonymous());
071                    jsonObj.put("priority", model.getPriority());
072                    jsonObj.put("allowPingbacks", model.getAllowPingbacks());
073                    jsonObj.put("status", model.getStatus());
074                    jsonObj.put("statusByUserId", model.getStatusByUserId());
075                    jsonObj.put("statusByUserName", model.getStatusByUserName());
076    
077                    Date statusDate = model.getStatusDate();
078    
079                    String statusDateJSON = StringPool.BLANK;
080    
081                    if (statusDate != null) {
082                            statusDateJSON = String.valueOf(statusDate.getTime());
083                    }
084    
085                    jsonObj.put("statusDate", statusDateJSON);
086    
087                    return jsonObj;
088            }
089    
090            public static JSONArray toJSONArray(
091                    com.liferay.portlet.messageboards.model.MBMessage[] models) {
092                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
093    
094                    for (MBMessage model : models) {
095                            jsonArray.put(toJSONObject(model));
096                    }
097    
098                    return jsonArray;
099            }
100    
101            public static JSONArray toJSONArray(
102                    com.liferay.portlet.messageboards.model.MBMessage[][] models) {
103                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
104    
105                    for (MBMessage[] model : models) {
106                            jsonArray.put(toJSONArray(model));
107                    }
108    
109                    return jsonArray;
110            }
111    
112            public static JSONArray toJSONArray(
113                    List<com.liferay.portlet.messageboards.model.MBMessage> models) {
114                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
115    
116                    for (MBMessage model : models) {
117                            jsonArray.put(toJSONObject(model));
118                    }
119    
120                    return jsonArray;
121            }
122    }