خرید بک لینک

Vote count: 0

My ObjectMapper bad to convert date. In year and month are errors. For example:

{"idtests":null,"title":"sda","date":"3916-06-29T09:27:48"}

I send: example

My code:

@FXML
private void AddTestAction(){
    if(!title.getText().isEmpty() && date.getValue() != null && minutes.getValue() != null && hours.getValue() != null){
            ObjectMapper mapper = new ObjectMapper();
            Tests obj = new Tests();
            String json = null;

            obj.setTitle(title.getText());
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            df.setTimeZone(TimeZone.getTimeZone("CET"));         

            Date t = new Date();
            t.setMinutes(Integer.parseInt(minutes.getValue().toString()));
            t.setHours(Integer.parseInt(hours.getValue().toString()));
            t.setYear(Integer.parseInt(date.getValue().toString().substring(0,4)));
            t.setMonth(Integer.parseInt(date.getValue().toString().substring(5,7)));
            t.setDate(Integer.parseInt(date.getValue().toString().substring(8,10)));           
            obj.setDate(t);                   

            try {
                mapper.setDateFormat(df); 
                mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
                json = mapper.writeValueAsString(obj);
            } catch (JsonProcessingException ex) {
                Logger.getLogger(adminController.class.getName()).log(Level.SEVERE, null, ex);
            }
            System.out.print(json);
            if(sendMessages("http://localhost:8080/Server/source/tests/", json)){
                info.setText("Test został dodany");
            }else{
                info.setText("Błąd połączenia");
            }

    }else{
        info.setText("Wprowadź identyfikator");
    }
}

All submitted data are correct. It seems to me error must be in configuration ObjectMapper but where? I can to subtract 1900 between a year and subtract 1 month, but it is too simple.

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 10 خرداد 1395 ساعت: 2:58

صفحه بندی