001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.http;
022:
023: import com.liferay.portal.model.Contact;
024:
025: import com.liferay.util.JSONUtil;
026:
027: import org.json.JSONArray;
028: import org.json.JSONObject;
029:
030: import java.util.List;
031:
032: /**
033: * <a href="ContactJSONSerializer.java.html"><b><i>View Source</i></b></a>
034: *
035: * <p>
036: * ServiceBuilder generated this class. Modifications in this class will be
037: * overwritten the next time is generated.
038: * </p>
039: *
040: * <p>
041: * This class is used by
042: * <code>com.liferay.portal.service.http.ContactServiceJSON</code>
043: * to translate objects.
044: * </p>
045: *
046: * @author Brian Wing Shun Chan
047: *
048: * @see com.liferay.portal.service.http.ContactServiceJSON
049: *
050: */
051: public class ContactJSONSerializer {
052: public static JSONObject toJSONObject(Contact model) {
053: JSONObject jsonObj = new JSONObject();
054:
055: JSONUtil.put(jsonObj, "contactId", model.getContactId());
056: JSONUtil.put(jsonObj, "companyId", model.getCompanyId());
057: JSONUtil.put(jsonObj, "userId", model.getUserId());
058: JSONUtil.put(jsonObj, "userName", model.getUserName());
059: JSONUtil.put(jsonObj, "createDate", model.getCreateDate());
060: JSONUtil.put(jsonObj, "modifiedDate", model.getModifiedDate());
061: JSONUtil.put(jsonObj, "accountId", model.getAccountId());
062: JSONUtil.put(jsonObj, "parentContactId", model
063: .getParentContactId());
064: JSONUtil.put(jsonObj, "firstName", model.getFirstName());
065: JSONUtil.put(jsonObj, "middleName", model.getMiddleName());
066: JSONUtil.put(jsonObj, "lastName", model.getLastName());
067: JSONUtil.put(jsonObj, "prefixId", model.getPrefixId());
068: JSONUtil.put(jsonObj, "suffixId", model.getSuffixId());
069: JSONUtil.put(jsonObj, "male", model.getMale());
070: JSONUtil.put(jsonObj, "birthday", model.getBirthday());
071: JSONUtil.put(jsonObj, "smsSn", model.getSmsSn());
072: JSONUtil.put(jsonObj, "aimSn", model.getAimSn());
073: JSONUtil.put(jsonObj, "icqSn", model.getIcqSn());
074: JSONUtil.put(jsonObj, "jabberSn", model.getJabberSn());
075: JSONUtil.put(jsonObj, "msnSn", model.getMsnSn());
076: JSONUtil.put(jsonObj, "skypeSn", model.getSkypeSn());
077: JSONUtil.put(jsonObj, "ymSn", model.getYmSn());
078: JSONUtil.put(jsonObj, "employeeStatusId", model
079: .getEmployeeStatusId());
080: JSONUtil.put(jsonObj, "employeeNumber", model
081: .getEmployeeNumber());
082: JSONUtil.put(jsonObj, "jobTitle", model.getJobTitle());
083: JSONUtil.put(jsonObj, "jobClass", model.getJobClass());
084: JSONUtil.put(jsonObj, "hoursOfOperation", model
085: .getHoursOfOperation());
086:
087: return jsonObj;
088: }
089:
090: public static JSONArray toJSONArray(List models) {
091: JSONArray jsonArray = new JSONArray();
092:
093: for (int i = 0; i < models.size(); i++) {
094: Contact model = (Contact) models.get(i);
095:
096: jsonArray.put(toJSONObject(model));
097: }
098:
099: return jsonArray;
100: }
101: }
|