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