Skip to content

Commit

Permalink
Fix #1383
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 24, 2016
1 parent a80cef2 commit bcd616d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Project: jackson-databind
#1368: Problem serializing `JsonMappingException` due to addition of non-ignored
`processor` property (added in 2.7)
(reported, suggesed fix by Josh C)
#1383: Problem with `@JsonCreator` with 1-arg factory-method, implicit param names

2.7.7 (27-Aug-2016)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,11 @@ protected boolean _handleSingleArgumentConstructor(DeserializationContext ctxt,
if (!useProps) { // not property based but delegating
/*boolean added=*/ _handleSingleArgumentFactory(config, beanDesc, vchecker, intr, creators,
factory, isCreator);
// otherwise just ignored
// 23-Sep-2016, tatu: [databind#1383]: Need to also sever link to avoid possible
// later problems with "unresolved" constructor property
if (argDef != null) {
((POJOPropertyBuilder) argDef).removeConstructors();
}
continue;
}
// fall through if there's name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,30 @@ public static ExplicitFactoryBeanB valueOf(String str) {

public String value() { return value; }
}

static class XY {
public int x, y;
}

// [databind#1383]
static class SingleArgWithImplicit {
protected XY _value;

private SingleArgWithImplicit() {
throw new Error("Should not get called");
}
private SingleArgWithImplicit(XY v, boolean bogus) {
_value = v;
}

@JsonCreator
public static SingleArgWithImplicit from(XY v) {
return new SingleArgWithImplicit(v, true);
}

public XY getFoobar() { return _value; }
}

/*
/**********************************************************
/* Test methods
Expand Down Expand Up @@ -147,7 +170,7 @@ public void testSingleImplicitlyNamedNotDelegating() throws Exception
StringyBeanWithProps bean = mapper.readValue("{\"value\":\"x\"}", StringyBeanWithProps.class);
assertEquals("x", bean.getValue());
}

// [databind#714]
public void testSingleExplicitlyNamedButDelegating() throws Exception
{
Expand All @@ -171,5 +194,18 @@ public void testExplicitFactory660b() throws Exception
assertNotNull(bean2);
assertEquals("def", bean2.value());
}

// [databind#1383]
public void testSingleImplicitDelegating() throws Exception
{
final ObjectMapper mapper = new ObjectMapper();
mapper.setAnnotationIntrospector(new MyParamIntrospector("value"));
SingleArgWithImplicit bean = mapper.readValue(aposToQuotes("{'x':1,'y':2}"),
SingleArgWithImplicit.class);
XY v = bean.getFoobar();
assertNotNull(v);
assertEquals(1, v.x);
assertEquals(2, v.y);
}
}

0 comments on commit bcd616d

Please sign in to comment.