title: Java Jackson serialization handle on getter throws exception
body: <p>I use an <strong>external</strong> library that has a method:</p>
  
  <pre><code>public class CustomUserDetails implements UserDetails {
  
      private final User principal;
      private final Collection&lt;GrantedAuthority&gt; authorities;
  
      //constructor, getters, setters
  
      @Override
      public String getPassword() {
          throw new UnsupportedOperationException("Not allowed");
      }
  }
  </code></pre>
  
  <p>And I have a @RequestMapping that returns an instance of that object:</p>
  
  <pre><code>@RequestMapping(value = "/authorities", method = GET)
      public ResponseEntity getAuthorities() {
          return new ResponseEntity&lt;&gt;(authenticatedUser.getAuthentication(), HttpStatus.OK); //getAuthentication returns CustomUserDetails instance
      }
  </code></pre>
  
  <p>And I'm getting 
  <code>org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: Not allowed</code>.</p>
  
  <p>How can I handle this? Ingore or set some default value to this property.</p>
  
  <p><strong>UPD</strong> I cannot add @JsonIngore to that class because it's not my library, I don't have access to its source.</p>