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

import java.util.*;

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

public class NestedUnwrappedLists180Test  extends XmlTestBase
{
    static class Records {
        @JacksonXmlElementWrapper(useWrapping=false)
        public List<Record> records = new ArrayList<Record>();
    }

    static class Record {
        @JacksonXmlElementWrapper(useWrapping=false)
        public List<Field> fields = new ArrayList<Field>();
    }

    static class Field {
        @JacksonXmlProperty(isAttribute=true)
        public String name;

        protected Field() { }
        public Field(String n) { name = n; }
    }

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

    private final XmlMapper MAPPER = new XmlMapper();

    public void testNestedUnwrappedLists180() throws Exception
    {
        /*
        Records recs = new Records();
        recs.records.add(new Record());
        recs.records.add(new Record());
        recs.records.add(new Record());
        recs.records.get(0).fields.add(new Field("a"));
        recs.records.get(2).fields.add(new Field("b"));

        String xml = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(recs);
        */

        String xml =
"<Records>\n"
+"  <records>\n"
+"    <fields name='a'/>\n"
+"  </records>\n"

// Important: it's the empty CDATA here that causes breakage -- empty element would be fine

+"  <records>\n"
+"  </records>\n"
+"  <records>\n"
+"   <fields name='b'/>\n"
+"  </records>\n"
+"</Records>\n"
;
        
//System.out.println("XML: "+xml);

        Records result = MAPPER.readValue(xml, Records.class);
        assertNotNull(result.records);
        assertEquals(3, result.records.size());
        assertEquals(1, result.records.get(2).fields.size());
        assertEquals("b", result.records.get(2).fields.get(0).name);
    }
}

@@ -1610,72 +1610,8 @@
 %5Cn%22%0A
-+%22  %3Crecords%3E%5Cn%22%0A+%22    %3Cfields name='a'/%3E%5Cn%22%0A+%22  %3C/records%3E%5Cn%22%0A%0A
 // I
@@ -1684,16 +1684,22 @@
 element 
+alone 
 would be
@@ -1704,21 +1704,20 @@
 be fine%0A
-%0A+%22  
+//+%22
 %3Crecords
@@ -1719,22 +1719,41 @@
 cords%3E%5Cn
-%22%0A+%22  
+%3C/records%3E%5Cn%22%0A+%22%3Crecords%3E
 %3C/record
@@ -2010,9 +2010,9 @@
 als(
-3
+2
 , re
@@ -2068,33 +2068,33 @@
 ult.records.get(
-2
+1
 ).fields.size())
@@ -2132,33 +2132,33 @@
 ult.records.get(
-2
+1
 ).fields.get(0).

Simplify #180 test a little for better debugging