Skip to content

Commit

Permalink
Test case demonstrating FasterXML#4327
Browse files Browse the repository at this point in the history
Signed-off-by: kwall <kwall@apache.org>
  • Loading branch information
k-wall committed Jan 17, 2024
1 parent 89ed565 commit 8380c94
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/test/java/tools/jackson/databind/deser/PropertyAliasTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import tools.jackson.databind.MapperFeature;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.json.JsonMapper;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -64,6 +66,20 @@ protected PolyWrapperForAlias() { }
public PolyWrapperForAlias(Object v) { value = v; }
}

@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
@JsonSubTypes({
@JsonSubTypes.Type(value = DeductionBean1.class),
@JsonSubTypes.Type(value = DeductionBean2.class)
})
interface Deduction {
}

record DeductionBean1(int x) implements Deduction {
}

record DeductionBean2(@JsonAlias("Y") int y) implements Deduction {
}

// [databind#2669]
static class Pojo2669 {
@JsonAlias({"nick", "name"})
Expand Down Expand Up @@ -126,6 +142,17 @@ public void testAliasWithPolymorphic() throws Exception
assertEquals(17, bean._a);
}

@ParameterizedTest
@ValueSource(strings = {"y", "Y"})
public void testAliasWithPolymorphicDeduction(String field) throws Exception
{
Deduction value = MAPPER.readValue(a2q(
"{'%s': 2 }".formatted(field)
), Deduction.class);
assertNotNull(value);
assertEquals(2, ((DeductionBean2) value).y());
}

// [databind#2378]
@Test
public void testAliasInFactoryMethod() throws Exception
Expand Down

0 comments on commit 8380c94

Please sign in to comment.