Skip to content

Commit 74f0f44

Browse files
committed
Add (failing) test for #2932
1 parent 8d48c75 commit 74f0f44

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -576,9 +576,9 @@ public TypeResolverBuilder<?> findTypeResolver(MapperConfig<?> config,
576576
public TypeResolverBuilder<?> findPropertyTypeResolver(MapperConfig<?> config,
577577
AnnotatedMember am, JavaType baseType)
578578
{
579-
/* As per definition of @JsonTypeInfo, should only apply to contents of container
580-
* (collection, map) types, not container types themselves:
581-
*/
579+
// As per definition of @JsonTypeInfo, should only apply to contents of container
580+
// (collection, map) types, not container types themselves:
581+
582582
// 17-Apr-2016, tatu: For 2.7.4 make sure ReferenceType also included
583583
if (baseType.isContainerType() || baseType.isReferenceType()) {
584584
return null;
@@ -591,9 +591,8 @@ public TypeResolverBuilder<?> findPropertyTypeResolver(MapperConfig<?> config,
591591
public TypeResolverBuilder<?> findPropertyContentTypeResolver(MapperConfig<?> config,
592592
AnnotatedMember am, JavaType containerType)
593593
{
594-
/* First: let's ensure property is a container type: caller should have
595-
* verified but just to be sure
596-
*/
594+
// First: let's ensure property is a container type: caller should have
595+
// verified but just to be sure
597596
if (containerType.getContentType() == null) {
598597
throw new IllegalArgumentException("Must call method with a container or reference type (got "+containerType+")");
599598
}

src/test/java/com/fasterxml/jackson/databind/deser/creators/ImplicitParamsForCreatorTest.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ public XY(int x, int y) {
3737
/**********************************************************
3838
*/
3939

40+
private final ObjectMapper MAPPER = jsonMapperBuilder()
41+
// important! Chain to also use standard Jackson annotations
42+
.annotationIntrospector(new MyParamIntrospector())
43+
.build();
44+
4045
public void testNonSingleArgCreator() throws Exception
4146
{
42-
ObjectMapper mapper = new ObjectMapper();
43-
mapper.setAnnotationIntrospector(new MyParamIntrospector());
44-
XY value = mapper.readValue(aposToQuotes("{'paramName0':1,'paramName1':2}"), XY.class);
47+
XY value = MAPPER.readValue(aposToQuotes("{'paramName0':1,'paramName1':2}"), XY.class);
4548
assertNotNull(value);
4649
assertEquals(1, value.x);
4750
assertEquals(2, value.y);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import com.fasterxml.jackson.databind.*;
4+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
5+
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
6+
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
7+
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
8+
9+
public class ImplicitParamsForCreator2932Test extends BaseMapTest
10+
{
11+
@SuppressWarnings("serial")
12+
static class MyParamIntrospector extends JacksonAnnotationIntrospector
13+
{
14+
@Override
15+
public String findImplicitPropertyName(AnnotatedMember param) {
16+
if (param instanceof AnnotatedParameter) {
17+
AnnotatedParameter ap = (AnnotatedParameter) param;
18+
return "paramName"+ap.getIndex();
19+
}
20+
return super.findImplicitPropertyName(param);
21+
}
22+
}
23+
24+
// [databind#2932]
25+
static class Bean2932
26+
{
27+
int _a, _b;
28+
29+
// @JsonCreator
30+
public Bean2932(/*@com.fasterxml.jackson.annotation.JsonProperty("paramName0")*/
31+
@JsonDeserialize() int a, int b) {
32+
_a = a;
33+
_b = b;
34+
}
35+
}
36+
37+
/*
38+
/**********************************************************
39+
/* Test methods
40+
/**********************************************************
41+
*/
42+
43+
private final ObjectMapper MAPPER = jsonMapperBuilder()
44+
// important! Chain to also use standard Jackson annotations
45+
.annotationIntrospector(new MyParamIntrospector())
46+
.build();
47+
48+
// [databind#2932]
49+
public void testJsonCreatorWithOtherAnnotations() throws Exception
50+
{
51+
Bean2932 bean = MAPPER.readValue(a2q("{'paramName0':1,'paramName1':2}"),
52+
Bean2932.class);
53+
assertNotNull(bean);
54+
assertEquals(1, bean._a);
55+
assertEquals(2, bean._b);
56+
}
57+
}

0 commit comments

Comments
 (0)