Skip to content

Commit c73b072

Browse files
committed
Add a (failing) test for #935
1 parent 6aee8e0 commit c73b072

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

src/test/java/com/fasterxml/jackson/databind/deser/TestBasicAnnotations.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static class BeanSubClass extends BaseBean
8787
static class BeanWithDeserialize {
8888
@JsonDeserialize protected int a;
8989
}
90-
90+
9191
/*
9292
/**********************************************************
9393
/* Other helper classes
@@ -162,7 +162,7 @@ public void testImpliedProperty() throws Exception
162162
assertEquals(3, bean.a);
163163
}
164164

165-
// [Issue#442]
165+
// [databind#442]
166166
public void testIssue442PrivateUnwrapped() throws Exception
167167
{
168168
Issue442Bean bean = MAPPER.readValue("{\"i\":5}", Issue442Bean.class);
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.fasterxml.jackson.databind.*;
5+
6+
public class ReadWriteOnlyProp935Test extends BaseMapTest
7+
{
8+
// for [databind#935], verify read/write-only cases
9+
static class ReadXWriteY {
10+
@JsonProperty(access=JsonProperty.Access.READ_ONLY)
11+
public int x = 1;
12+
13+
@JsonProperty(access=JsonProperty.Access.WRITE_ONLY)
14+
public int y = 2;
15+
16+
public void setX(int x) {
17+
throw new Error("Should NOT set x");
18+
}
19+
20+
public int getY() {
21+
throw new Error("Should NOT get y");
22+
}
23+
}
24+
25+
public static class Pojo935
26+
{
27+
private String firstName = "Foo";
28+
private String lastName = "Bar";
29+
30+
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
31+
public String getFullName() {
32+
return firstName + " " + lastName;
33+
}
34+
35+
public String getFirstName() {
36+
return firstName;
37+
}
38+
39+
public void setFirstName(String n) {
40+
firstName = n;
41+
}
42+
43+
public String getLastName() {
44+
return lastName;
45+
}
46+
47+
public void setLastName(String n) {
48+
lastName = n;
49+
}
50+
}
51+
52+
/*
53+
/**********************************************************
54+
/* Test methods
55+
/**********************************************************
56+
*/
57+
58+
private final ObjectMapper MAPPER = new ObjectMapper();
59+
60+
// [databind#935]
61+
public void testReadOnlyAndWriteOnly() throws Exception
62+
{
63+
String json = MAPPER.writeValueAsString(new ReadXWriteY());
64+
assertEquals("{\"x\":1}", json);
65+
66+
ReadXWriteY result = MAPPER.readValue("{\"x\":5, \"y\":6}", ReadXWriteY.class);
67+
assertNotNull(result);
68+
assertEquals(0, result.x);
69+
assertEquals(6, result.y);
70+
}
71+
72+
public void testReadOnl935() throws Exception
73+
{
74+
String json = MAPPER.writeValueAsString(new Pojo935());
75+
Pojo935 result = MAPPER.readValue(json, Pojo935.class);
76+
assertNotNull(result);
77+
}
78+
}

0 commit comments

Comments
 (0)