Skip to content

Commit 8e0dc29

Browse files
committed
Add failing tests for #2283, #2675
1 parent 3e5efd0 commit 8e0dc29

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

src/main/java/com/fasterxml/jackson/databind/ser/std/StdJdkSerializers.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static Collection<Map.Entry<Class<?>, Object>> all()
6060
} catch (NoClassDefFoundError e) {
6161
// nothing much we can do here; could log, but probably not useful for now.
6262
}
63-
63+
6464
return sers.entrySet();
6565
}
6666

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import java.util.*;
4+
5+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
6+
import com.fasterxml.jackson.annotation.JsonProperty;
7+
import com.fasterxml.jackson.databind.*;
8+
9+
// [databind#2283]: ignore read-only Lists even if "getter-as-setter" enabled
10+
public class ReadOnlyList2283Test
11+
extends BaseMapTest
12+
{
13+
static class RenamedToSameOnGetter {
14+
@JsonProperty(value = "list", access = JsonProperty.Access.READ_ONLY)
15+
List<Long> getList() {
16+
return Collections.emptyList();
17+
}
18+
}
19+
20+
static class RenamedToDifferentOnGetter {
21+
@JsonProperty(value = "renamedList", access = JsonProperty.Access.READ_ONLY)
22+
List<Long> getList() {
23+
return Collections.emptyList();
24+
}
25+
}
26+
27+
@JsonIgnoreProperties(value={ "renamedList" }, allowGetters=true)
28+
static class RenamedOnClass {
29+
@JsonProperty("renamedList")
30+
List<Long> getList() {
31+
return Collections.emptyList();
32+
}
33+
}
34+
35+
/*
36+
/**********************************************************
37+
/* Test methods
38+
/**********************************************************
39+
*/
40+
41+
private final ObjectMapper MAPPER = jsonMapperBuilder()
42+
.configure(MapperFeature.USE_GETTERS_AS_SETTERS, true).build();
43+
44+
public void testRenamedToSameOnGetter() throws Exception
45+
{
46+
assertEquals("{\"list\":[]}",
47+
MAPPER.writeValueAsString(new RenamedToSameOnGetter()));
48+
String payload = "{\"list\":[1,2,3,4]}";
49+
RenamedToSameOnGetter foo = MAPPER.readValue(payload, RenamedToSameOnGetter.class);
50+
assertTrue("List should be empty", foo.getList().isEmpty());
51+
}
52+
53+
public void testRenamedToDifferentOnGetter() throws Exception
54+
{
55+
assertEquals("{\"renamedList\":[]}",
56+
MAPPER.writeValueAsString(new RenamedToDifferentOnGetter()));
57+
String payload = "{\"renamedList\":[1,2,3,4]}";
58+
RenamedToDifferentOnGetter foo = MAPPER.readValue(payload, RenamedToDifferentOnGetter.class);
59+
assertTrue("List should be empty", foo.getList().isEmpty());
60+
}
61+
62+
public void testRenamedOnClass() throws Exception
63+
{
64+
assertEquals("{\"renamedList\":[]}",
65+
MAPPER.writeValueAsString(new RenamedOnClass()));
66+
String payload = "{\"renamedList\":[1,2,3,4]}";
67+
RenamedOnClass foo = MAPPER.readValue(payload, RenamedOnClass.class);
68+
assertTrue("List should be empty", foo.getList().isEmpty());
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import com.fasterxml.jackson.databind.*;
4+
5+
public class VoidProperties2675Test extends BaseMapTest
6+
{
7+
static class VoidBean {
8+
public Void getValue() { return null; }
9+
}
10+
11+
/*
12+
/**********************************************************************
13+
/* Test methods
14+
/**********************************************************************
15+
*/
16+
17+
private final ObjectMapper MAPPER = new ObjectMapper();
18+
19+
public void testVoidBean() throws Exception {
20+
final String EXP = "{\"value\":null}";
21+
assertEquals(EXP, MAPPER.writeValueAsString(new VoidBean()));
22+
VoidBean result = MAPPER.readValue(EXP, VoidBean.class);
23+
assertNotNull(result);
24+
}
25+
}

0 commit comments

Comments
 (0)