I am answering my own question. It was almost solved by adding this:
JsonbConfig config = new JsonbConfig();
config.setProperty(JsonbConfig.DATE_FORMAT, JsonbDateFormat.TIME_IN_MILLIS);
Jsonb jsonB = JsonbBuilder.create(config);
and writing the response like this:
return Response.ok(jsonB.toJson(object)).build();
But as the objects can have also Date fields in addition to the Timestamps they are now both written as integers and now the clients dont like Date fields as they are expecting something like "2023-05-05".
For example:
public class HaePaivajarjestysPaluuDto extends SaliDtoAC implements Serializable {
private String tekninenavain;
private Date istuntopvm;
private Timestamp ilmoitettualkuaika;
gives:
"haePaivajarjestysPaluuDto": {
"tekninenavain": "2023/131",
"ilmoitettualkuaika": 1683270000000,
"istuntopvm": 1683234000000,