I'm using MappingJacksonJsonView to serialize to JSON a class, however, I'd like to be able to rename some of the fields from the default name based on the getter name.
This is because I've to output field names like "delete_url" and "delete_type" for jQuery file upload. I'm using @Jsonserialize annotation to hand pick the fields to serialize.
@JsonAutoDetect(getterVisibility = Visibility.NONE)
public interface Picture {
@JsonSerialize
String getName();
@JsonSerialize
String getDelete_url();
...
For instance, I'm forced to call a method getDelete_url()
, while I'd like to call it getDeleteUrl()
, but still output the key "delete_url"
when serializing to JSON.
You should be able to qualify using @JsonProperty
.
@JsonAutoDetect(getterVisibility = Visibility.NONE)
public interface Picture {
@JsonSerialize
@JsonProperty("name")
String getName();
@JsonSerialize
@JsonProperty("delete_url")
String getDeleteUrl();
//...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With