title: Jackson - Deserialize with JsonView
body: <p>I am trying to restrict which properties from a JSON object are deserialised using Jackson JSONViews. The aim is to use this to prevent consumers of my API from submitting data that they shouldn't.</p>
  
  <p>The problem is, I have either misunderstood JSONViews or I am doing something wrong. See below.</p>
  
  <p>I started trying to do this in Spring but have noticed that even the simple test below doesn't work.</p>
  
  <p>Account Class</p>
  
  <pre><code>public class Account {
  
      @Id
      private String id;
  
      private String name;
  
      private List&lt;String&gt; items;
  
      private List&lt;User&gt; users;
  
      @JsonView(AccountViews.Private.class)
      public void setId(String id) {
          this.id = id;
      }
  
      @JsonView(AccountViews.Public.class)
      public void setName(String name) {
          this.name = name;
      }
  
      @JsonView(AccountViews.Public.class)
      public void setItems(List&lt;String&gt; items) {
          this.items = items;
      }
  
      @JsonView(AccountViews.Private.class)
      public void setUsers(List&lt;User&gt; users) {
          this.users = users;
      }
  }
  </code></pre>
  
  <p>Views</p>
  
  <pre><code>public class AccountViews {
  
      public interface Public {}
  
      public interface Private extends Public {}
  
  }
  </code></pre>
  
  <p>Test </p>
  
  <pre><code>@Test
  public void testDeserialization(){
  
          ObjectMapper mapper = new ObjectMapper();
          mapper.disable(MapperFeature.DEFAULT_VIEW_INCLUSION);
  
          Account account = mapper.readerWithView(AccountViews.Public.class).forType(Account.class).readValue("{ \"name\": \"account1\", \"items\": [\"item1\"], \"users\": [ { \"firstname\": \"user1_firstname\", \"lastname\": \"user1_lastname\" }] }");
  
          assertEquals(account.getName(), "account1");
          assertNull(account.getUsers());
  
  }
  </code></pre>
  
  <p>Unforunately, the 2nd assertion fails because Users has a user object inside.</p>
  
  <p>Basically, even though "users" is a property of Account, I don't want the value to be deserialized because I have used the JSONView (AccountViews.Public.class). However, whatever I try it always seems to be deserialized and is present on the account object.</p>
  
  <p>Any help much appreciated.</p>
  
  <p>Error</p>
  
  <pre><code>`java.lang.AssertionError: expected null, but was:&lt;[User@609db43b]&gt;
  at org.junit.Assert.fail(Assert.java:88)
  at org.junit.Assert.failNotNull(Assert.java:755)
  at org.junit.Assert.assertNull(Assert.java:737)
  at org.junit.Assert.assertNull(Assert.java:747)
  at`
  </code></pre>