Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.0.0
-
Fix Version/s: 2.0.2
-
Component/s: Deserializer
-
Labels:None
-
Number of attachments :
Description
I tried the following example with views:
public class RView {} public class XView {} public class SimpleClass { @JsonView(XView.class) public int num = 1; @JsonView(RView.class) public String str = "string"; }
When I read a new SimpleClass with view, the behavior is as I expected:
ObjectMapper mapper = new ObjectMapper(); SimpleClass simple = mapper.reader(SimpleClass.class).withView(RView.class).readValue("{\"num\": 10, \"str\":\"test\"}"); System.out.println("num: " + simple.num + ", str: " + simple.str);
Output:
num: 1, str: test
The 'num' attribute is ignored because it doesn't belong to the view RView - as expected.
Now, when I try to do the same, but using existing instance instead of creating a new one:
SimpleClass simple2 = new SimpleClass(); simple2.num = 100; simple2.str = "test string"; mapper.readerForUpdating(simple2).withView(RView.class).readValue("{\"num\": 10, \"str\":\"test\"}"); System.out.println("num: " + simple2.num + ", str: " + simple2.str);
Output:
num: 100, str: test string
I expected that "str" property is read into simple2 since it belongs to the "RView" view, but it seems no properties are read at all.
P.S. when looking at the source code, I saw that there's a START_OBJECT token that is skipped for "regular" deserialization, but not for "updating object with view" deserialization.
Fixed: the problem was indeed due to START_OBJECT not being skipped in relevant place; added unit tests, now passes.