Skip to content

Commit

Permalink
Trying to make #1572 test work (fail)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 29, 2017
1 parent a2e3460 commit f70ae5d
Showing 1 changed file with 33 additions and 8 deletions.
Expand Up @@ -4,6 +4,7 @@


import com.fasterxml.jackson.databind.BaseMapTest; import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.introspect.*;


public class IgnoredCreatorProperty1572Test extends BaseMapTest public class IgnoredCreatorProperty1572Test extends BaseMapTest
{ {
Expand All @@ -15,15 +16,37 @@ static class InnerTest


static class OuterTest static class OuterTest
{ {
InnerTest inner; InnerTest innerTest;


@JsonIgnore @JsonIgnore
public String otherStr; String otherOtherStr;


@JsonCreator @JsonCreator
public OuterTest(@JsonProperty("inner") InnerTest inner, public OuterTest(/*@JsonProperty("innerTest")*/ InnerTest inner,
@JsonProperty("otherOtherStr") String otherStr) { /*@JsonProperty("otherOtherStr")*/ String otherStr) {
this.inner = inner; this.innerTest = inner;
}
}

static class ImplicitNames extends JacksonAnnotationIntrospector
{
private static final long serialVersionUID = 1L;

@Override
public String findImplicitPropertyName(AnnotatedMember member) {
if (member instanceof AnnotatedParameter) {
// A placeholder for legitimate property name detection
// such as what the JDK8 module provides
AnnotatedParameter param = (AnnotatedParameter) member;
switch (param.getIndex()) {
case 0:
return "innerTest";
case 1:
return "otherOtherStr";
default:
}
}
return null;
} }
} }


Expand All @@ -33,16 +56,18 @@ public OuterTest(@JsonProperty("inner") InnerTest inner,
/******************************************************** /********************************************************
*/ */


private final ObjectMapper MAPPER = new ObjectMapper();

// [databind#1572] // [databind#1572]
public void testIgnoredCtorParam() throws Exception public void testIgnoredCtorParam() throws Exception
{ {
final ObjectMapper mapper = new ObjectMapper();
mapper.setAnnotationIntrospector(new ImplicitNames());
String JSON = aposToQuotes("{'innerTest': {\n" String JSON = aposToQuotes("{'innerTest': {\n"
+"'str':'str',\n" +"'str':'str',\n"
+"'otherStr': 'otherStr'\n" +"'otherStr': 'otherStr'\n"
+"}}\n"); +"}}\n");
OuterTest result = MAPPER.readValue(JSON, OuterTest.class); OuterTest result = mapper.readValue(JSON, OuterTest.class);
assertNotNull(result); assertNotNull(result);
assertNotNull(result.innerTest);
assertEquals("otherStr", result.innerTest.otherStr);
} }
} }

0 comments on commit f70ae5d

Please sign in to comment.