001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.json;
016    
017    /**
018     * @author Brian Wing Shun Chan
019     */
020    public class JSONFactoryUtil {
021    
022            public static JSONArray createJSONArray() {
023                    return getJSONFactory().createJSONArray();
024            }
025    
026            public static JSONArray createJSONArray(String json) throws JSONException {
027                    return getJSONFactory().createJSONArray(json);
028            }
029    
030            public static <T> JSONDeserializer<T> createJSONDeserializer() {
031                    return getJSONFactory().createJSONDeserializer();
032            }
033    
034            public static JSONObject createJSONObject() {
035                    return getJSONFactory().createJSONObject();
036            }
037    
038            public static JSONObject createJSONObject(String json)
039                    throws JSONException {
040    
041                    return getJSONFactory().createJSONObject(json);
042            }
043    
044            public static JSONSerializer createJSONSerializer() {
045                    return getJSONFactory().createJSONSerializer();
046            }
047    
048            public static Object deserialize(JSONObject jsonObj) {
049                    return getJSONFactory().deserialize(jsonObj);
050            }
051    
052            public static Object deserialize(String json) {
053                    return getJSONFactory().deserialize(json);
054            }
055    
056            public static JSONFactory getJSONFactory() {
057                    return _jsonFactory;
058            }
059    
060            public static String getNullJSON() {
061                    return getJSONFactory().getNullJSON();
062            }
063    
064            public static Object looseDeserialize(String json) {
065                    return getJSONFactory().looseDeserialize(json);
066            }
067    
068            public static <T> T looseDeserialize(String json, Class<T> clazz) {
069                    return getJSONFactory().looseDeserialize(json, clazz);
070            }
071    
072            public static String looseSerialize(Object object) {
073                    return getJSONFactory().looseSerialize(object);
074            }
075    
076            public static String looseSerialize(
077                    Object object, JSONTransformer jsonTransformer, Class<?> clazz) {
078    
079                    return getJSONFactory().looseSerialize(object, jsonTransformer, clazz);
080            }
081    
082            public static String looseSerialize(Object object, String... includes) {
083                    return getJSONFactory().looseSerialize(object, includes);
084            }
085    
086            public static String looseSerializeDeep(Object object) {
087                    return getJSONFactory().looseSerializeDeep(object);
088            }
089    
090            public static String serialize(Object object) {
091                    return getJSONFactory().serialize(object);
092            }
093    
094            public static String serializeException(Exception exception) {
095                    return getJSONFactory().serializeException(exception);
096            }
097    
098            public void setJSONFactory(JSONFactory jsonFactory) {
099                    _jsonFactory = jsonFactory;
100            }
101    
102            private static JSONFactory _jsonFactory;
103    
104    }