blob: 48a9ff240b60786c7dd2d8a0daef536739423454 [file] [log] [blame]
Tatu1ae2d622014-05-15 14:13:09 -07001package com.fasterxml.jackson.failing;
2
3import com.fasterxml.jackson.annotation.*;
4
5import com.fasterxml.jackson.databind.*;
6
7/**
8 * Unit tests for checking handling of unknown properties
9 */
10public class TestUnknownProperty426 extends BaseMapTest
11{
Tatu Saloranta22c483a2015-12-21 19:53:31 -080012 // For [databind#426]
Tatu Saloranta1dc51902014-09-23 17:57:29 -070013 @JsonIgnoreProperties({ "userId" })
14 static class User {
Cowtowncodere7155452014-12-12 09:20:29 -080015 public String firstName;
Tatu1ae2d622014-05-15 14:13:09 -070016 Integer userId;
17
Tatu Saloranta5f8c69e2017-03-30 19:37:09 -070018 public void setUserId(CharSequence id) {
Tatu Saloranta22c483a2015-12-21 19:53:31 -080019 // 21-Dec-2015, tatu: With a fix in 2.7, use of String would not
20 // trigger the problem, so use CharSequence...
21 setUserId(new Integer(id.toString()));
Tatu1ae2d622014-05-15 14:13:09 -070022 }
Cowtowncodere7155452014-12-12 09:20:29 -080023
Tatu1ae2d622014-05-15 14:13:09 -070024 public Integer getUserId() {
25 return userId;
26 }
Cowtowncodere7155452014-12-12 09:20:29 -080027
Tatu1ae2d622014-05-15 14:13:09 -070028 public void setUserId(Integer v) {
29 this.userId = v;
30 }
31 }
32
33 /*
34 /**********************************************************
35 /* Test methods
36 /**********************************************************
37 */
38
39 private final ObjectMapper MAPPER = new ObjectMapper();
40
41 public void testIssue426() throws Exception
42 {
Cowtowncodere7155452014-12-12 09:20:29 -080043 final String JSON = aposToQuotes("{'userId': 9, 'firstName': 'Mike' }");
Cowtowncodera936f432015-05-12 12:33:46 -070044 User result = MAPPER.readerFor(User.class).readValue(JSON);
Tatu1ae2d622014-05-15 14:13:09 -070045 assertNotNull(result);
Cowtowncodere7155452014-12-12 09:20:29 -080046 assertEquals("Mike", result.firstName);
Tatu1ae2d622014-05-15 14:13:09 -070047 }
48}
49