/
IgnoredCreatorProperty1572Test.java
73 lines (63 loc) · 2.18 KB
/
IgnoredCreatorProperty1572Test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.fasterxml.jackson.failing;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.introspect.*;
public class IgnoredCreatorProperty1572Test extends BaseMapTest
{
static class InnerTest
{
public String str;
public String otherStr;
}
static class OuterTest
{
InnerTest innerTest;
@JsonIgnore
String otherOtherStr;
@JsonCreator
public OuterTest(/*@JsonProperty("innerTest")*/ InnerTest inner,
/*@JsonProperty("otherOtherStr")*/ String otherStr) {
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;
}
}
/*
/********************************************************
/* Test methods
/********************************************************
*/
// [databind#1572]
public void testIgnoredCtorParam() throws Exception
{
final ObjectMapper mapper = new ObjectMapper();
mapper.setAnnotationIntrospector(new ImplicitNames());
String JSON = aposToQuotes("{'innerTest': {\n"
+"'str':'str',\n"
+"'otherStr': 'otherStr'\n"
+"}}\n");
OuterTest result = mapper.readValue(JSON, OuterTest.class);
assertNotNull(result);
assertNotNull(result.innerTest);
assertEquals("otherStr", result.innerTest.otherStr);
}
}