I have the following code with Jackson:
public class Header implements Serializable {
@JsonProperty("numeroUnico")
private Integer numeroCliente;
@JsonProperty("oficina")
private Integer oficina;
@JsonProperty("fecha")
@JsonSerialize(using = CustomDateSerializer.class)
private Date fechaInscripcion;
}
this is my class "CustomDateSerializer.class"
public class CustomDateSerializer extends StdSerializer<Date> {
private SimpleDateFormat formatter
= new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
public CustomDateSerializer() {
this(null);
}
public CustomDateSerializer(Class t) {
super(t);
}
@Override
public void serialize (Date value, JsonGenerator gen, SerializerProvider arg2)
throws IOException, JsonProcessingException {
gen.writeString(formatter.format(value));
}
}
They asked me to migrate all the implementations of Jackson to Gson. Taking into account that the notation in Jackson @JsonProperty has an equivalence in Gson that is @SerializedName. But for the notation in Jackson of:
@JsonSerialize (using = CustomDateSerializer.class)
What is its equivalent for Gson? if not, as it should be the implementation for attributes of type Date in my DTO.