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.json.jabsorb.serializer;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    
020    import org.jabsorb.serializer.ProcessedObject;
021    import org.jabsorb.serializer.SerializerState;
022    
023    import org.json.JSONException;
024    import org.json.JSONObject;
025    
026    /**
027     * @author Tomas Polesovsky
028     */
029    public class LiferaySerializerState extends SerializerState {
030    
031            @Override
032            public ProcessedObject store(Object object) {
033                    if (!(object instanceof JSONObject)) {
034                            return super.store(object);
035                    }
036    
037                    JSONObject jsonObject = (JSONObject)object;
038    
039                    if (jsonObject.has("javaClass")) {
040                            try {
041                                    String javaClass = jsonObject.getString("javaClass");
042    
043                                    if (javaClass.contains("com.liferay") &&
044                                            javaClass.contains("Util")) {
045    
046                                            throw new RuntimeException(
047                                                    "Not instantiating " + javaClass);
048                                    }
049                            }
050                            catch (JSONException jsone) {
051                                    _log.error("Unable to parse object", jsone);
052                            }
053                    }
054    
055                    return super.store(object);
056            }
057    
058            private static Log _log = LogFactoryUtil.getLog(
059                    LiferaySerializerState.class);
060    
061    }