最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring boot - Getting "Failed to read request" from Springboot rest endpoint - Stack Overflow

programmeradmin1浏览0评论

I am getting this "Failed to read request" response using swagger or postman. My code is never reached (never hits breakpoint) This my controller code:

    @PostMapping(value = "/lineinpolygon",
        consumes = MediaType.APPLICATION_JSON_VALUE, 
        produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Is line within polygon.",
        description = "Is line within polygon. Give the id for the for the polygon and a track to check. The geometry format should be Lon, Lat, Alt.  The SRID for the geometries use 4326.",
        responses = {
                @ApiResponse(responseCode = "200", description = "Success", 
                content = {
                        @Content(
                                mediaType = "application/json",
                                schema = @Schema(implementation = WithinPolygonResponse.class)
                        )
                }),
                @ApiResponse(responseCode = "400", description = "An error occurred while getting if line is within polygon.")
        })
        public ResponseEntity<WithinPolygonResponse> getLineWithinPolygon(@RequestBody LineWithinRequestID entity) {
                try {
                        Optional<Integer>opSrid = Optional.ofNullable(entity.getSrid()) ;
                        boolean match = myService.isLineContainedInPolygon(entity.getId(),entity.getCoordinateList(), opSrid.orElse(4326));

                        return ResponseEntity.ok(new WithinPolygonResponse(match));
                } catch (Exception exc) {
                        throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Get line Within polygon error.", exc);
                }
        }

This is the LineWithinRequestID object:

@Getter
@Setter
@Data
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class LineWithinRequestID {

    @JsonProperty("id")
    private Long id;

    @JsonProperty("srid")
    private Integer srid;

    @JsonProperty("coordinates")
    private List<List<Double>> coordinateList;
}

And here is my WithinPolygonResponse object:

@Getter
@Setter
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class WithinPolygonResponse {

    @JsonProperty("status")
    private Boolean status;
}

This is what I am putting into my request:

{
  "id": 2,
  "srid": 4326,
  "coordinates": [
    [
      [-77.292894, 38.392816, 0], [-77.169498, 38.468925, 0], [-77.204214, 38.568971, 0]
    ]
  ]
}

What am I doing wrong? I am a newbie to Springboot and Swagger

I am getting this "Failed to read request" response using swagger or postman. My code is never reached (never hits breakpoint) This my controller code:

    @PostMapping(value = "/lineinpolygon",
        consumes = MediaType.APPLICATION_JSON_VALUE, 
        produces = MediaType.APPLICATION_JSON_VALUE)
    @Operation(summary = "Is line within polygon.",
        description = "Is line within polygon. Give the id for the for the polygon and a track to check. The geometry format should be Lon, Lat, Alt.  The SRID for the geometries use 4326.",
        responses = {
                @ApiResponse(responseCode = "200", description = "Success", 
                content = {
                        @Content(
                                mediaType = "application/json",
                                schema = @Schema(implementation = WithinPolygonResponse.class)
                        )
                }),
                @ApiResponse(responseCode = "400", description = "An error occurred while getting if line is within polygon.")
        })
        public ResponseEntity<WithinPolygonResponse> getLineWithinPolygon(@RequestBody LineWithinRequestID entity) {
                try {
                        Optional<Integer>opSrid = Optional.ofNullable(entity.getSrid()) ;
                        boolean match = myService.isLineContainedInPolygon(entity.getId(),entity.getCoordinateList(), opSrid.orElse(4326));

                        return ResponseEntity.ok(new WithinPolygonResponse(match));
                } catch (Exception exc) {
                        throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Get line Within polygon error.", exc);
                }
        }

This is the LineWithinRequestID object:

@Getter
@Setter
@Data
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class LineWithinRequestID {

    @JsonProperty("id")
    private Long id;

    @JsonProperty("srid")
    private Integer srid;

    @JsonProperty("coordinates")
    private List<List<Double>> coordinateList;
}

And here is my WithinPolygonResponse object:

@Getter
@Setter
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class WithinPolygonResponse {

    @JsonProperty("status")
    private Boolean status;
}

This is what I am putting into my request:

{
  "id": 2,
  "srid": 4326,
  "coordinates": [
    [
      [-77.292894, 38.392816, 0], [-77.169498, 38.468925, 0], [-77.204214, 38.568971, 0]
    ]
  ]
}

What am I doing wrong? I am a newbie to Springboot and Swagger

Share Improve this question asked Jan 29 at 21:07 user398482user398482 1192 silver badges10 bronze badges 1
  • Is there any way for me to debug this in VS code as to what is wrong? – user398482 Commented Jan 29 at 22:00
Add a comment  | 

1 Answer 1

Reset to default 0

I got it, silly typo.

{
  "id": 2,
  "srid": 4326,
  "coordinates": [
 --->[
       [-77.292894, 38.392816, 0], [-77.169498, 38.468925, 0], [-77.204214, 38.568971, 0]
     ]<---
  ]
}

Extra set of brackets so it was getting a List<List<List<Double>>> a mismatch to what the LineWithinRequestID's coordinateList was expecting

发布评论

评论列表(0)

  1. 暂无评论