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.Address;
30
31 import java.util.Date;
32 import java.util.List;
33
34
53 public class AddressJSONSerializer {
54 public static JSONObject toJSONObject(Address model) {
55 JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
56
57 jsonObj.put("addressId", model.getAddressId());
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("street1", model.getStreet1());
84 jsonObj.put("street2", model.getStreet2());
85 jsonObj.put("street3", model.getStreet3());
86 jsonObj.put("city", model.getCity());
87 jsonObj.put("zip", model.getZip());
88 jsonObj.put("regionId", model.getRegionId());
89 jsonObj.put("countryId", model.getCountryId());
90 jsonObj.put("typeId", model.getTypeId());
91 jsonObj.put("mailing", model.getMailing());
92 jsonObj.put("primary", model.getPrimary());
93
94 return jsonObj;
95 }
96
97 public static JSONArray toJSONArray(
98 List<com.liferay.portal.model.Address> models) {
99 JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
100
101 for (Address model : models) {
102 jsonArray.put(toJSONObject(model));
103 }
104
105 return jsonArray;
106 }
107 }