Quantcast
Channel: Programação - GUJ
Viewing all articles
Browse latest Browse all 33093

Serialização LocalDateTime

$
0
0

@cido18 escreveu:

Olá a todos,

Estou tentando serializar um objeto que possui uma data com a classe LocalDateTime utilizando o Spring Boot, mas o seguinte erro:


2016-10-09 18:28:26.218 WARN 17395 --- [ XNIO-2 task-2] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Text '2016-10-09T13:00:00.000Z' could not be parsed at index 2 (through reference chain: br.com.wt.agendadoador.modelo.Agenda["date"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Text '2016-10-09T13:00:00.000Z' could not be parsed at index 2 (through reference chain: br.com.wt.agendadoador.modelo.Agenda["date"])

Fiz algumas pesquisas mas não consegui encontrar o motivo...

Trecho da classe:

@Entity
public class Agenda {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="doador_id")
@JsonProperty
private Doador doador;
@Enumerated(EnumType.STRING)
private StatusAgenda statusAgenda;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name="laboratorio_id")
@JsonProperty
private Laboratorio laboratorio;
@JsonFormat(pattern = "dd-MM-yyyy HH:mm:ss")
@DateTimeFormat(iso = DateTimeFormat.ISO.TIME)
private LocalDateTime date;

Minha configuração no application.properties e Jackson-datetype-jrs310:

spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS =false
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>

Por fim o Controller
`
@RestController
@RequestMapping(value = "agenda")
public class AgendaController {

@Autowired
private AgendaRepository agendaRepository;

@RequestMapping(value = "/", method = RequestMethod.POST,headers="Accept=application/json", produces = "application/json")
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
public ResponseEntity<Void> add(@Valid @RequestBody Agenda agenda) {
	HttpHeaders headers = new HttpHeaders();
	try {
		agenda.setStatusAgenda(StatusAgenda.EMABERTO);
		agendaRepository.save(agenda);
		return new ResponseEntity<Void>(headers, HttpStatus.OK);
	} catch (RuntimeErrorException e) {
		System.out.println(e.getMessage());
		return new ResponseEntity<Void>(headers, HttpStatus.NOT_ACCEPTABLE);
	}

}`

Obrigado

Mensagens: 2

Participantes: 2

Ler tópico completo


Viewing all articles
Browse latest Browse all 33093


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>