I'm working on a project where they used a serializer to convert data fields:
public static class DateSerializer extends JsonSerializer<Date> {
private static final DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
@Override
public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeNumber(df.format(value));
}
}
With this, all Date fields are formatted with the same mask.
I need a specific field from one of the models to be formatted with another mask ("yyyy-MM-dd", without time).
public class DPS {
private Date dhEmi;
private Date dCompet;
...
}
Excepted result:
<DPS>
<dhEmi>2022-09-22T10:36:00-03:00</dhEmi>
<dCompet>2022-09-22</dCompet>
</DPS>
I tried using @JsonFormat on field dCompet, but the Serializer overrides the notation, and the notation is ignored.
Removing the Serializer and adding the notation to all Date fields in the project is an option, but I should consider it as a last resort due to the labor involved.
Is there a way to do this without refactoring the whole project?