Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JsonAlias with unwrapped lists #456

Merged
merged 1 commit into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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