I’m trying to have a custom date format in Gson output, but .setDateFormat(DateFormat.FULL)
doesn’t seem to work and it the same with .registerTypeAdapter(Date.class, new DateSerializer())
.
It’s like Gson doesn’t care about the object “Date” and print it in its way.
How can I change that?
Thanks
EDIT:
@Entity
public class AdviceSheet {
public Date lastModif;
[...]
}
public void method {
Gson gson = new GsonBuilder().setDateFormat(DateFormat.LONG).create();
System.out.println(gson.toJson(adviceSheet);
}
I always use java.util.Date
; setDateFormat()
doesn’t work 🙁