2017-07-09 51 views
0

我用的是有一個方法的外部庫:在吸氣的Java序列化的傑克遜把手拋出異常

public class CustomUserDetails implements UserDetails { 

    private final User principal; 
    private final Collection<GrantedAuthority> authorities; 

    //constructor, getters, setters 

    @Override 
    public String getPassword() { 
     throw new UnsupportedOperationException("Not allowed"); 
    } 
} 

而且我有一個返回對象實例的@RequestMapping:

@RequestMapping(value = "/authorities", method = GET) 
    public ResponseEntity getAuthorities() { 
     return new ResponseEntity<>(authenticatedUser.getAuthentication(), HttpStatus.OK); //getAuthentication returns CustomUserDetails instance 
    } 

而我得到 org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: Not allowed

我該如何處理? Ingore或爲此屬性設置一些默認值。

UPD我不能將@JsonIngore添加到該類,因爲它不是我的庫,我無法訪問其源。

+0

@EbrahimPoursadeqi以及如何做這個崗位解決我的問題的系列化頂部JsonIgnore註解? – Daria

+1

使用Jackson mixins克服第三方限制。 –

+1

我已添加重複的鏈接。 –

回答