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 */ 028public class UonComplexExample { 029 /** 030 * Serializing PojoComplex bean into UON format. 031 * 032 * @param args Unused. 033 * @throws Exception Unused. 034 */ 035 public static void main(String[] args) throws Exception { 036 037 // Fill some data to a PojoComplex bean 038 var values = new HashMap<String,List<Pojo>>(); 039 var setOne = new ArrayList<Pojo>(); 040 setOne.add(new Pojo("1.1", "name1")); 041 setOne.add(new Pojo("1.1", "name2")); 042 var setTwo = new ArrayList<Pojo>(); 043 setTwo.add(new Pojo("1.2", "name1")); 044 setTwo.add(new Pojo("1.2", "name2")); 045 values.put("setOne", setOne); 046 values.put("setTwo", setTwo); 047 var pojoc = new PojoComplex("pojo", new Pojo("1.0", "name0"), values); 048 049 // this creates an RDF serializer with the default XML structure 050 /**Produces 051 * (innerPojo=(name=name0,id='1.0'), 052 * values=(setOne=@((name=name1,id='1.1'),(name=name2,id='1.1')), 053 * setTwo=@((name=name1,id='1.2'),(name=name2,id='1.2'))),id=pojo) 054 */ 055 var uonSerializer = UonSerializer.DEFAULT; 056 // This will show the final output from the bean 057 System.out.println(uonSerializer.serialize(pojoc)); 058 059 var obj = UonParser.DEFAULT.parse(uonSerializer.serialize(pojoc), PojoComplex.class); 060 061 assert obj.getId().equals(pojoc.getId()); 062 063 } 064}