001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.examples.core.uon;
018
019import java.util.*;
020
021import org.apache.juneau.examples.core.pojo.*;
022import org.apache.juneau.uon.*;
023
024/**
025 * UON complex example.
026 *
027 * <h5 class='section'>See Also:</h5><ul>
028 * </ul>
029 */
030public class UonComplexExample {
031   /**
032    * Serializing PojoComplex bean into UON format.
033    *
034    * @param args Unused.
035    * @throws Exception Unused.
036    */
037   public static void main(String[] args) throws Exception {
038
039      // Fill some data to a PojoComplex bean
040      HashMap<String, List<Pojo>> values = new HashMap<>();
041      ArrayList<Pojo> setOne = new ArrayList<>();
042      setOne.add(new Pojo("1.1", "name1"));
043      setOne.add(new Pojo("1.1", "name2"));
044      ArrayList<Pojo> setTwo = new ArrayList<>();
045      setTwo.add(new Pojo("1.2", "name1"));
046      setTwo.add(new Pojo("1.2", "name2"));
047      values.put("setOne", setOne);
048      values.put("setTwo", setTwo);
049      PojoComplex pojoc = new PojoComplex("pojo", new Pojo("1.0", "name0"), values);
050
051      // this creates an RDF serializer with the default XML structure
052      /**Produces
053       * (innerPojo=(name=name0,id='1.0'),
054       * values=(setOne=@((name=name1,id='1.1'),(name=name2,id='1.1')),
055       * setTwo=@((name=name1,id='1.2'),(name=name2,id='1.2'))),id=pojo)
056       */
057      UonSerializer uonSerializer = UonSerializer.DEFAULT;
058      // This will show the final output from the bean
059      System.out.println(uonSerializer.serialize(pojoc));
060
061      PojoComplex obj = UonParser.DEFAULT.parse(uonSerializer.serialize(pojoc), PojoComplex.class);
062
063      assert obj.getId().equals(pojoc.getId());
064
065   }
066}