1
22
23 package com.liferay.portal.service.http;
24
25 import com.liferay.portal.model.Address;
26
27 import com.liferay.util.JSONUtil;
28
29 import org.json.JSONArray;
30 import org.json.JSONObject;
31
32 import java.util.List;
33
34
52 public class AddressJSONSerializer {
53 public static JSONObject toJSONObject(Address model) {
54 JSONObject jsonObj = new JSONObject();
55 JSONUtil.put(jsonObj, "addressId", model.getAddressId());
56 JSONUtil.put(jsonObj, "companyId", model.getCompanyId());
57 JSONUtil.put(jsonObj, "userId", model.getUserId());
58 JSONUtil.put(jsonObj, "userName", model.getUserName());
59 JSONUtil.put(jsonObj, "createDate", model.getCreateDate());
60 JSONUtil.put(jsonObj, "modifiedDate", model.getModifiedDate());
61 JSONUtil.put(jsonObj, "classNameId", model.getClassNameId());
62 JSONUtil.put(jsonObj, "classPK", model.getClassPK());
63 JSONUtil.put(jsonObj, "street1", model.getStreet1());
64 JSONUtil.put(jsonObj, "street2", model.getStreet2());
65 JSONUtil.put(jsonObj, "street3", model.getStreet3());
66 JSONUtil.put(jsonObj, "city", model.getCity());
67 JSONUtil.put(jsonObj, "zip", model.getZip());
68 JSONUtil.put(jsonObj, "regionId", model.getRegionId());
69 JSONUtil.put(jsonObj, "countryId", model.getCountryId());
70 JSONUtil.put(jsonObj, "typeId", model.getTypeId());
71 JSONUtil.put(jsonObj, "mailing", model.getMailing());
72 JSONUtil.put(jsonObj, "primary", model.getPrimary());
73
74 return jsonObj;
75 }
76
77 public static JSONArray toJSONArray(List models) {
78 JSONArray jsonArray = new JSONArray();
79
80 for (int i = 0; i < models.size(); i++) {
81 Address model = (Address)models.get(i);
82 jsonArray.put(toJSONObject(model));
83 }
84
85 return jsonArray;
86 }
87 }