package com.fasterxml.jackson.databind.deser;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;

public class PropertyAliasTest extends BaseMapTest
{
    static class AliasBean {
        @JsonAlias({ "nm", "Name" })
        public String name;

        int _xyz;

        int _a;

        @JsonCreator
        public AliasBean(@JsonProperty("a")
            @JsonAlias("A") int a) {
            _a = a;
        }
        
        @JsonAlias({ "Xyz" })
        public void setXyz(int x) {
            _xyz = x;
        }
    }

    private final ObjectMapper MAPPER = new ObjectMapper();

    // [databind#1029]
    public void testSimpleAliases() throws Exception
    {
        AliasBean bean;

        // first, one indicated by field annotation, set via field
        bean = MAPPER.readValue(aposToQuotes("{'Name':'Foobar','a':3,'xyz':37}"),
                AliasBean.class);
        assertEquals("Foobar", bean.name);
        assertEquals(3, bean._a);
        assertEquals(37, bean._xyz);

        // then method-bound one
        bean = MAPPER.readValue(aposToQuotes("{'name':'Foobar','a':3,'Xyz':37}"),
                AliasBean.class);
        assertEquals("Foobar", bean.name);
        assertEquals(3, bean._a);
        assertEquals(37, bean._xyz);
        
        // and finally, constructor-backed one
        bean = MAPPER.readValue(aposToQuotes("{'name':'Foobar','A':3,'xyz':37}"),
                AliasBean.class);
        assertEquals("Foobar", bean.name);
        assertEquals(3, bean._a);
        assertEquals(37, bean._xyz);
    }
}

@@ -198,16 +198,124 @@
 operty;%0A
+import com.fasterxml.jackson.annotation.JsonSubTypes;%0Aimport com.fasterxml.jackson.annotation.JsonTypeInfo;%0A
 import c
@@ -357,16 +357,16 @@
 apTest;%0A
-
 import c
@@ -840,16 +840,407 @@
 %0A    %7D%0A%0A
+    static class PolyWrapperForAlias %7B%0A        @JsonTypeInfo(use = JsonTypeInfo.Id.NAME,%0A                include = JsonTypeInfo.As.WRAPPER_ARRAY)%0A        @JsonSubTypes(%7B%0A            @JsonSubTypes.Type(value = AliasBean.class,name = %22ab%22),%0A        %7D)%0A        public Object value;%0A%0A        protected PolyWrapperForAlias() %7B %7D%0A        public PolyWrapperForAlias(Object v) %7B value = v; %7D%0A    %7D%0A%0A
     priv
@@ -1274,17 +1274,16 @@
 ER = new
- 
 ObjectMa
@@ -2200,32 +2200,32 @@
 ls(3, bean._a);%0A
-
         assertEq
@@ -2250,11 +2250,423 @@
 );%0A    %7D
+%0A%0A    public void testAliasWithPolymorphic() throws Exception%0A    %7B%0A        PolyWrapperForAlias value = MAPPER.readValue(aposToQuotes(%0A                %22%7B'value': %5B'ab', %7B'nm' : 'Bob', 'A' : 17%7D %5D %7D%22%0A                ), PolyWrapperForAlias.class);%0A        assertNotNull(value.value);%0A        AliasBean bean = (AliasBean) value.value;%0A        assertEquals(%22Bob%22, bean.name);%0A        assertEquals(17, bean._a);%0A    %7D
 %0A%7D%0A

test improvement for alias/polymorphic