1
22
23 package com.liferay.portlet.messageboards.service.http;
24
25 import com.liferay.portal.kernel.json.JSONArray;
26 import com.liferay.portal.kernel.json.JSONFactoryUtil;
27 import com.liferay.portal.kernel.json.JSONObject;
28 import com.liferay.portal.kernel.util.StringPool;
29
30 import com.liferay.portlet.messageboards.model.MBThread;
31
32 import java.util.Date;
33 import java.util.List;
34
35
51 public class MBThreadJSONSerializer {
52 public static JSONObject toJSONObject(MBThread model) {
53 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
54
55 jsonObj.put("threadId", model.getThreadId());
56 jsonObj.put("groupId", model.getGroupId());
57 jsonObj.put("categoryId", model.getCategoryId());
58 jsonObj.put("rootMessageId", model.getRootMessageId());
59 jsonObj.put("messageCount", model.getMessageCount());
60 jsonObj.put("viewCount", model.getViewCount());
61 jsonObj.put("lastPostByUserId", model.getLastPostByUserId());
62
63 Date lastPostDate = model.getLastPostDate();
64
65 String lastPostDateJSON = StringPool.BLANK;
66
67 if (lastPostDate != null) {
68 lastPostDateJSON = String.valueOf(lastPostDate.getTime());
69 }
70
71 jsonObj.put("lastPostDate", lastPostDateJSON);
72 jsonObj.put("priority", model.getPriority());
73
74 return jsonObj;
75 }
76
77 public static JSONArray toJSONArray(
78 com.liferay.portlet.messageboards.model.MBThread[] models) {
79 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
80
81 for (MBThread model : models) {
82 jsonArray.put(toJSONObject(model));
83 }
84
85 return jsonArray;
86 }
87
88 public static JSONArray toJSONArray(
89 com.liferay.portlet.messageboards.model.MBThread[][] models) {
90 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
91
92 for (MBThread[] model : models) {
93 jsonArray.put(toJSONArray(model));
94 }
95
96 return jsonArray;
97 }
98
99 public static JSONArray toJSONArray(
100 List<com.liferay.portlet.messageboards.model.MBThread> models) {
101 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
102
103 for (MBThread model : models) {
104 jsonArray.put(toJSONObject(model));
105 }
106
107 return jsonArray;
108 }
109 }