jackson-databind
jackson-databind copied to clipboard
When deserializing, `JsonProperty.Access.READ_ONLY` not working in all cases
hi I can't well english. please your understand.
until 2.9.0 successful. but fail from 2.9.1. 2.9.3 will still fail Has changed spec for access option in JsonProperty? or bug? I attach test code
Test Class
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.junit.Before;
import org.junit.Test;
import java.io.IOException;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
public class DeserializeTest {
private ObjectMapper objectMapper;
@Before
public void setUp(){
this.objectMapper = new ObjectMapper();
}
@Test
public void test() throws IOException {
String json = "{\"pubtrans\":\"\",\"name\":\"changyong\"}";
TestClass result = this.objectMapper.readValue(json, TestClass.class);
// jackson 2.9.0 is success, 2.9.1~2.9.3 is fail
assertThat(result.getPubtrans(), is(nullValue()));
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class TestClass{
@JsonProperty(access = JsonProperty.Access.READ_ONLY)
private Pubtrans pubtrans;
private String name;
}
enum Pubtrans{
SUBWAY, BUS
}
}