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.MBBan;
23
24 import java.util.Date;
25 import java.util.List;
26
27
43 public class MBBanJSONSerializer {
44 public static JSONObject toJSONObject(MBBan model) {
45 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
46
47 jsonObj.put("banId", model.getBanId());
48 jsonObj.put("groupId", model.getGroupId());
49 jsonObj.put("companyId", model.getCompanyId());
50 jsonObj.put("userId", model.getUserId());
51 jsonObj.put("userName", model.getUserName());
52
53 Date createDate = model.getCreateDate();
54
55 String createDateJSON = StringPool.BLANK;
56
57 if (createDate != null) {
58 createDateJSON = String.valueOf(createDate.getTime());
59 }
60
61 jsonObj.put("createDate", createDateJSON);
62
63 Date modifiedDate = model.getModifiedDate();
64
65 String modifiedDateJSON = StringPool.BLANK;
66
67 if (modifiedDate != null) {
68 modifiedDateJSON = String.valueOf(modifiedDate.getTime());
69 }
70
71 jsonObj.put("modifiedDate", modifiedDateJSON);
72 jsonObj.put("banUserId", model.getBanUserId());
73
74 return jsonObj;
75 }
76
77 public static JSONArray toJSONArray(
78 com.liferay.portlet.messageboards.model.MBBan[] models) {
79 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
80
81 for (MBBan 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.MBBan[][] models) {
90 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
91
92 for (MBBan[] 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.MBBan> models) {
101 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
102
103 for (MBBan model : models) {
104 jsonArray.put(toJSONObject(model));
105 }
106
107 return jsonArray;
108 }
109 }