View Javadoc

1   /**********************************************************************
2    * XStreamJsonAdapter.java
3    * created on 24.10.2006 by netseeker
4    * $Id: XStreamJsonAdapter.java,v 1.2 2007/11/17 10:59:17 netseeker Exp $
5    * $Log: XStreamJsonAdapter.java,v $
6    * Revision 1.2  2007/11/17 10:59:17  netseeker
7    * *** empty log message ***
8    *
9    * Revision 1.1  2007/02/11 15:42:20  netseeker
10   * *** empty log message ***
11   *
12   * Revision 1.3  2006/11/10 00:35:13  netseeker
13   * switched to maven2
14   *
15   * Revision 1.2  2006/11/05 17:13:09  netseeker
16   * added source documentation
17   *
18   * Revision 1.1  2006/11/05 16:33:37  netseeker
19   * changed adapter connection handling
20   * added support for JSON with different JSON-adapters (XStream,JSON-lib,MyJSON)
21   *
22   *
23   * ====================================================================
24   *
25   *  Copyright 2005-2006 netseeker aka Michael Manske
26   *
27   *  Licensed under the Apache License, Version 2.0 (the "License");
28   *  you may not use this file except in compliance with the License.
29   *  You may obtain a copy of the License at
30   *
31   *      http://www.apache.org/licenses/LICENSE-2.0
32   *
33   *  Unless required by applicable law or agreed to in writing, software
34   *  distributed under the License is distributed on an "AS IS" BASIS,
35   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36   *  See the License for the specific language governing permissions and
37   *  limitations under the License.
38   * ====================================================================
39   *
40   * This file is part of the EJOE framework.
41   * For more information on the author, please see
42   * <http://www.manskes.de/>.
43   *
44   *********************************************************************/
45  package de.netseeker.ejoe.adapter.json;
46  
47  import java.io.InputStream;
48  
49  import com.thoughtworks.xstream.XStream;
50  import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
51  
52  import de.netseeker.ejoe.adapter.UTF8StringAdapter;
53  import de.netseeker.ejoe.adapter.XStreamAdapter;
54  
55  /***
56   * Write-only SerializeAdapter supporting JSON. Uses XSteam for writing out Objects to JSON but can't deserialize JSON
57   * requests to Objects. It does just return the JSON strings on read operations.
58   * 
59   * @author netseeker
60   * @since 0.3.9.1
61   * @see <a href="http://xtream.codehaus.org">XStream</a>
62   */
63  public class XStreamJsonAdapter extends XStreamAdapter
64  {
65      /***
66       * 
67       */
68      private static final long serialVersionUID = 1L;
69  
70      private UTF8StringAdapter _strAdapter;
71  
72      /***
73       * Creates a new instance of this adapter. The instance will use XStreams JsonHierarchicalStreamDriver for
74       * serializing abitary objects to JSON.
75       */
76      public XStreamJsonAdapter()
77      {
78          super();
79          _xstream = new XStream( new JsonHierarchicalStreamDriver() );
80          _strAdapter = new UTF8StringAdapter();
81      }
82  
83      /*
84       * (non-Javadoc)
85       * 
86       * @see de.netseeker.ejoe.adapter.XStreamAdapter#read(java.io.InputStream)
87       */
88      public Object read( InputStream in ) throws Exception
89      {
90          return _strAdapter.read( in );
91      }
92  
93      /*
94       * (non-Javadoc)
95       * 
96       * @see de.netseeker.ejoe.adapter.BaseAdapter#getContentType()
97       */
98      public String getContentType()
99      {
100         return "application/json";
101     }
102 }