001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.juneau.examples.core.uon; 020 021import org.apache.juneau.examples.core.pojo.Pojo; 022import org.apache.juneau.examples.core.pojo.PojoComplex; 023import org.apache.juneau.uon.UonParser; 024import org.apache.juneau.uon.UonSerializer; 025 026import java.util.ArrayList; 027import java.util.HashMap; 028import java.util.List; 029 030public class UONComplexExample { 031 /** 032 * Serializing PojoComplex bean into UON format. 033 * 034 * @param args 035 * @throws Exception 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}