I would like serialize an object such that one of the fields will be named differently based on the type of the field. For example:
public class Response {
my own solution.
@Data
@EqualsAndHashCode
@ToString
@JsonSerialize(using = ElementsListBean.CustomSerializer.class)
public class ElementsListBean {
public ElementsListBean()
{
}
public ElementsListBean(final String fieldName, final List elements)
{
this.fieldName = fieldName;
this.elements = elements;
}
private String fieldName;
private List elements;
public int length()
{
return (this.elements != null) ? this.elements.size() : 0;
}
private static class CustomSerializer extends JsonSerializer