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

import java.util.*;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;

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;

// Actual reproduction of [dataformat-xml#469]: quite specific set up
// needed, alas
public class ListDeser469FailingTest extends XmlTestBase
{
    static class OuterBean {
        public MiddleBean middle;
    }

    @JsonPropertyOrder({"inner1", "inner2"})
    static class MiddleBean
    {
        public InnerBean1 inner1;

        @JacksonXmlElementWrapper(useWrapping = false)
        public List<InnerBean2> inner2;
    }

    static class InnerBean1
    {
        public String str;

        // Fail if (and only if!) wrapping disabled, by default or via
        // annotations
        // (that is; if this is commented out, passes)
        @JacksonXmlElementWrapper(useWrapping = false)
        public List<InnerBean1Item> item;
    }

    static class InnerBean1Item
    {
        @JacksonXmlProperty(isAttribute = true)
        public String id;
    }

    static class InnerBean2
    {
        @JacksonXmlProperty(isAttribute = true)
        public String str2;

        protected InnerBean2() { }
        public InnerBean2(String s) { str2 = s; }
    }

    /*
    /**********************************************************************
    /* Test methods
    /**********************************************************************
     */

    public void testIssue469WithDefaults() throws Exception
    {
        // Here we just use default settings (which defaults to using wrappers)
        final XmlMapper mapper = newMapper();

        // First: create POJO value to test round-trip:
        {
            OuterBean source = new OuterBean();
            source.middle = new MiddleBean();
            List<InnerBean2> items = new ArrayList<>();
            items.add(new InnerBean2("foo"));
            source.middle.inner2 = items;

            String xml = mapper.writerWithDefaultPrettyPrinter()
                    .writeValueAsString(source);

            OuterBean result = mapper.readValue(xml, OuterBean.class);

            MiddleBean mid = result.middle;
            assertNotNull(mid);
            assertNotNull(mid.inner2);
            assertEquals(1, mid.inner2.size());
            assertEquals("foo", mid.inner2.get(0).str2);
        }

        // And then verify from XML String
        String xmlInput = "<OuterBean>\n" +
            "  <middle>\n" +
            "    <inner1/>\n" +
            "    <inner2 str2='aaaa'/>\n" +
            "  </middle>\n" +
            "</OuterBean>\n";

        OuterBean outer = mapper.readValue(xmlInput, OuterBean.class);

        MiddleBean mid = outer.middle;
        assertNotNull(mid);

        assertNotNull(mid.inner2);
        assertEquals(1, mid.inner2.size());
        assertEquals("aaaa", mid.inner2.get(0).str2);
    }
}

@@ -128,16 +128,69 @@
 yOrder;%0A
+import com.fasterxml.jackson.annotation.JsonRootName;
 %0Aimport 
@@ -600,78 +600,8 @@
 e%0A%7B%0A
-    static class OuterBean %7B%0A        public MiddleBean middle;%0A    %7D%0A%0A
     
@@ -641,16 +641,43 @@
 ner2%22%7D)%0A
+    @JsonRootName(%22outer%22)%0A
     stat
@@ -685,26 +685,24 @@
 c class 
-MiddleBean
+Outer469
 %0A    %7B%0A 
@@ -1918,16 +1918,26 @@
 %0A       
+ if (true)
  %7B%0A     
@@ -1948,20 +1948,19 @@
    Outer
-Bean
+469
  source 
@@ -1974,58 +1974,11 @@
 uter
-Bean();%0A            source.middle = new MiddleBean
+469
 ();%0A
@@ -2102,15 +2102,8 @@
 rce.
-middle.
 inne
@@ -2229,16 +2229,52 @@
 ource);%0A
+//System.err.println(%22XML: %5Cn%22+xml);
 %0A       
@@ -2283,20 +2283,19 @@
    Outer
-Bean
+469
  result 
@@ -2319,28 +2319,27 @@
 e(xml, Outer
-Bean
+469
 .class);%0A%0A  
@@ -2340,52 +2340,8 @@
 );%0A%0A
-            MiddleBean mid = result.middle;%0A
     
@@ -2362,19 +2362,22 @@
 NotNull(
-mid
+result
 );%0A     
@@ -2389,35 +2389,38 @@
   assertNotNull(
-mid
+result
 .inner2);%0A      
@@ -2433,35 +2433,38 @@
 assertEquals(1, 
-mid
+result
 .inner2.size());
@@ -2496,19 +2496,22 @@
 (%22foo%22, 
-mid
+result
 .inner2.
@@ -2607,26 +2607,8 @@
 ut =
- %22%3COuterBean%3E%5Cn%22 +
 %0A   
@@ -2621,17 +2621,14 @@
    %22
-  %3Cmiddle
+%3Couter
 %3E%5Cn%22
@@ -2635,34 +2635,32 @@
  +%0A            %22
-  
   %3Cinner1/%3E%5Cn%22 +
@@ -2673,18 +2673,16 @@
        %22
-  
   %3Cinner
@@ -2719,49 +2719,15 @@
    %22
-  %3C/middle%3E%5Cn%22 +%0A            %22%3C/OuterBean
+%3C/outer
 %3E%5Cn%22
@@ -2746,18 +2746,18 @@
 uter
-Bean outer
+469 result
  = m
@@ -2791,20 +2791,19 @@
 uter
-Bean
+469
 .class);
 %0A%0A  
@@ -2802,48 +2802,8 @@
 ss);
-%0A%0A        MiddleBean mid = outer.middle;
 %0A   
@@ -2821,19 +2821,22 @@
 NotNull(
-mid
+result
 );%0A%0A    
@@ -2853,19 +2853,22 @@
 NotNull(
-mid
+result
 .inner2)
@@ -2893,19 +2893,22 @@
 uals(1, 
-mid
+result
 .inner2.
@@ -2949,11 +2949,14 @@
 a%22, 
-mid
+result
 .inn

Simplify failing #469 test to minimal repro