Skip to content

Commit

Permalink
Add a (failing) test for #935
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Sep 16, 2015
1 parent 6aee8e0 commit c73b072
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static class BeanSubClass extends BaseBean
static class BeanWithDeserialize {
@JsonDeserialize protected int a;
}

/*
/**********************************************************
/* Other helper classes
Expand Down Expand Up @@ -162,7 +162,7 @@ public void testImpliedProperty() throws Exception
assertEquals(3, bean.a);
}

// [Issue#442]
// [databind#442]
public void testIssue442PrivateUnwrapped() throws Exception
{
Issue442Bean bean = MAPPER.readValue("{\"i\":5}", Issue442Bean.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.fasterxml.jackson.failing;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.*;

public class ReadWriteOnlyProp935Test extends BaseMapTest
{
// for [databind#935], verify read/write-only cases
static class ReadXWriteY {
@JsonProperty(access=JsonProperty.Access.READ_ONLY)
public int x = 1;

@JsonProperty(access=JsonProperty.Access.WRITE_ONLY)
public int y = 2;

public void setX(int x) {
throw new Error("Should NOT set x");
}

public int getY() {
throw new Error("Should NOT get y");
}
}

public static class Pojo935
{
private String firstName = "Foo";
private String lastName = "Bar";

@JsonProperty(access = JsonProperty.Access.READ_ONLY)
public String getFullName() {
return firstName + " " + lastName;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String n) {
firstName = n;
}

public String getLastName() {
return lastName;
}

public void setLastName(String n) {
lastName = n;
}
}

/*
/**********************************************************
/* Test methods
/**********************************************************
*/

private final ObjectMapper MAPPER = new ObjectMapper();

// [databind#935]
public void testReadOnlyAndWriteOnly() throws Exception
{
String json = MAPPER.writeValueAsString(new ReadXWriteY());
assertEquals("{\"x\":1}", json);

ReadXWriteY result = MAPPER.readValue("{\"x\":5, \"y\":6}", ReadXWriteY.class);
assertNotNull(result);
assertEquals(0, result.x);
assertEquals(6, result.y);
}

public void testReadOnl935() throws Exception
{
String json = MAPPER.writeValueAsString(new Pojo935());
Pojo935 result = MAPPER.readValue(json, Pojo935.class);
assertNotNull(result);
}
}

0 comments on commit c73b072

Please sign in to comment.