1
22
23 package com.liferay.portal.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 import com.liferay.portal.model.Phone;
30
31 import java.util.Date;
32 import java.util.List;
33
34
53 public class PhoneJSONSerializer {
54 public static JSONObject toJSONObject(Phone model) {
55 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
56
57 jsonObj.put("phoneId", model.getPhoneId());
58 jsonObj.put("companyId", model.getCompanyId());
59 jsonObj.put("userId", model.getUserId());
60 jsonObj.put("userName", model.getUserName());
61
62 Date createDate = model.getCreateDate();
63
64 String createDateJSON = StringPool.BLANK;
65
66 if (createDate != null) {
67 createDateJSON = String.valueOf(createDate.getTime());
68 }
69
70 jsonObj.put("createDate", createDateJSON);
71
72 Date modifiedDate = model.getModifiedDate();
73
74 String modifiedDateJSON = StringPool.BLANK;
75
76 if (modifiedDate != null) {
77 modifiedDateJSON = String.valueOf(modifiedDate.getTime());
78 }
79
80 jsonObj.put("modifiedDate", modifiedDateJSON);
81 jsonObj.put("classNameId", model.getClassNameId());
82 jsonObj.put("classPK", model.getClassPK());
83 jsonObj.put("number", model.getNumber());
84 jsonObj.put("extension", model.getExtension());
85 jsonObj.put("typeId", model.getTypeId());
86 jsonObj.put("primary", model.getPrimary());
87
88 return jsonObj;
89 }
90
91 public static JSONArray toJSONArray(
92 List<com.liferay.portal.model.Phone> models) {
93 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
94
95 for (Phone model : models) {
96 jsonArray.put(toJSONObject(model));
97 }
98
99 return jsonArray;
100 }
101 }