package com.levelup.java.xml;

import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.List;

import org.junit.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.google.common.base.Objects;

/**
 * This java example will demonstrate converting json
 * to XML.  There are quite a few various libs that appear
 * to do it, this example will focus on jackson.
 * 
 * @author Justin Musgrove
 * @see <a href='http://www.leveluplunch.com/java/examples/convert-json-to-xml/'>Convert json to xml</a>
 * 
 */
public class ConvertJSONtoXML {

	
	class Browser {
		private String name;

		public Browser(String name) {
			super();
			this.name = name;
		}
		
		@Override
		public String toString() {
			return Objects.toStringHelper(this)
					.add("name", name)
					.toString();
		}

		public String getName() {
			return name;
		}
	}
	
	
	@Test
	public void convert_json_to_xml_jackson () throws IOException {
		
		String browsersAsJson ="[{\"name\":\"Chrome\"},{\"name\":\"FireFox\"},{\"name\":\"Internet Explorer\"}]\n";
		
		ObjectMapper jsonMapper = new ObjectMapper();
	    
		@SuppressWarnings("unchecked")
		List<Browser> browsers = jsonMapper.readValue(browsersAsJson, List.class);

	    XmlMapper xmlMapper = new XmlMapper();
	    
	    String browsersAsXml = xmlMapper.writeValueAsString(browsers);
	    
	    assertTrue(browsersAsXml.length() > 0);
	}
	
}

@@ -116,24 +116,56 @@
 util.List;%0A%0A
+import org.apache.log4j.Logger;%0A
 import org.j
@@ -321,16 +321,65 @@
 Objects;
+%0Aimport com.levelup.java.util.ReadPropertiesFile;
 %0A%0A/**%0A *
@@ -714,16 +714,99 @@
 toXML %7B%0A
+%09%0A%09private static final Logger logger = Logger.getLogger(ReadPropertiesFile.class);
 %0A%09%0A%09clas
@@ -1568,24 +1568,63 @@
 ers);%0A%09    %0A
+%09    logger.info(browsersAsXml);%0A%09    %0A
 %09    assertT
@@ -1660,11 +1660,12 @@
 0);%0A%09%7D%0A%09
+ 
 %0A%7D%0A

add logger