package com.fasterxml.jackson.dataformat.xml.jaxb;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
import com.fasterxml.jackson.dataformat.xml.XmlAnnotationIntrospector;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;

public class TestElementWrapper extends XmlTestBase
{
    @XmlRootElement(name = "Individual")
    class MyPerson {
          public String name;

          @XmlElementWrapper(name = "offspring")
          @XmlElement(name = "kid")
          public List<MyPerson> children = new ArrayList<MyPerson>();
    }

    /*
    /**********************************************************************
    /* Unit tests
    /**********************************************************************
     */

    public void testElementWrapper() throws Exception
    {
        XmlMapper _jaxbMapper = new XmlMapper();
        // Use JAXB-then-Jackson annotation introspector
        AnnotationIntrospector intr = XmlAnnotationIntrospector.Pair.instance
            (new XmlJaxbAnnotationIntrospector(), new JacksonAnnotationIntrospector());
        _jaxbMapper.setAnnotationIntrospector(intr);

        MyPerson person = new MyPerson();
        person.name = "Jay";

        MyPerson child = new MyPerson();
        child.name = "Junior";
        
        person.children.add(child);

        String xml = _jaxbMapper.writer().writeValueAsString(person);
        
        String expected = "<Individual><name>Jay</name>"
                + "<offspring><kid><name>Junior</name><offspring/></kid></offspring></Individual>";
        assertEquals(expected, xml);
    }
}

@@ -568,16 +568,250 @@
 estBase;
+%0Aimport com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;%0Aimport com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;%0Aimport com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 %0A%0Apublic
@@ -1113,16 +1113,905 @@
 %0A    %7D%0A%0A
+    @JacksonXmlRootElement(localName = %22output%22)%0A    static class Bean %7B%0A        public BeanInfo%5B%5D beanInfo;%0A        public BeanInfo%5B%5D beanOther;%0A%0A        @JacksonXmlElementWrapper(localName = %22beanInfo%22)%0A        @JacksonXmlProperty(localName = %22item%22)%0A        public BeanInfo%5B%5D getBeanInfo() %7B%0A            return beanInfo;%0A        %7D%0A%0A        public void setBeanInfo(BeanInfo%5B%5D beanInfo) %7B%0A            this.beanInfo = beanInfo;%0A        %7D%0A%0A        @JacksonXmlElementWrapper(localName = %22beanOther%22)%0A        @JacksonXmlProperty(localName = %22item%22)%0A        public BeanInfo%5B%5D getBeanOther() %7B%0A            return beanOther;%0A        %7D%0A%0A        public void setBeanOther(BeanInfo%5B%5D beanOther) %7B%0A            this.beanOther = beanOther;%0A        %7D%0A    %7D    %0A    static class BeanInfo %7B%0A        public String name;%0A%0A        public BeanInfo() %7B %7D%0A        public BeanInfo(String n) %7B name = n; %7D%0A    %7D%0A%0A
     /*%0A 
@@ -3000,16 +3000,16 @@
 dual%3E%22;%0A
-
         
@@ -3042,11 +3042,454 @@
 );%0A    %7D
+%0A%0A    public void testIssue27() throws Exception%0A    %7B%0A        XmlMapper mapper = new XmlMapper();%0A%0A        Bean bean = new Bean();%0A        BeanInfo beanInfo = new BeanInfo(%22name%22);%0A        BeanInfo beanOther = new BeanInfo(%22name%22);%0A        bean.setBeanInfo(new BeanInfo%5B%5D %7B beanInfo %7D);%0A        bean.setBeanOther(new BeanInfo%5B%5D %7B beanOther %7D);%0A        String output = mapper.writeValueAsString(bean);%0A        System.out.println(output);%0A    %7D
 %0A%7D%0A

Add unit test for [Issue-27]