1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.http;
16  
17  import com.liferay.portal.kernel.json.JSONArray;
18  import com.liferay.portal.kernel.json.JSONFactoryUtil;
19  import com.liferay.portal.kernel.json.JSONObject;
20  import com.liferay.portal.kernel.util.StringPool;
21  import com.liferay.portal.model.Contact;
22  
23  import java.util.Date;
24  import java.util.List;
25  
26  /**
27   * <a href="ContactJSONSerializer.java.html"><b><i>View Source</i></b></a>
28   *
29   * <p>
30   * ServiceBuilder generated this class. Modifications in this class will be
31   * overwritten the next time is generated.
32   * </p>
33   *
34   * <p>
35   * This class is used by {@link ContactServiceJSON} to translate objects.
36   * </p>
37   *
38   * @author    Brian Wing Shun Chan
39   * @see       com.liferay.portal.service.http.ContactServiceJSON
40   * @generated
41   */
42  public class ContactJSONSerializer {
43      public static JSONObject toJSONObject(Contact model) {
44          JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
45  
46          jsonObj.put("contactId", model.getContactId());
47          jsonObj.put("companyId", model.getCompanyId());
48          jsonObj.put("userId", model.getUserId());
49          jsonObj.put("userName", model.getUserName());
50  
51          Date createDate = model.getCreateDate();
52  
53          String createDateJSON = StringPool.BLANK;
54  
55          if (createDate != null) {
56              createDateJSON = String.valueOf(createDate.getTime());
57          }
58  
59          jsonObj.put("createDate", createDateJSON);
60  
61          Date modifiedDate = model.getModifiedDate();
62  
63          String modifiedDateJSON = StringPool.BLANK;
64  
65          if (modifiedDate != null) {
66              modifiedDateJSON = String.valueOf(modifiedDate.getTime());
67          }
68  
69          jsonObj.put("modifiedDate", modifiedDateJSON);
70          jsonObj.put("accountId", model.getAccountId());
71          jsonObj.put("parentContactId", model.getParentContactId());
72          jsonObj.put("firstName", model.getFirstName());
73          jsonObj.put("middleName", model.getMiddleName());
74          jsonObj.put("lastName", model.getLastName());
75          jsonObj.put("prefixId", model.getPrefixId());
76          jsonObj.put("suffixId", model.getSuffixId());
77          jsonObj.put("male", model.getMale());
78  
79          Date birthday = model.getBirthday();
80  
81          String birthdayJSON = StringPool.BLANK;
82  
83          if (birthday != null) {
84              birthdayJSON = String.valueOf(birthday.getTime());
85          }
86  
87          jsonObj.put("birthday", birthdayJSON);
88          jsonObj.put("smsSn", model.getSmsSn());
89          jsonObj.put("aimSn", model.getAimSn());
90          jsonObj.put("facebookSn", model.getFacebookSn());
91          jsonObj.put("icqSn", model.getIcqSn());
92          jsonObj.put("jabberSn", model.getJabberSn());
93          jsonObj.put("msnSn", model.getMsnSn());
94          jsonObj.put("mySpaceSn", model.getMySpaceSn());
95          jsonObj.put("skypeSn", model.getSkypeSn());
96          jsonObj.put("twitterSn", model.getTwitterSn());
97          jsonObj.put("ymSn", model.getYmSn());
98          jsonObj.put("employeeStatusId", model.getEmployeeStatusId());
99          jsonObj.put("employeeNumber", model.getEmployeeNumber());
100         jsonObj.put("jobTitle", model.getJobTitle());
101         jsonObj.put("jobClass", model.getJobClass());
102         jsonObj.put("hoursOfOperation", model.getHoursOfOperation());
103 
104         return jsonObj;
105     }
106 
107     public static JSONArray toJSONArray(
108         com.liferay.portal.model.Contact[] models) {
109         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
110 
111         for (Contact model : models) {
112             jsonArray.put(toJSONObject(model));
113         }
114 
115         return jsonArray;
116     }
117 
118     public static JSONArray toJSONArray(
119         com.liferay.portal.model.Contact[][] models) {
120         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
121 
122         for (Contact[] model : models) {
123             jsonArray.put(toJSONArray(model));
124         }
125 
126         return jsonArray;
127     }
128 
129     public static JSONArray toJSONArray(
130         List<com.liferay.portal.model.Contact> models) {
131         JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
132 
133         for (Contact model : models) {
134             jsonArray.put(toJSONObject(model));
135         }
136 
137         return jsonArray;
138     }
139 }