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); } }