Tatu | 1ae2d62 | 2014-05-15 14:13:09 -0700 | [diff] [blame] | 1 | package com.fasterxml.jackson.failing; |
| 2 | |
| 3 | import com.fasterxml.jackson.annotation.*; |
| 4 | |
| 5 | import com.fasterxml.jackson.databind.*; |
| 6 | |
| 7 | /** |
| 8 | * Unit tests for checking handling of unknown properties |
| 9 | */ |
| 10 | public class TestUnknownProperty426 extends BaseMapTest |
| 11 | { |
Tatu Saloranta | 22c483a | 2015-12-21 19:53:31 -0800 | [diff] [blame] | 12 | // For [databind#426] |
Tatu Saloranta | 1dc5190 | 2014-09-23 17:57:29 -0700 | [diff] [blame] | 13 | @JsonIgnoreProperties({ "userId" }) |
| 14 | static class User { |
Cowtowncoder | e715545 | 2014-12-12 09:20:29 -0800 | [diff] [blame] | 15 | public String firstName; |
Tatu | 1ae2d62 | 2014-05-15 14:13:09 -0700 | [diff] [blame] | 16 | Integer userId; |
| 17 | |
Tatu Saloranta | 5f8c69e | 2017-03-30 19:37:09 -0700 | [diff] [blame] | 18 | public void setUserId(CharSequence id) { |
Tatu Saloranta | 22c483a | 2015-12-21 19:53:31 -0800 | [diff] [blame] | 19 | // 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())); |
Tatu | 1ae2d62 | 2014-05-15 14:13:09 -0700 | [diff] [blame] | 22 | } |
Cowtowncoder | e715545 | 2014-12-12 09:20:29 -0800 | [diff] [blame] | 23 | |
Tatu | 1ae2d62 | 2014-05-15 14:13:09 -0700 | [diff] [blame] | 24 | public Integer getUserId() { |
| 25 | return userId; |
| 26 | } |
Cowtowncoder | e715545 | 2014-12-12 09:20:29 -0800 | [diff] [blame] | 27 | |
Tatu | 1ae2d62 | 2014-05-15 14:13:09 -0700 | [diff] [blame] | 28 | 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 | { |
Cowtowncoder | e715545 | 2014-12-12 09:20:29 -0800 | [diff] [blame] | 43 | final String JSON = aposToQuotes("{'userId': 9, 'firstName': 'Mike' }"); |
Cowtowncoder | a936f43 | 2015-05-12 12:33:46 -0700 | [diff] [blame] | 44 | User result = MAPPER.readerFor(User.class).readValue(JSON); |
Tatu | 1ae2d62 | 2014-05-15 14:13:09 -0700 | [diff] [blame] | 45 | assertNotNull(result); |
Cowtowncoder | e715545 | 2014-12-12 09:20:29 -0800 | [diff] [blame] | 46 | assertEquals("Mike", result.firstName); |
Tatu | 1ae2d62 | 2014-05-15 14:13:09 -0700 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | |