public class JU_Stream2Obj {
- /*
- <?xml version="1.0" encoding=Config.UTF-8 standalone="yes"?>
- <root xmlns="urn:inherit">
- <base xsi:type="derivedA" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <name>myDerivedA_1</name>
- <num>1432</num>
- <shortName>mda_1</shortName>
- <value>value_1</value>
- <value>value_2</value>
- </base>
- </root>
-
- {"base":[{"__extension":"derivedA","name":"myDerivedA_1","num":1432,"shortName":"mda_1","value":["value_1","value_2"]}]}
- */
-
- @Test
- public void json2Obj() throws APIException, SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException, IOException {
- DerivedA da = new DerivedA();
- da.setName("myDerivedA_1");
- da.setNum((short)1432);
- da.setShortName("mda_1");
- da.getValue().add("value_1");
- da.getValue().add("value_2");
-
- Root root = new Root();
- root.getBase().add(da);
-
- da = new DerivedA();
- da.setName("myDerivedA_2");
- da.setNum((short)1432);
- da.setShortName("mda_2");
- da.getValue().add("value_2.1");
- da.getValue().add("value_2.2");
- root.getBase().add(da);
-
- EnvJAXB env = new BasicEnv();
- DataFactory<Root> rootDF = env.newDataFactory(Root.class);
-
- String xml = rootDF.newData(env).out(Data.TYPE.XML).load(root).option(Data.PRETTY).asString();
- System.out.println(xml);
-
- InXML inXML;
- Parse<Reader,?> in = inXML = new InXML(Root.class);
- Out out = new OutRaw();
-
- StringWriter sw = new StringWriter();
- out.extract(new StringReader(xml), sw, in);
- System.out.println(sw.toString());
-
-
- out = new OutJson();
-
- sw = new StringWriter();
- out.extract(new StringReader(xml), sw, in);
- String json;
- System.out.println(json = sw.toString());
-
- in = new InJson();
- out = new OutRaw();
-
- sw = new StringWriter();
- out.extract(new StringReader(json), sw, in);
- System.out.println(sw.toString());
-
- out = new OutXML(inXML);
-
- sw = new StringWriter();
- out.extract(new StringReader(json), sw, in, true);
- System.out.println(sw.toString());
-
- System.out.flush();
-
- }
+ /*
+ <?xml version="1.0" encoding=Config.UTF-8 standalone="yes"?>
+ <root xmlns="urn:inherit">
+ <base xsi:type="derivedA" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <name>myDerivedA_1</name>
+ <num>1432</num>
+ <shortName>mda_1</shortName>
+ <value>value_1</value>
+ <value>value_2</value>
+ </base>
+ </root>
+
+ {"base":[{"__extension":"derivedA","name":"myDerivedA_1","num":1432,"shortName":"mda_1","value":["value_1","value_2"]}]}
+ */
+
+ @Test
+ public void json2Obj() throws APIException, SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException, IOException {
+ DerivedA da = new DerivedA();
+ da.setName("myDerivedA_1");
+ da.setNum((short)1432);
+ da.setShortName("mda_1");
+ da.getValue().add("value_1");
+ da.getValue().add("value_2");
+
+ Root root = new Root();
+ root.getBase().add(da);
+
+ da = new DerivedA();
+ da.setName("myDerivedA_2");
+ da.setNum((short)1432);
+ da.setShortName("mda_2");
+ da.getValue().add("value_2.1");
+ da.getValue().add("value_2.2");
+ root.getBase().add(da);
+
+ EnvJAXB env = new BasicEnv();
+ DataFactory<Root> rootDF = env.newDataFactory(Root.class);
+
+ String xml = rootDF.newData(env).out(Data.TYPE.XML).load(root).option(Data.PRETTY).asString();
+ System.out.println(xml);
+
+ InXML inXML;
+ Parse<Reader,?> in = inXML = new InXML(Root.class);
+ Out out = new OutRaw();
+
+ StringWriter sw = new StringWriter();
+ out.extract(new StringReader(xml), sw, in);
+ System.out.println(sw.toString());
+
+
+ out = new OutJson();
+
+ sw = new StringWriter();
+ out.extract(new StringReader(xml), sw, in);
+ String json;
+ System.out.println(json = sw.toString());
+
+ in = new InJson();
+ out = new OutRaw();
+
+ sw = new StringWriter();
+ out.extract(new StringReader(json), sw, in);
+ System.out.println(sw.toString());
+
+ out = new OutXML(inXML);
+
+ sw = new StringWriter();
+ out.extract(new StringReader(json), sw, in, true);
+ System.out.println(sw.toString());
+
+ System.out.flush();
+
+ }
}