I have objects of Date and Timestamp in a class. I want to serialize Timestamp as YYYY-MM-dd HH:mm:ss and let Date serialize as YYYY-MM-dd
Gson gson = new GsonBuilder().setDateFormat("YYYY-MM-dd HH:mm:ss").create();
String jsonStr = gson.toJson(experimentItems);
This code will get me two YYYY-MM-dd HH:mm:ss formats.
Use JsonAdapter Annotation!
class Person {
@JsonAdapter(DateAdapter.class)
private Date birthday;
@JsonAdapter(TimestampAdapter.class)
private TimeStamp birthdayAndTime;
}