Android REST POST loses Date value

Viewed 743

I have an Android App (Spring Android + Android Annotations + Gson) that consume REST services from a Web App (Jersey + Spring + Hibernate / JPA). The problem is that my java.util.Date properties are not serialized:

Activity (Android App):

...
@Click(R.id.buttonLogin)
void onLoginClick() {
    Student student = new Student();
    student.setDateRegistration(new Date()); //Property where the problem occurs
    student.setFirstName("Venilton");
    student.setGender(Gender.M);

    doSomethingInBackground(student);
}

@Background
void doSomethingInBackground(Student student) {
    this.restClient.insert(student);
}
...

Rest Client (Android App):

@Rest(rootUrl = "http://MY_IP:8080/restful-app", 
    converters = { GsonHttpMessageConverter.class })
public interface StudentRESTfulClient {

    @Post("/student/insert")
    Student insert(Student student);
}

Rest Server (Web App):

@Component
@Path("/student")
public class StudentRESTfulServer {

    @Autowired
    private StudentService studentServiceJpa;

    @POST 
    @Path("/insert")
    public Student insert(Student student) {
        //student.getDateRegistration() is null! It's a problem!

        Student studentResponse = null;
        try {
                this.studentServiceJpa.insert(student);
                studentResponse = student;
        } catch (Exception exception) { }

        return studentResponse;
    }
}

The Android application performs the POST the Student object for REST service, but the DateRegistration property loses its value when the student object arrives in StudentRESTfulServer.

Could you help me?

1 Answers
Related