001    /**
002     * Copyright (c) 2000-2012 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.kernel.json;
016    
017    import java.util.List;
018    
019    /**
020     * @author Brian Wing Shun Chan
021     */
022    public class JSONFactoryUtil {
023    
024            public static String convertJSONMLArrayToXML(String jsonml) {
025                    return getJSONFactory().convertJSONMLArrayToXML(jsonml);
026            }
027    
028            public static String convertJSONMLObjectToXML(String jsonml) {
029                    return getJSONFactory().convertJSONMLObjectToXML(jsonml);
030            }
031    
032            public static String convertXMLtoJSONMLArray(String xml) {
033                    return getJSONFactory().convertXMLtoJSONMLArray(xml);
034            }
035    
036            public static String convertXMLtoJSONMLObject(String xml) {
037                    return getJSONFactory().convertXMLtoJSONMLObject(xml);
038            }
039    
040            public static JSONTransformer createJavaScriptNormalizerJSONTransformer(
041                    List<String> javaScriptAttributes) {
042    
043                    return getJSONFactory().createJavaScriptNormalizerJSONTransformer(
044                            javaScriptAttributes);
045            }
046    
047            public static JSONArray createJSONArray() {
048                    return getJSONFactory().createJSONArray();
049            }
050    
051            public static JSONArray createJSONArray(String json) throws JSONException {
052                    return getJSONFactory().createJSONArray(json);
053            }
054    
055            public static <T> JSONDeserializer<T> createJSONDeserializer() {
056                    return getJSONFactory().createJSONDeserializer();
057            }
058    
059            public static JSONObject createJSONObject() {
060                    return getJSONFactory().createJSONObject();
061            }
062    
063            public static JSONObject createJSONObject(String json)
064                    throws JSONException {
065    
066                    return getJSONFactory().createJSONObject(json);
067            }
068    
069            public static JSONSerializer createJSONSerializer() {
070                    return getJSONFactory().createJSONSerializer();
071            }
072    
073            public static Object deserialize(JSONObject jsonObj) {
074                    return getJSONFactory().deserialize(jsonObj);
075            }
076    
077            public static Object deserialize(String json) {
078                    return getJSONFactory().deserialize(json);
079            }
080    
081            public static JSONFactory getJSONFactory() {
082                    return _jsonFactory;
083            }
084    
085            public static String getNullJSON() {
086                    return getJSONFactory().getNullJSON();
087            }
088    
089            public static Object looseDeserialize(String json) {
090                    return getJSONFactory().looseDeserialize(json);
091            }
092    
093            public static <T> T looseDeserialize(String json, Class<T> clazz) {
094                    return getJSONFactory().looseDeserialize(json, clazz);
095            }
096    
097            public static String looseSerialize(Object object) {
098                    return getJSONFactory().looseSerialize(object);
099            }
100    
101            public static String looseSerialize(
102                    Object object, JSONTransformer jsonTransformer, Class<?> clazz) {
103    
104                    return getJSONFactory().looseSerialize(object, jsonTransformer, clazz);
105            }
106    
107            public static String looseSerialize(Object object, String... includes) {
108                    return getJSONFactory().looseSerialize(object, includes);
109            }
110    
111            public static String looseSerializeDeep(Object object) {
112                    return getJSONFactory().looseSerializeDeep(object);
113            }
114    
115            public static String looseSerializeDeep(
116                    Object object, JSONTransformer jsonTransformer, Class<?> clazz) {
117    
118                    return getJSONFactory().looseSerializeDeep(
119                            object, jsonTransformer, clazz);
120            }
121    
122            public static String serialize(Object object) {
123                    return getJSONFactory().serialize(object);
124            }
125    
126            public static String serializeException(Exception exception) {
127                    return getJSONFactory().serializeException(exception);
128            }
129    
130            public void setJSONFactory(JSONFactory jsonFactory) {
131                    _jsonFactory = jsonFactory;
132            }
133    
134            private static JSONFactory _jsonFactory;
135    
136    }