1
22
23 package com.liferay.portlet.tags.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.tags.model.TagsEntry;
31
32 import java.util.Date;
33 import java.util.List;
34
35
51 public class TagsEntryJSONSerializer {
52 public static JSONObject toJSONObject(TagsEntry model) {
53 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
54
55 jsonObj.put("entryId", model.getEntryId());
56 jsonObj.put("companyId", model.getCompanyId());
57 jsonObj.put("userId", model.getUserId());
58 jsonObj.put("userName", model.getUserName());
59
60 Date createDate = model.getCreateDate();
61
62 String createDateJSON = StringPool.BLANK;
63
64 if (createDate != null) {
65 createDateJSON = String.valueOf(createDate.getTime());
66 }
67
68 jsonObj.put("createDate", createDateJSON);
69
70 Date modifiedDate = model.getModifiedDate();
71
72 String modifiedDateJSON = StringPool.BLANK;
73
74 if (modifiedDate != null) {
75 modifiedDateJSON = String.valueOf(modifiedDate.getTime());
76 }
77
78 jsonObj.put("modifiedDate", modifiedDateJSON);
79 jsonObj.put("name", model.getName());
80
81 return jsonObj;
82 }
83
84 public static JSONArray toJSONArray(
85 com.liferay.portlet.tags.model.TagsEntry[] models) {
86 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
87
88 for (TagsEntry model : models) {
89 jsonArray.put(toJSONObject(model));
90 }
91
92 return jsonArray;
93 }
94
95 public static JSONArray toJSONArray(
96 com.liferay.portlet.tags.model.TagsEntry[][] models) {
97 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
98
99 for (TagsEntry[] model : models) {
100 jsonArray.put(toJSONArray(model));
101 }
102
103 return jsonArray;
104 }
105
106 public static JSONArray toJSONArray(
107 List<com.liferay.portlet.tags.model.TagsEntry> models) {
108 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
109
110 for (TagsEntry model : models) {
111 jsonArray.put(toJSONObject(model));
112 }
113
114 return jsonArray;
115 }
116 }