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 org.jabsorb.JSONSerializer;
018    import org.jabsorb.serializer.ObjectMatch;
019    import org.jabsorb.serializer.SerializerState;
020    import org.jabsorb.serializer.UnmarshallException;
021    
022    /**
023     * @author Tomas Polesovsky
024     */
025    public class LiferayJSONSerializer extends JSONSerializer {
026    
027            @Override
028            public ObjectMatch tryUnmarshall(
029                            SerializerState serializerState,
030                            @SuppressWarnings("rawtypes") Class clazz, Object json)
031                    throws UnmarshallException {
032    
033                    if (!(serializerState instanceof LiferaySerializerState)) {
034                            serializerState = new LiferaySerializerState();
035                    }
036    
037                    return super.tryUnmarshall(serializerState, clazz, json);
038            }
039    
040            @Override
041            public Object unmarshall(
042                            SerializerState serializerState,
043                            @SuppressWarnings("rawtypes") Class clazz, Object json)
044                    throws UnmarshallException {
045    
046                    if (!(serializerState instanceof LiferaySerializerState)) {
047                            serializerState = new LiferaySerializerState();
048                    }
049    
050                    return super.unmarshall(serializerState, clazz, json);
051            }
052    
053    }