Skip to content

Commit 781457b

Browse files
committed
Added failing test for #2789
1 parent ece6210 commit 781457b

File tree

2 files changed

+88
-10
lines changed

2 files changed

+88
-10
lines changed

src/test/java/com/fasterxml/jackson/databind/ser/TestAutoDetect.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,26 @@ static class ProtMethodBean extends MethodBean { }
4242
/*********************************************************
4343
*/
4444

45+
private final ObjectMapper MAPPER = newJsonMapper();
46+
4547
public void testDefaults() throws Exception
4648
{
47-
ObjectMapper m = new ObjectMapper();
4849
// by default, only public fields and getters are detected
4950
assertEquals("{\"p1\":\"public\"}",
50-
m.writeValueAsString(new FieldBean()));
51+
MAPPER.writeValueAsString(new FieldBean()));
5152
assertEquals("{\"a\":\"a\"}",
52-
m.writeValueAsString(new MethodBean()));
53+
MAPPER.writeValueAsString(new MethodBean()));
5354
}
5455

5556
public void testProtectedViaAnnotations() throws Exception
5657
{
57-
ObjectMapper m = new ObjectMapper();
58-
59-
Map<String,Object> result = writeAndMap(m, new ProtFieldBean());
58+
Map<String,Object> result = writeAndMap(MAPPER, new ProtFieldBean());
6059
assertEquals(2, result.size());
6160
assertEquals("public", result.get("p1"));
6261
assertEquals("protected", result.get("p2"));
6362
assertNull(result.get("p3"));
6463

65-
result = writeAndMap(m, new ProtMethodBean());
64+
result = writeAndMap(MAPPER, new ProtMethodBean());
6665
assertEquals(2, result.size());
6766
assertEquals("a", result.get("a"));
6867
assertEquals("b", result.get("b"));
@@ -93,7 +92,6 @@ public void testPrivateUsingGlobals() throws Exception
9392
assertEquals("c", result.get("c"));
9493
}
9594

96-
// [JACKSON-621]
9795
public void testBasicSetup() throws Exception
9896
{
9997
ObjectMapper m = new ObjectMapper();
@@ -108,7 +106,6 @@ public void testBasicSetup() throws Exception
108106
assertEquals("private", result.get("p3"));
109107
}
110108

111-
// [JACKSON-595]
112109
public void testMapperShortcutMethods() throws Exception
113110
{
114111
ObjectMapper m = new ObjectMapper();
@@ -120,5 +117,4 @@ public void testMapperShortcutMethods() throws Exception
120117
assertEquals("protected", result.get("p2"));
121118
assertEquals("private", result.get("p3"));
122119
}
123-
124120
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.util.*;
4+
5+
import com.fasterxml.jackson.annotation.*;
6+
7+
import com.fasterxml.jackson.databind.*;
8+
9+
/**
10+
* Unit tests for checking extended auto-detect configuration,
11+
* in context of serialization
12+
*/
13+
public class TestAutoDetect2789
14+
extends BaseMapTest
15+
{
16+
// For [databind#2789]
17+
18+
@SuppressWarnings("unused")
19+
@JsonAutoDetect(
20+
getterVisibility = JsonAutoDetect.Visibility.NONE,
21+
creatorVisibility = JsonAutoDetect.Visibility.NONE,
22+
isGetterVisibility = JsonAutoDetect.Visibility.NONE,
23+
fieldVisibility = JsonAutoDetect.Visibility.NONE,
24+
setterVisibility = JsonAutoDetect.Visibility.NONE)
25+
@JsonTypeInfo(
26+
use = JsonTypeInfo.Id.NAME,
27+
include = JsonTypeInfo.As.PROPERTY,
28+
property = "type",
29+
visible = true)
30+
@JsonSubTypes({
31+
@JsonSubTypes.Type(name = "CLASS_A", value = DataClassA.class)
32+
})
33+
private static abstract class DataParent2789 {
34+
35+
@JsonProperty("type")
36+
@JsonTypeId
37+
private final DataType2789 type;
38+
39+
DataParent2789() {
40+
super();
41+
this.type = null;
42+
}
43+
44+
DataParent2789(final DataType2789 type) {
45+
super();
46+
this.type = Objects.requireNonNull(type);
47+
}
48+
49+
public DataType2789 getType() {
50+
return this.type;
51+
}
52+
}
53+
54+
private static final class DataClassA extends DataParent2789 {
55+
DataClassA() {
56+
super(DataType2789.CLASS_A);
57+
}
58+
}
59+
60+
private enum DataType2789 {
61+
CLASS_A;
62+
}
63+
64+
/*
65+
/*********************************************************
66+
/* Test methods
67+
/*********************************************************
68+
*/
69+
70+
private final ObjectMapper MAPPER = newJsonMapper();
71+
72+
// [databind#2789]
73+
74+
public void testAnnotatedFieldIssue2789() throws Exception {
75+
final DataParent2789 test = new DataClassA();
76+
77+
final String json = MAPPER.writeValueAsString(test);
78+
79+
final DataParent2789 copy = MAPPER.readValue(json, DataParent2789.class);
80+
assertEquals(DataType2789.CLASS_A, copy.getType());
81+
}
82+
}

0 commit comments

Comments
 (0)