Code example for GsonBuilder

Methods: createsetDateFormat

0
    	if (appointmentsJson == null) {
    		return new Appointment[]{}; 
    	} 
         
    	// Serialize the JSON string into appointment objects 
    	GsonBuilder builder = new GsonBuilder();
    	builder.setDateFormat(APPOINTMENT_DATE_FORMAT);
    	Gson gson = builder.create(); 
    	Appointment[] appointments = gson.fromJson(appointmentsJson, Appointment[].class);
    	 
    	return appointments;
    } 
	 
	public void saveBookedAppointments(Appointment[] appointments) {
		// Android SDK doesn't know how to serialize objects, so we convert them to JSON 
    	GsonBuilder builder = new GsonBuilder();
    	builder.setDateFormat(APPOINTMENT_DATE_FORMAT);
    	Gson gson = builder.create(); 
    	String appointmentsJson = gson.toJson(appointments);
         
Contextual code suggestions in your IDE  Get Codota for Java