У меня есть запрос GET < /p>
Код: Выделить всё
import static com.toedter.spring.hateoas.jsonapi.MediaTypes.JSON_API_VALUE;
import org.springframework.hateoas.EntityModel;
import java.time.LocalDateTime;
@GetMapping("/getMovie",produces = JSON_API_VALUE)
public Movie getMovie(){
LocalDateTime localDateTime=LocalDateTime.now();
return new Movie(1,"Avengers",localDateTime);
}
< /code>
и класс фильма имеет < /p>
< /blockquote>
Public class Movie{
private Integer id;
private String name;
private LocalDateTime availableTime;
//Getters setters and Constructor
}
}
< /code>
Я добавил следующую конфигурацию для объекта Mapper < /p>
@Bean
@Primary
fun objectMapper(): ObjectMapper =
JsonMapper.builder()
.addModule(JavaTimeModule())
.build()
< /code>
Я использую следующие зависимости hatos и jsonapi < /p>
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'com.toedter:spring-hateoas-jsonapi:2.1.3'
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.7.3'
< /code>
Я получаю следующую ошибку < /p>
org.springframework.http.converter.HttpMessageNotWritableException:Could not write JSON:Java 8 date/time type java.time.LocalDateTime not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"
< /code>
Если я добавлю < /p>
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime localdaetTime;
< /code>
Когда я использую приведенный выше код на Getter, он работает, но я не могу использовать это, потому что класс модели присутствует в библиотеке, и я не могу его изменить.
Также, если я удалюproduces = JSON_API_VALUE
Подробнее здесь: https://stackoverflow.com/questions/797 ... n-using-ha