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