2013-12-11 22 views
2

我試圖避免使用spring-data-rest在JSON響應的內容中顯示幾個字段。註解@RestResource(exported = false)不適用於實體類中的屬性。這可能是一個類似的問題,到那個在報告:Property reference mapping in Spring Data Rest 2.0.0Spring Data Rest 2.0.0 - @RestResource(exported = false)不適用於屬性

在我的情況我有以下兩種屬性:

@RestResource(exported = false) 
private byte[] image; 
@RestResource(exported = false) 
private Date updateTime; 

註釋不工作。我也嘗試沒有成功的另一個方法:

@Override 
protected void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {  
config.setResourceMappingForDomainType(MyClass.class) 
       .addResourceMappingFor("updateTime") 
       .setExported(false); 
} 

在彈簧數據休息當前代碼展望github上讓我覺得,任何元數據(註釋)設置爲JSON對象是從未使用過的內容。感謝您對此問題的幫助。也許在當前的2.0.0版本中有不同的方式來做到這一點?

+0

嘗試同時使用'@ RestResource'和'@ JsonIgnore'。它爲我工作。 – ElderMael

回答

0

如果您正在使用latests快照以下應該工作

@JsonIgnore 
private byte[] image; 

@JsonIgnore 
private Date updateTime; 

順便說一句,@RestResource是一個類和方法的註釋,並告訴SDR,如果你想通過SDR

公開這些類或方法

用於控制域對象序列化使用傑克遜註釋@JsonIgnore

0

它應該在下一個版本中修復,因爲此issue report說。

相關問題