title: Exclude fields in json Using Jackson and Json-View
body: <p>I am using <a href="https://github.com/monitorjbl/json-view" rel="noreferrer">json-view</a> to create a dynamic json as per my need ,it is a great library ,I am using this library for a while now .
  Recently I am facing a problem with my one of the Use cases, let me place my code first</p>
  
  <h1>User class</h1>
  
  <pre><code>public class User {
  
      private String name;
      private String emailId;
      private String mobileNo;
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getEmailId() {
          return emailId;
      }
  
      public void setEmailId(String emailId) {
          this.emailId = emailId;
      }
  
      public String getMobileNo() {
          return mobileNo;
      }
  
      public void setMobileNo(String mobileNo) {
          this.mobileNo = mobileNo;
      }
  
  }
  </code></pre>
  
  <h1>ScreenInfoPojo class</h1>
  
  <pre><code>public class ScreenInfoPojo {
  
      private Long id;
      private String name;
      private ScreenInfoPojo parentScreen;
      private User createdBy;
      private User lastUpdatedBy;
  
      public Long getId() {
          return id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public ScreenInfoPojo getParentScreen() {
          return parentScreen;
      }
  
      public void setParentScreen(ScreenInfoPojo parentScreen) {
          this.parentScreen = parentScreen;
      }
  
  
  
      public User getCreatedBy() {
          return createdBy;
      }
  
      public void setCreatedBy(User createdBy) {
          this.createdBy = createdBy;
      }
  
      public User getLastUpdatedBy() {
          return lastUpdatedBy;
      }
  
      public void setLastUpdatedBy(User lastUpdatedBy) {
          this.lastUpdatedBy = lastUpdatedBy;
      } 
  </code></pre>
  
  <h1>Run code</h1>
  
  <pre><code>public class TestMain {
      public static void main(String[] args) throws JsonProcessingException {
          User user=new User();
          user.setName("ABC");
          user.setEmailId("dev@abc123.com");
          user.setMobileNo("123456789");
  
          ScreenInfoPojo screen1=new ScreenInfoPojo();
          screen1.setId(1l);
          screen1.setName("Screen1");
          screen1.setCreatedBy(user);
          screen1.setLastUpdatedBy(user);
  
          ScreenInfoPojo screen2=new ScreenInfoPojo();
          screen2.setId(2l);
          screen2.setName("Screen2");
          screen2.setParentScreen(Screen1);
          screen2.setCreatedBy(user);
          screen2.setLastUpdatedBy(user);
  
          ScreenInfoPojo screen3=new ScreenInfoPojo();
          screen3.setId(3l);
          screen3.setName("Screen3");
          screen3.setParentScreen(Screen2);
          screen3.setCreatedBy(user);
          screen3.setLastUpdatedBy(user);
  
          ScreenInfoPojo screen4=new ScreenInfoPojo();
          screen4.setId(4l);
          screen4.setName("Screen4");
          screen4.setParentScreen(Screen3);
          screen4.setCreatedBy(user);
          screen4.setLastUpdatedBy(user);
  
          List&lt;ScreenInfoPojo&gt; screens=new ArrayList&lt;&gt;();
          screens.add(screen1);
          screens.add(screen2);
          screens.add(screen3);
          screens.add(screen4);
  
          ObjectMapper mapper = new ObjectMapper().registerModule(new JsonViewModule());
          String json = mapper.writeValueAsString(JsonView.with(screens).onClass(ScreenInfoPojo.class, Match.match()
                  .exclude("*")
                  .include("id","name","createdBy.name","lastUpdatedBy.mobileNo","parentScreen.id")));
          System.out.println("json"+json);
      }    
  </code></pre>
  
  <h1>Result</h1>
  
  <pre><code>[{
      "id": 1,
      "name": "Screen1",
      "parentScreen": null,
      "createdBy": {
          "name": "ABC"
      },
      "lastUpdatedBy": {
          "mobileNo": "123456789"
      }
  }, {
      "id": 2,
      "name": "Screen2",
      "parentScreen": {
          "id": 1,
          "name": "Screen1",
          "parentScreen": null,
          "createdBy": {},
          "lastUpdatedBy": {}
      },
      "createdBy": {
          "name": "ABC"
      },
      "lastUpdatedBy": {
          "mobileNo": "123456789"
      }
  }, {
      "id": 3,
      "name": "Screen3",
      "parentScreen": {
          "id": 2,
          "name": "Screen2",
          "parentScreen": {
              "id": 1,
              "name": "Screen1",
              "parentScreen": null,
              "createdBy": {},
              "lastUpdatedBy": {}
          },
          "createdBy": {},
          "lastUpdatedBy": {}
      },
      "createdBy": {
          "name": "ABC"
      },
      "lastUpdatedBy": {
          "mobileNo": "123456789"
      }
  }, {
      "id": 4,
      "name": "Screen4",
      "parentScreen": {
          "id": 3,
          "name": "Screen3",
          "parentScreen": {
              "id": 2,
              "name": "Screen2",
              "parentScreen": {
                  "id": 1,
                  "name": "Screen1",
                  "parentScreen": null,
                  "createdBy": {},
                  "lastUpdatedBy": {}
              },
              "createdBy": {},
              "lastUpdatedBy": {}
          },
          "createdBy": {},
          "lastUpdatedBy": {}
      },
      "createdBy": {
          "name": "ABC"
      },
      "lastUpdatedBy": {
          "mobileNo": "123456789"
      }
  }]
  </code></pre>
  
  <h1>Expected Result</h1>
  
  <pre><code>[{
      "id": 1,
      "name": "Screen1",
      "parentScreen": null,
      "createdBy": {
          "name": "ABC"
      },
      "lastUpdatedBy": {
          "mobileNo": "123456789"
      }
  }, {
      "id": 2,
      "name": "Screen2",
      "parentScreen": {
          "id": 1
      },
      "createdBy": {
          "name": "ABC"
      },
      "lastUpdatedBy": {
          "mobileNo": "123456789"
      }
  }, {
      "id": 3,
      "name": "Screen3",
      "parentScreen": {
          "id": 2
      },
      "createdBy": {
          "name": "ABC"
      },
      "lastUpdatedBy": {
          "mobileNo": "123456789"
      }
  }, {
      "id": 4,
      "name": "Screen4",
      "parentScreen": {
          "id": 3
      },
      "createdBy": {
          "name": "ABC"
      },
      "lastUpdatedBy": {
          "mobileNo": "123456789"
      }
  }]
  </code></pre>
  
  <h1>Problem</h1>
  
  <p>In my use case I have a class <strong>ScreenInfoPojo</strong> which refers to same class as <strong>parentScreen</strong> ,
  I am trying to fetch specific field/fields of parent ( <strong>"parentScreen.id"</strong>) instate I am getting all fields that I have defined on child/target Object (<strong>"id","name","createdBy.name","lastUpdatedBy.mobileNo","parentScreen.id"</strong>) and parent response is again recursive ! One thing i observed that It is only happening in case of a class has its own reference , I placed <strong>User</strong> class reference as two different field <strong>createdBy</strong> and <strong>lastUpdatedBy</strong> and tried to fetch <strong>"name"</strong> and <strong>"mobileNo"</strong> respectively worked just fine.</p>
  
  <p>Any suggestion to solve this problem will be really helpful !!!!</p>
  
  <p>Thanks</p>