001
014
015 package com.liferay.portlet.imagegallery.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.imagegallery.model.IGImage;
023
024 import java.util.Date;
025 import java.util.List;
026
027
031 public class IGImageJSONSerializer {
032 public static JSONObject toJSONObject(IGImage model) {
033 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
034
035 jsonObj.put("uuid", model.getUuid());
036 jsonObj.put("imageId", model.getImageId());
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("description", model.getDescription());
063 jsonObj.put("smallImageId", model.getSmallImageId());
064 jsonObj.put("largeImageId", model.getLargeImageId());
065 jsonObj.put("custom1ImageId", model.getCustom1ImageId());
066 jsonObj.put("custom2ImageId", model.getCustom2ImageId());
067
068 return jsonObj;
069 }
070
071 public static JSONArray toJSONArray(
072 com.liferay.portlet.imagegallery.model.IGImage[] models) {
073 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
074
075 for (IGImage model : models) {
076 jsonArray.put(toJSONObject(model));
077 }
078
079 return jsonArray;
080 }
081
082 public static JSONArray toJSONArray(
083 com.liferay.portlet.imagegallery.model.IGImage[][] models) {
084 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
085
086 for (IGImage[] model : models) {
087 jsonArray.put(toJSONArray(model));
088 }
089
090 return jsonArray;
091 }
092
093 public static JSONArray toJSONArray(
094 List<com.liferay.portlet.imagegallery.model.IGImage> models) {
095 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
096
097 for (IGImage model : models) {
098 jsonArray.put(toJSONObject(model));
099 }
100
101 return jsonArray;
102 }
103 }