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