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 static org.apache.juneau.commons.utils.Shorts.*; 020 021import java.util.*; 022 023import org.apache.juneau.commons.logging.*; 024import org.apache.juneau.examples.core.pojo.*; 025import org.apache.juneau.marshall.uon.*; 026 027/** 028 * UON complex example. 029 * 030 */ 031public class UonComplexExample { 032 033 /** 034 * Serializing PojoComplex bean into UON format. 035 * 036 * @param args Unused. 037 * @throws Exception Unused. 038 */ 039 public static void main(String[] args) throws Exception { 040 041 // Fill some data to a PojoComplex bean 042 Map<String,List<Pojo>> values = m(); 043 List<Pojo> setOne = l(); 044 setOne.add(new Pojo("1.1", "name1")); 045 setOne.add(new Pojo("1.1", "name2")); 046 List<Pojo> setTwo = l(); 047 setTwo.add(new Pojo("1.2", "name1")); 048 setTwo.add(new Pojo("1.2", "name2")); 049 values.put("setOne", setOne); 050 values.put("setTwo", setTwo); 051 var pojoc = new PojoComplex("pojo", new Pojo("1.0", "name0"), values); 052 053 // this creates an RDF serializer with the default XML structure 054 /**Produces 055 * (innerPojo=(name=name0,id='1.0'), 056 * values=(setOne=@((name=name1,id='1.1'),(name=name2,id='1.1')), 057 * setTwo=@((name=name1,id='1.2'),(name=name2,id='1.2'))),id=pojo) 058 */ 059 var uonSerializer = UonSerializer.DEFAULT; 060 // This will show the final output from the bean 061 RichLogger.getLogger(UonComplexExample.class).info(uonSerializer.write(pojoc)); 062 063 var obj = UonParser.DEFAULT.read(uonSerializer.write(pojoc), PojoComplex.class); 064 065 assert obj.getId().equals(pojoc.getId()); 066 067 } 068}