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