У меня ошибка при работе почтальона при получении данных из другого сервиса с использованием RestTemplate.
У меня есть две услуги. Первый сервис имеет класс сущностей userdetails, а второй сервис имеет класс сущностей posts. Это код почтового контроллера.
@GetMapping("/findpostbyareacode/{areacode}")
List<Posts> getPostByAreacode(@PathVariable(value="areacode") Long areacode){
RestTemplate restTemplate=new RestTemplate();
ResponseEntity<List<UserDetails>> response=
restTemplate.exchange("http://localhost:8091/voiceofbengal/userdetailsbyareacode/"+areacode, HttpMethod.GET,
null, new ParameterizedTypeReference<List<UserDetails>>(){
});
List<UserDetails> body=response.getBody();
List<Posts> postList=new ArrayList<>();
List<Posts> totalPost=new ArrayList<>();
for(UserDetails users : body) {
totalPost=postService.findByU_id(users.getU_id());
for(Posts posts : totalPost) {
postList.add(posts);
}
}
return postList;
}
Я получаю эту ошибку в почтальоне.
"timestamp": "2019-01-17T09:10:32.977+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Error while extracting response for type [java.util.List<com.css.vob.model.UserDetails>] and content type [application/json;charset=UTF-8]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String \"01-01-1990\": not a valid representation (error: Failed to parse Date value '01-01-1990': Cannot parse date \"01-01-1990\": not compatible with any of standard forms (\"yyyy-MM-dd'T'HH:mm:ss.SSSZ\", \"yyyy-MM-dd'T'HH:mm:ss.SSS\", \"EEE, dd MMM yyyy HH:mm:ss zzz\", \"yyyy-MM-dd\")); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String \"01-01-1990\": not a valid representation (error: Failed to parse Date value '01-01-1990': Cannot parse date \"01-01-1990\": not compatible with any of standard forms (\"yyyy-MM-dd'T'HH:mm:ss.SSSZ\", \"yyyy-MM-dd'T'HH:mm:ss.SSS\", \"EEE, dd MMM yyyy HH:mm:ss zzz\", \"yyyy-MM-dd\"))\n at [Source: (PushbackInputStream); line: 1, column: 57] (through reference chain: java.util.ArrayList[0]->com.css.vob.model.UserDetails[\"dob\"])",
Edit- После попытки решения @ Pijotrek, я получаю эту ошибку сейчас.
"message": "could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet"
Вот мой класс сущности, DAO и JPARepository
Это класс сущности UserDetails
А вот метод Controller для пользовательских данных, которые я вызывал из post controller-
@GetMapping("/userdetailsbyareacode/{areacode}")
public ResponseEntity<List<UserDetails>> getUserByAreacode(@PathVariable(value="areacode") Long areacode){
List<UserDetails> user=userdetailsService.getuserByAreacode(areacode);
if(user==null) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok().body(user);
}
Вот JPAR-хранилище почтового контроллера-
public interface PostRepository extends JpaRepository<Posts,Long> {
@Transactional
@Query(nativeQuery=true,value="SELECT * FROM POSTS WHERE U_ID=:u_id")
List<Posts> findPostsByU_id(@Param("u_id") Long u_id);