Package de.netseeker.ejoe.adapter.json

Source Code of de.netseeker.ejoe.adapter.json.XStreamJsonAdapter

/*********************************************************************
* XStreamJsonAdapter.java
* created on 24.10.2006 by netseeker
* $Id: XStreamJsonAdapter.java,v 1.2 2007/11/17 10:59:17 netseeker Exp $
* $Log: XStreamJsonAdapter.java,v $
* Revision 1.2  2007/11/17 10:59:17  netseeker
* *** empty log message ***
*
* Revision 1.1  2007/02/11 15:42:20  netseeker
* *** empty log message ***
*
* Revision 1.3  2006/11/10 00:35:13  netseeker
* switched to maven2
*
* Revision 1.2  2006/11/05 17:13:09  netseeker
* added source documentation
*
* Revision 1.1  2006/11/05 16:33:37  netseeker
* changed adapter connection handling
* added support for JSON with different JSON-adapters (XStream,JSON-lib,MyJSON)
*
*
* ====================================================================
*
*  Copyright 2005-2006 netseeker aka Michael Manske
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
* ====================================================================
*
* This file is part of the EJOE framework.
* For more information on the author, please see
* <http://www.manskes.de/>.
*
*********************************************************************/
package de.netseeker.ejoe.adapter.json;

import java.io.InputStream;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;

import de.netseeker.ejoe.adapter.UTF8StringAdapter;
import de.netseeker.ejoe.adapter.XStreamAdapter;

/**
* Write-only SerializeAdapter supporting JSON. Uses XSteam for writing out Objects to JSON but can't deserialize JSON
* requests to Objects. It does just return the JSON strings on read operations.
*
* @author netseeker
* @since 0.3.9.1
* @see <a href="http://xtream.codehaus.org">XStream</a>
*/
public class XStreamJsonAdapter extends XStreamAdapter
{
    /**
     *
     */
    private static final long serialVersionUID = 1L;

    private UTF8StringAdapter _strAdapter;

    /**
     * Creates a new instance of this adapter. The instance will use XStreams JsonHierarchicalStreamDriver for
     * serializing abitary objects to JSON.
     */
    public XStreamJsonAdapter()
    {
        super();
        _xstream = new XStream( new JsonHierarchicalStreamDriver() );
        _strAdapter = new UTF8StringAdapter();
    }

    /*
     * (non-Javadoc)
     *
     * @see de.netseeker.ejoe.adapter.XStreamAdapter#read(java.io.InputStream)
     */
    public Object read( InputStream in ) throws Exception
    {
        return _strAdapter.read( in );
    }

    /*
     * (non-Javadoc)
     *
     * @see de.netseeker.ejoe.adapter.BaseAdapter#getContentType()
     */
    public String getContentType()
    {
        return "application/json";
    }
}
TOP

Related Classes of de.netseeker.ejoe.adapter.json.XStreamJsonAdapter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.