2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.misc.rosetta.test;
24 import inherit.DerivedA;
27 import java.io.IOException;
28 import java.io.Reader;
29 import java.io.StringReader;
30 import java.io.StringWriter;
32 import org.junit.Test;
33 import org.onap.aaf.misc.env.APIException;
34 import org.onap.aaf.misc.env.Data;
35 import org.onap.aaf.misc.env.DataFactory;
36 import org.onap.aaf.misc.env.EnvJAXB;
37 import org.onap.aaf.misc.env.impl.BasicEnv;
38 import org.onap.aaf.misc.rosetta.InJson;
39 import org.onap.aaf.misc.rosetta.InXML;
40 import org.onap.aaf.misc.rosetta.Out;
41 import org.onap.aaf.misc.rosetta.OutJson;
42 import org.onap.aaf.misc.rosetta.OutRaw;
43 import org.onap.aaf.misc.rosetta.OutXML;
44 import org.onap.aaf.misc.rosetta.Parse;
45 import org.onap.aaf.misc.rosetta.ParseException;
47 public class JU_Stream2Obj {
50 <?xml version="1.0" encoding=Config.UTF-8 standalone="yes"?>
51 <root xmlns="urn:inherit">
52 <base xsi:type="derivedA" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
53 <name>myDerivedA_1</name>
55 <shortName>mda_1</shortName>
56 <value>value_1</value>
57 <value>value_2</value>
61 {"base":[{"__extension":"derivedA","name":"myDerivedA_1","num":1432,"shortName":"mda_1","value":["value_1","value_2"]}]}
65 public void json2Obj() throws APIException, SecurityException, NoSuchFieldException, ClassNotFoundException, ParseException, IOException {
66 DerivedA da = new DerivedA();
67 da.setName("myDerivedA_1");
68 da.setNum((short)1432);
69 da.setShortName("mda_1");
70 da.getValue().add("value_1");
71 da.getValue().add("value_2");
73 Root root = new Root();
74 root.getBase().add(da);
77 da.setName("myDerivedA_2");
78 da.setNum((short)1432);
79 da.setShortName("mda_2");
80 da.getValue().add("value_2.1");
81 da.getValue().add("value_2.2");
82 root.getBase().add(da);
84 EnvJAXB env = new BasicEnv();
85 DataFactory<Root> rootDF = env.newDataFactory(Root.class);
87 String xml = rootDF.newData(env).out(Data.TYPE.XML).load(root).option(Data.PRETTY).asString();
88 System.out.println(xml);
91 Parse<Reader,?> in = inXML = new InXML(Root.class);
92 Out out = new OutRaw();
94 StringWriter sw = new StringWriter();
95 out.extract(new StringReader(xml), sw, in);
96 System.out.println(sw.toString());
101 sw = new StringWriter();
102 out.extract(new StringReader(xml), sw, in);
104 System.out.println(json = sw.toString());
109 sw = new StringWriter();
110 out.extract(new StringReader(json), sw, in);
111 System.out.println(sw.toString());
113 out = new OutXML(inXML);
115 sw = new StringWriter();
116 out.extract(new StringReader(json), sw, in, true);
117 System.out.println(sw.toString());