Home  >  Q&A  >  body text

java - spring data rest + restTemplate cannot obtain the data collection when building a data reading and writing service

Client:

ParameterizedTypeReference<PagedResources<Pass>> responseType =
                new ParameterizedTypeReference<PagedResources<Pass>>() {};
PagedResources<Pass> passes =restTemplate.exchange(uri, HttpMethod.GET, null, responseType).getBody();

Server:

@RepositoryRestResource(collectionResourceRel = "pass", path = "pass")
public interface PassRepository extends JpaRepository<Pass,String> {
    List<Pass> findByCarPlate(@Param("carPlate")String carPlate);
}

The data can be obtained normally by inputting URI on the web page, but the result is empty every time. Does anyone know how to solve it?

There is no problem in obtaining a single object, but there is a problem with the data set

过去多啦不再A梦过去多啦不再A梦2686 days ago692

reply all(1)I'll reply

  • 世界只因有你

    世界只因有你2017-06-12 09:29:10

    Let me answer it myself, it’s still a problem with RestTemplate configuration.
    Answer on stackoverflow

    PagedResources does not have the _embedded attribute, resulting in the inability to obtain content.

    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    

    This configuration seems to eliminate the function of parsing failure if the fields do not match, similar to @JsonIgnoreProperties.

    I don’t know if I understand it correctly. I hope someone who understands can explain it.

    reply
    0
  • Cancelreply