commit | author | age
|
ca8e1e
|
1 |
/* |
U |
2 |
Transit - Remote procedure calls made simple |
|
3 |
Copyright (c) 2012 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as published by |
|
7 |
the Free Software Foundation, either version 3 of the License, or |
|
8 |
(at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
|
19 |
package de.uhilger.transit; |
|
20 |
|
|
21 |
import java.io.Writer; |
|
22 |
import java.util.List; |
|
23 |
|
|
24 |
import com.thoughtworks.xstream.XStream; |
|
25 |
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver; |
|
26 |
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver; |
|
27 |
import com.thoughtworks.xstream.io.json.JsonWriter; |
|
28 |
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; |
|
29 |
|
|
30 |
/** |
|
31 |
* Java-Objekte in die JavaScript Object Notation (JSON) |
|
32 |
* verwandeln und umgekehrt |
|
33 |
* |
|
34 |
* <p>Diese Klasse benoetigt die Java-Klassenbibliotheken |
|
35 |
* <a href="http://xstream.codehaus.org/">XStream</a> |
|
36 |
* und <a href="http://jettison.codehaus.org/">Jettison</a> |
|
37 |
* im Classpath.</p> |
|
38 |
* |
|
39 |
* @author Copyright (c) Ulrich Hilger, http://uhilger.de |
|
40 |
* @author Published under the terms and conditions of |
|
41 |
* the <a href="http://www.gnu.org/licenses/agpl-3.0" target="_blank">GNU Affero General Public License</a> |
|
42 |
* |
|
43 |
* @version 1, September 16, 2012 |
|
44 |
*/ |
|
45 |
public class JsonFlatWandler extends AbstractWandler { |
|
46 |
|
|
47 |
/** Bezeichnerdes Formats, das dieser Wandler unterstuetzt */ |
|
48 |
public static final String FORMAT_FLATJSON = "FLATJSON"; |
|
49 |
|
|
50 |
protected XStream getXStream() { |
|
51 |
//XStream xstream = new XStream(new JettisonMappedXmlDriver()); |
|
52 |
XStream xstream = new XStream(new JsonHierarchicalStreamDriver() { |
|
53 |
public HierarchicalStreamWriter createWriter(Writer writer) { |
|
54 |
return new JsonWriter(writer, JsonWriter.DROP_ROOT_MODE); |
|
55 |
} |
|
56 |
}); |
|
57 |
return xstream; |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* Das Format ermitteln, das dieser Wandler verarbeitet |
|
62 |
* @return das Format, das dieser Wandler verarbeitet |
|
63 |
*/ |
|
64 |
@Override |
|
65 |
public String getFormat() { |
|
66 |
return FORMAT_FLATJSON; |
|
67 |
} |
|
68 |
|
|
69 |
} |