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