001
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.MBCategory;
023
024 import java.util.Date;
025 import java.util.List;
026
027
031 public class MBCategoryJSONSerializer {
032 public static JSONObject toJSONObject(MBCategory model) {
033 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034
035 jsonObj.put("uuid", model.getUuid());
036 jsonObj.put("categoryId", model.getCategoryId());
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("parentCategoryId", model.getParentCategoryId());
062 jsonObj.put("name", model.getName());
063 jsonObj.put("description", model.getDescription());
064 jsonObj.put("threadCount", model.getThreadCount());
065 jsonObj.put("messageCount", model.getMessageCount());
066
067 Date lastPostDate = model.getLastPostDate();
068
069 String lastPostDateJSON = StringPool.BLANK;
070
071 if (lastPostDate != null) {
072 lastPostDateJSON = String.valueOf(lastPostDate.getTime());
073 }
074
075 jsonObj.put("lastPostDate", lastPostDateJSON);
076
077 return jsonObj;
078 }
079
080 public static JSONArray toJSONArray(
081 com.liferay.portlet.messageboards.model.MBCategory[] models) {
082 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
083
084 for (MBCategory model : models) {
085 jsonArray.put(toJSONObject(model));
086 }
087
088 return jsonArray;
089 }
090
091 public static JSONArray toJSONArray(
092 com.liferay.portlet.messageboards.model.MBCategory[][] models) {
093 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
094
095 for (MBCategory[] model : models) {
096 jsonArray.put(toJSONArray(model));
097 }
098
099 return jsonArray;
100 }
101
102 public static JSONArray toJSONArray(
103 List<com.liferay.portlet.messageboards.model.MBCategory> models) {
104 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
105
106 for (MBCategory model : models) {
107 jsonArray.put(toJSONObject(model));
108 }
109
110 return jsonArray;
111 }
112 }