001
014
015 package com.liferay.portlet.bookmarks.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.bookmarks.model.BookmarksEntry;
023
024 import java.util.Date;
025 import java.util.List;
026
027
031 public class BookmarksEntryJSONSerializer {
032 public static JSONObject toJSONObject(BookmarksEntry model) {
033 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034
035 jsonObj.put("uuid", model.getUuid());
036 jsonObj.put("entryId", model.getEntryId());
037 jsonObj.put("groupId", model.getGroupId());
038 jsonObj.put("companyId", model.getCompanyId());
039 jsonObj.put("userId", model.getUserId());
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("folderId", model.getFolderId());
061 jsonObj.put("name", model.getName());
062 jsonObj.put("url", model.getUrl());
063 jsonObj.put("comments", model.getComments());
064 jsonObj.put("visits", model.getVisits());
065 jsonObj.put("priority", model.getPriority());
066
067 return jsonObj;
068 }
069
070 public static JSONArray toJSONArray(
071 com.liferay.portlet.bookmarks.model.BookmarksEntry[] models) {
072 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
073
074 for (BookmarksEntry model : models) {
075 jsonArray.put(toJSONObject(model));
076 }
077
078 return jsonArray;
079 }
080
081 public static JSONArray toJSONArray(
082 com.liferay.portlet.bookmarks.model.BookmarksEntry[][] models) {
083 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
084
085 for (BookmarksEntry[] model : models) {
086 jsonArray.put(toJSONArray(model));
087 }
088
089 return jsonArray;
090 }
091
092 public static JSONArray toJSONArray(
093 List<com.liferay.portlet.bookmarks.model.BookmarksEntry> models) {
094 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
095
096 for (BookmarksEntry model : models) {
097 jsonArray.put(toJSONObject(model));
098 }
099
100 return jsonArray;
101 }
102 }