Skip to content

Commit bcd616d

Browse files
committed
Fix #1383
1 parent a80cef2 commit bcd616d

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Project: jackson-databind
1515
#1368: Problem serializing `JsonMappingException` due to addition of non-ignored
1616
`processor` property (added in 2.7)
1717
(reported, suggesed fix by Josh C)
18+
#1383: Problem with `@JsonCreator` with 1-arg factory-method, implicit param names
1819

1920
2.7.7 (27-Aug-2016)
2021

src/main/java/com/fasterxml/jackson/databind/deser/BasicDeserializerFactory.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,11 @@ protected boolean _handleSingleArgumentConstructor(DeserializationContext ctxt,
683683
if (!useProps) { // not property based but delegating
684684
/*boolean added=*/ _handleSingleArgumentFactory(config, beanDesc, vchecker, intr, creators,
685685
factory, isCreator);
686-
// otherwise just ignored
686+
// 23-Sep-2016, tatu: [databind#1383]: Need to also sever link to avoid possible
687+
// later problems with "unresolved" constructor property
688+
if (argDef != null) {
689+
((POJOPropertyBuilder) argDef).removeConstructors();
690+
}
687691
continue;
688692
}
689693
// fall through if there's name

src/test/java/com/fasterxml/jackson/databind/creators/SingleArgCreatorTest.java

+37-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,30 @@ public static ExplicitFactoryBeanB valueOf(String str) {
115115

116116
public String value() { return value; }
117117
}
118+
119+
static class XY {
120+
public int x, y;
121+
}
118122

123+
// [databind#1383]
124+
static class SingleArgWithImplicit {
125+
protected XY _value;
126+
127+
private SingleArgWithImplicit() {
128+
throw new Error("Should not get called");
129+
}
130+
private SingleArgWithImplicit(XY v, boolean bogus) {
131+
_value = v;
132+
}
133+
134+
@JsonCreator
135+
public static SingleArgWithImplicit from(XY v) {
136+
return new SingleArgWithImplicit(v, true);
137+
}
138+
139+
public XY getFoobar() { return _value; }
140+
}
141+
119142
/*
120143
/**********************************************************
121144
/* Test methods
@@ -147,7 +170,7 @@ public void testSingleImplicitlyNamedNotDelegating() throws Exception
147170
StringyBeanWithProps bean = mapper.readValue("{\"value\":\"x\"}", StringyBeanWithProps.class);
148171
assertEquals("x", bean.getValue());
149172
}
150-
173+
151174
// [databind#714]
152175
public void testSingleExplicitlyNamedButDelegating() throws Exception
153176
{
@@ -171,5 +194,18 @@ public void testExplicitFactory660b() throws Exception
171194
assertNotNull(bean2);
172195
assertEquals("def", bean2.value());
173196
}
197+
198+
// [databind#1383]
199+
public void testSingleImplicitDelegating() throws Exception
200+
{
201+
final ObjectMapper mapper = new ObjectMapper();
202+
mapper.setAnnotationIntrospector(new MyParamIntrospector("value"));
203+
SingleArgWithImplicit bean = mapper.readValue(aposToQuotes("{'x':1,'y':2}"),
204+
SingleArgWithImplicit.class);
205+
XY v = bean.getFoobar();
206+
assertNotNull(v);
207+
assertEquals(1, v.x);
208+
assertEquals(2, v.y);
209+
}
174210
}
175211

0 commit comments

Comments
 (0)