/*********************************************************************
* JsonToolsAdapter.java
* created on 28.02.2007 by netseeker
* $Id: JsonToolsAdapter.java,v 1.1 2007/02/28 18:22:33 netseeker Exp $
* $Log: JsonToolsAdapter.java,v $
* Revision 1.1 2007/02/28 18:22:33 netseeker
* *** empty log message ***
*
*
* ====================================================================
*
* 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 java.io.OutputStream;
import com.sdicons.json.model.JSONObject;
import com.sdicons.json.parser.JSONParser;
import com.sdicons.json.serializer.marshall.JSONMarshall;
import com.sdicons.json.serializer.marshall.Marshall;
import de.netseeker.ejoe.adapter.UTF8StringAdapter;
/**
* A true multimode SerializeAdapter supporting JSON via Json Tools.
* @author netseeker
* @since 0.3.9.2
* @see <a href="http://jsontools.berlios.de">Json Tools</a>
*/
public class JsonToolsAdapter extends UTF8StringAdapter
{
/**
*
*/
private static final long serialVersionUID = 1L;
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.adapter.SerializeAdapter#read(java.io.InputStream)
*/
public Object read( InputStream in ) throws Exception
{
JSONParser parser = new JSONParser( in );
JSONObject jObj = (JSONObject) parser.nextValue();
Marshall marshaller = new JSONMarshall();
return marshaller.unmarshall( jObj ).getReference();
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.adapter.SerializeAdapter#write(java.lang.Object, java.io.OutputStream)
*/
public void write( Object obj, OutputStream out ) throws Exception
{
Marshall marshaller = new JSONMarshall();
JSONObject jObj = marshaller.marshall( obj );
super.write( jObj.render( false ), out );
}
/*
* (non-Javadoc)
*
* @see de.netseeker.ejoe.adapter.BaseAdapter#getContentType()
*/
public String getContentType()
{
return "application/json";
}
}