sti*_*vlo 16 java spring json spring-mvc jackson
我正在使用MappingJacksonJsonView将类序列化为JSON,但是,我希望能够根据getter名称重命名默认名称中的某些字段.
这是因为我要为jQuery文件上传输出"delete_url"和"delete_type"等字段名称.我正在使用@Jsonserialize注释来手动选择要序列化的字段.
@JsonAutoDetect(getterVisibility = Visibility.NONE)
public interface Picture {
@JsonSerialize
String getName();
@JsonSerialize
String getDelete_url();
...
Run Code Online (Sandbox Code Playgroud)
例如,我被迫调用一个方法getDelete_url()
,而我想调用它getDeleteUrl()
,但"delete_url"
在序列化为JSON时仍然输出密钥.
nic*_*ild 30
你应该能够使用资格@JsonProperty
.
@JsonAutoDetect(getterVisibility = Visibility.NONE)
public interface Picture {
@JsonSerialize
@JsonProperty("name")
String getName();
@JsonSerialize
@JsonProperty("delete_url")
String getDeleteUrl();
//...
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
19033 次 |
最近记录: |