001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.http;
016    
017    import com.liferay.portal.kernel.json.JSONArray;
018    import com.liferay.portal.kernel.json.JSONFactoryUtil;
019    import com.liferay.portal.kernel.json.JSONObject;
020    import com.liferay.portal.kernel.util.StringPool;
021    import com.liferay.portal.model.Contact;
022    
023    import java.util.Date;
024    import java.util.List;
025    
026    /**
027     * @author    Brian Wing Shun Chan
028     * @generated
029     */
030    public class ContactJSONSerializer {
031            public static JSONObject toJSONObject(Contact model) {
032                    JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
033    
034                    jsonObj.put("contactId", model.getContactId());
035                    jsonObj.put("companyId", model.getCompanyId());
036                    jsonObj.put("userId", model.getUserId());
037                    jsonObj.put("userName", model.getUserName());
038    
039                    Date createDate = model.getCreateDate();
040    
041                    String createDateJSON = StringPool.BLANK;
042    
043                    if (createDate != null) {
044                            createDateJSON = String.valueOf(createDate.getTime());
045                    }
046    
047                    jsonObj.put("createDate", createDateJSON);
048    
049                    Date modifiedDate = model.getModifiedDate();
050    
051                    String modifiedDateJSON = StringPool.BLANK;
052    
053                    if (modifiedDate != null) {
054                            modifiedDateJSON = String.valueOf(modifiedDate.getTime());
055                    }
056    
057                    jsonObj.put("modifiedDate", modifiedDateJSON);
058                    jsonObj.put("accountId", model.getAccountId());
059                    jsonObj.put("parentContactId", model.getParentContactId());
060                    jsonObj.put("firstName", model.getFirstName());
061                    jsonObj.put("middleName", model.getMiddleName());
062                    jsonObj.put("lastName", model.getLastName());
063                    jsonObj.put("prefixId", model.getPrefixId());
064                    jsonObj.put("suffixId", model.getSuffixId());
065                    jsonObj.put("male", model.getMale());
066    
067                    Date birthday = model.getBirthday();
068    
069                    String birthdayJSON = StringPool.BLANK;
070    
071                    if (birthday != null) {
072                            birthdayJSON = String.valueOf(birthday.getTime());
073                    }
074    
075                    jsonObj.put("birthday", birthdayJSON);
076                    jsonObj.put("smsSn", model.getSmsSn());
077                    jsonObj.put("aimSn", model.getAimSn());
078                    jsonObj.put("facebookSn", model.getFacebookSn());
079                    jsonObj.put("icqSn", model.getIcqSn());
080                    jsonObj.put("jabberSn", model.getJabberSn());
081                    jsonObj.put("msnSn", model.getMsnSn());
082                    jsonObj.put("mySpaceSn", model.getMySpaceSn());
083                    jsonObj.put("skypeSn", model.getSkypeSn());
084                    jsonObj.put("twitterSn", model.getTwitterSn());
085                    jsonObj.put("ymSn", model.getYmSn());
086                    jsonObj.put("employeeStatusId", model.getEmployeeStatusId());
087                    jsonObj.put("employeeNumber", model.getEmployeeNumber());
088                    jsonObj.put("jobTitle", model.getJobTitle());
089                    jsonObj.put("jobClass", model.getJobClass());
090                    jsonObj.put("hoursOfOperation", model.getHoursOfOperation());
091    
092                    return jsonObj;
093            }
094    
095            public static JSONArray toJSONArray(
096                    com.liferay.portal.model.Contact[] models) {
097                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
098    
099                    for (Contact model : models) {
100                            jsonArray.put(toJSONObject(model));
101                    }
102    
103                    return jsonArray;
104            }
105    
106            public static JSONArray toJSONArray(
107                    com.liferay.portal.model.Contact[][] models) {
108                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
109    
110                    for (Contact[] model : models) {
111                            jsonArray.put(toJSONArray(model));
112                    }
113    
114                    return jsonArray;
115            }
116    
117            public static JSONArray toJSONArray(
118                    List<com.liferay.portal.model.Contact> models) {
119                    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
120    
121                    for (Contact model : models) {
122                            jsonArray.put(toJSONObject(model));
123                    }
124    
125                    return jsonArray;
126            }
127    }