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.MBBan;
023
024 import java.util.Date;
025 import java.util.List;
026
027
031 public class MBBanJSONSerializer {
032 public static JSONObject toJSONObject(MBBan model) {
033 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034
035 jsonObj.put("banId", model.getBanId());
036 jsonObj.put("groupId", model.getGroupId());
037 jsonObj.put("companyId", model.getCompanyId());
038 jsonObj.put("userId", model.getUserId());
039 jsonObj.put("userName", model.getUserName());
040
041 Date createDate = model.getCreateDate();
042
043 String createDateJSON = StringPool.BLANK;
044
045 if (createDate != null) {
046 createDateJSON = String.valueOf(createDate.getTime());
047 }
048
049 jsonObj.put("createDate", createDateJSON);
050
051 Date modifiedDate = model.getModifiedDate();
052
053 String modifiedDateJSON = StringPool.BLANK;
054
055 if (modifiedDate != null) {
056 modifiedDateJSON = String.valueOf(modifiedDate.getTime());
057 }
058
059 jsonObj.put("modifiedDate", modifiedDateJSON);
060 jsonObj.put("banUserId", model.getBanUserId());
061
062 return jsonObj;
063 }
064
065 public static JSONArray toJSONArray(
066 com.liferay.portlet.messageboards.model.MBBan[] models) {
067 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
068
069 for (MBBan model : models) {
070 jsonArray.put(toJSONObject(model));
071 }
072
073 return jsonArray;
074 }
075
076 public static JSONArray toJSONArray(
077 com.liferay.portlet.messageboards.model.MBBan[][] models) {
078 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
079
080 for (MBBan[] model : models) {
081 jsonArray.put(toJSONArray(model));
082 }
083
084 return jsonArray;
085 }
086
087 public static JSONArray toJSONArray(
088 List<com.liferay.portlet.messageboards.model.MBBan> models) {
089 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
090
091 for (MBBan model : models) {
092 jsonArray.put(toJSONObject(model));
093 }
094
095 return jsonArray;
096 }
097 }