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.BookmarksFolder;
023
024 import java.util.Date;
025 import java.util.List;
026
027
031 public class BookmarksFolderJSONSerializer {
032 public static JSONObject toJSONObject(BookmarksFolder model) {
033 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034
035 jsonObj.put("uuid", model.getUuid());
036 jsonObj.put("folderId", model.getFolderId());
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("parentFolderId", model.getParentFolderId());
061 jsonObj.put("name", model.getName());
062 jsonObj.put("description", model.getDescription());
063
064 return jsonObj;
065 }
066
067 public static JSONArray toJSONArray(
068 com.liferay.portlet.bookmarks.model.BookmarksFolder[] models) {
069 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
070
071 for (BookmarksFolder model : models) {
072 jsonArray.put(toJSONObject(model));
073 }
074
075 return jsonArray;
076 }
077
078 public static JSONArray toJSONArray(
079 com.liferay.portlet.bookmarks.model.BookmarksFolder[][] models) {
080 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
081
082 for (BookmarksFolder[] model : models) {
083 jsonArray.put(toJSONArray(model));
084 }
085
086 return jsonArray;
087 }
088
089 public static JSONArray toJSONArray(
090 List<com.liferay.portlet.bookmarks.model.BookmarksFolder> models) {
091 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
092
093 for (BookmarksFolder model : models) {
094 jsonArray.put(toJSONObject(model));
095 }
096
097 return jsonArray;
098 }
099 }