Skip to content

Commit

Permalink
Fix JsonAlias with unwrapped lists (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
westinrm authored Mar 26, 2021
1 parent bd95805 commit a55f327
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
}
// not optimal; should be able to use PropertyName...
unwrappedNames.add(prop.getName());
for (PropertyName alias : prop.findAliases(ctxt.getConfig())) {
unwrappedNames.add(alias.getSimpleName());
}
}
// Ok: if nothing to take care of, just return the delegatee...
if (unwrappedNames == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fasterxml.jackson.dataformat.xml.lists;

import com.fasterxml.jackson.annotation.JsonAlias;
import java.util.*;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
Expand Down Expand Up @@ -68,6 +69,7 @@ static class ListBeanWrapped
static class ListBeanUnwrapped
{
@JacksonXmlElementWrapper(useWrapping=false)
@JsonAlias("aliasValue")
public List<Integer> values;
}

Expand Down Expand Up @@ -193,6 +195,19 @@ public void testUnwrappedListBeanDeser() throws Exception
assertEquals(Integer.valueOf(3), bean.values.get(2));
}

public void testUnwrappedAliasListBeanDeser() throws Exception
{
ListBeanUnwrapped bean = MAPPER.readValue(
"<ListBeanUnwrapped><aliasValue>1</aliasValue><aliasValue>2</aliasValue><aliasValue>3</aliasValue></ListBeanUnwrapped>",
ListBeanUnwrapped.class);
assertNotNull(bean);
assertNotNull(bean.values);
assertEquals(3, bean.values.size());
assertEquals(Integer.valueOf(1), bean.values.get(0));
assertEquals(Integer.valueOf(2), bean.values.get(1));
assertEquals(Integer.valueOf(3), bean.values.get(2));
}

// [dataformat-xml#191]
public void testListDeser191() throws Exception
{
Expand Down

0 comments on commit a55f327

Please sign in to comment.