A lot is writed implemented but again and again i can not splve my problem for more then 4 days. i have to Serialize an data time to json. Even that a lot is shown but none of them helped my to solve my problem.
I need to have a special format as shown on the follow code.
I got the follwoing solution from this link GSON - Date format
Item item = new Item(); // a Java class that some getter/setter methods.
JsonSerializer<Date> ser = new JsonSerializer<Date>() {
@Override
public JsonElement serialize(Date src, Type typeOfSrc,
JsonSerializationContext context) {
// TODO Auto-generated method stub
//return src == null ? null : new JsonPrimitive(src.getDate());
String format = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
return new JsonPrimitive(format);
}
};
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, ser).create();
Log.d("new Gson().toJson(item)", gson.toJson(item));
// I need this to send data to Server
dataOut.writeBytes(gson.toJson(item));
dataOut.flush();
dataOut.close();
I need to have a time format as follows. yyyy-MM-dd'T'HH:mm:ss.SSSZ. not as string but from my own serializer.