Automatic message conversion is not for the next Rest.GET. How can I use automatic JSON message conversion? I read many different solutions without solving the important issue.
Spring Boot is said to have a lot of standard message converters.
Q1: Why is the message conversion failing?
Q2: Should I really add the Jackson JSON converter to the message converter list? How?
The POJO object is:
public class CacheCoordinateRange {
private double latitudeMin;
private double latitudeMax;
private double longitudeMin;
private double longitudeMax;
public CacheCoordinateRange() { }
public CacheCoordinateRange( double latMin, double latMax, double lonMin, double lonMax) {
this.latitudeMin = latMin;
this.latitudeMax = latMax;
this.longitudeMin = lonMin;
this.longitudeMax = lonMax;
}
... getters and setters
The Rest controller consists of:
@RequestMapping(method = RequestMethod.GET, value = "/coordinaterange", produces = { "application/json" }, consumes = MediaType.ALL_VALUE )
public List<Items> findByCoordinateRange( @RequestBody CacheCoordinateRange coordinateRange) {
return cacheRepository.findByLatitudeBetweenAndLongitudeBetween( coordinateRange.getLatitudeMin(),
coordinateRange.getLatitudeMax(), coordinateRange.getLongitudeMin(), coordinateRange.getLongitudeMax());
}
The rest(Test)Template is:
CacheCoordinateRange range = new CacheCoordinateRange( 52.023456, 52.223456, -12.0234562, -12.223456);
HttpHeaders headersRange = new HttpHeaders();
headersRange.setContentType(MediaType.APPLICATION_JSON);
HttpEntity entityRange = new HttpEntity( range,headersRange);
ResponseEntity<SolvedCache[]> resultRange = restTestTemplate.exchange(solvedCacheRestServices + "/coordinaterange", HttpMethod.GET, entityRange, SolvedCache[].class);
objects = responseEntity.getBody();
The error is:
WARN org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public java.util.List<nl.xyz.caches.Cache> nl.xyz.caches.SolvedCacheServices.findByCoordinateRange(nl.xyz.caches.CacheCoordinateRange)