* 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.
public void single() throws Exception {
Single single = setSData();
SingleMarshal psingle = new SingleMarshal();
-
+
OutRaw raw = new OutRaw();
OutJson json = new OutJson();
OutXML xml = new OutXML("Single","xmlns=urn:types:xsd");
-
-
+
+
System.out.println("===== RAW =====");
raw.extract(single, System.out, psingle);
System.out.println("\n===== JSON =====");
json.extract(single, System.out, psingle);
-
+
System.out.println("\n\n===== Pretty JSON =====");
json.extract(single, System.out, psingle, true);
// xml.extract(single, sw, psingle, true);
news = jumar.unmarshal(env.info(), sw.toString());
System.out.println(sw.toString());
-
+
String sample = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ "\n<ns2:urn.types.xsd xmlns:ns2=\"Single\" xmlns=\"urn:types:xsd\">"
+ "\n<str>MyString</str>"
System.out.println(news.getDatetime());
}
-
+
@Test
public void multi() throws Exception {
OutRaw raw = new OutRaw();
Multi multi = new Multi();
MultiMarshal pmulti = new MultiMarshal();
-
+
for (int i=0;i<10;++i) {
System.out.println("===== Multi Iteration " + i + " =====");
if (i>0) {
}
System.out.println(" ===== RAW =====");
raw.extract(multi, System.out, pmulti);
-
+
System.out.println("\n ===== JSON =====");
json.extract(multi, System.out, pmulti);
-
+
System.out.println("\n\n ===== Pretty JSON =====");
json.extract(multi, System.out, pmulti, true);
-
+
System.out.println("\n\n ===== XML =====");
xml.extract(multi, System.out, pmulti,false);
-
+
System.out.println("\n\n ===== Pretty XML =====");
xml.extract(multi, System.out, pmulti, true);
}
Multi multi = new Multi();
DocMarshal<Multi> doc = DocMarshal.root(new MultiMarshal());
-
+
for (int i=0;i<3;++i) {
System.out.println("===== Multi Iteration " + i + " =====");
if (i>0) {
}
System.out.println(" ===== RAW =====");
raw.extract(multi, System.out, doc);
-
+
System.out.println("\n ===== JSON =====");
json.extract(multi, System.out, doc);
-
+
System.out.println("\n\n ===== Pretty JSON =====");
json.extract(multi, System.out, doc, true);
-
+
System.out.println("\n\n ===== XML =====");
xml.extract(multi, System.out, doc,false);
-
+
System.out.println("\n\n ===== Pretty XML =====");
xml.extract(multi, System.out, doc, true);
}
// Saved saved = new Saved();
// saved.extract(in, ignore, parser, options);
// }
-
+
@Test
public void df() throws Exception {
RosettaEnv env = new RosettaEnv();
RosettaDF<Multi> df = env.newDataFactory(Multi.class);
df.out(TYPE.JSON).option(Data.PRETTY);
-
+
Multi multi = new Multi();
multi.getSingle().add(setSData());
-
+
System.out.println("========== Original loading");
Trans trans = env.newTrans();
}
trans = env.newTrans();
data = df.newData(trans);
-
+
int iters = 10000;
for (int i=0;i<iters;++i) {
data.load(multi);
}
trans = env.newTrans();
data = df.newData(trans);
-
+
for (int i=0;i<iters;++i) {
data.load(multi);
}
metrics = trans.auditTrail(0, null,Env.JSON,Env.XML);
System.out.println(data.asString());
System.out.println(metrics.total/iters + "ms avg");
-
+
// Assert.assertEquals(first, second);
System.out.println("========== Direct Object to JSON String");
sbw.reset();
data.direct(multi, sbw, true);
}
-
+
metrics = trans.auditTrail(0, null,Env.JSON,Env.XML);
System.out.println(sbw.toString());
System.out.println(metrics.total/iters + "ms avg");
-
+
}
-
+
private Single setSData() {
Single s = new Single();
s.setStr("MyString");
// Out jout = new OutJson();
//
//// go(jin, jout, "{\"id\":\"Me, Myself\",\"date\":1353094689100}");
-//
+//
// }
-
-
+
+
/*
private void go(Parse<Reader,?> in, Out out, String str) throws IOException, ParseException {
-
+
System.out.println(str);
StringWriter sw = new StringWriter(1024);
out.extract(new StringReader(str), sw, in);
System.out.println(sw);
String result = sw.toString();
-
+
if (!result.equals(str)) {
sw.getBuffer().setLength(0);
new OutRaw().extract(new StringReader(str), sw, in);