0

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.

Community
  • 1
  • 1
student
  • 1
  • 3
  • can you explain what you need in english? it's quicker for people instead of reading all your code first. – Maurizio In denmark Jul 24 '13 at 11:16
  • @ Maurizio In denmark sorry for my bad english. I am trying for a few days to solve my problem unsuccessfully. 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 as said above. – student Jul 24 '13 at 11:19

0 Answers0