Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

java - org.springframework.http.converter.HttpMessageNotReadableException when sending a GET Request

I am trying to print the fields of a class. The class is as follows:

package com.telstra.sdwan.portal.model.neo4j;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.Id;
import org.neo4j.ogm.annotation.NodeEntity;

import java.util.HashMap;

@NodeEntity
@Getter
@Setter
@NoArgsConstructor
public class Metrics {

    @Id
    @GeneratedValue
    public Long id;
    public String name;
    public HashMap<String, Long> success = new HashMap<String, Long>();
    public HashMap<String, Long> failure = new HashMap<String, Long>();

    public Metrics(String name) {
        this.name = name;
        success.put(name, 0L);
        failure.put(name, 0L);
    }
}

On running the API in the postman I am getting this error:

{
    "timestamp": "2021-01-27T16:28:44.5161857",
    "status": "BAD_REQUEST",
    "errors": [
        "Malformed JSON request"
    ],
    "message": "Required request body is missing: public org.springframework.http.ResponseEntity<com.telstra.sdwan.portal.model.neo4j.Metrics> com.telstra.sdwan.portal.controller.ConfigOpsAppController.apiCalled(com.telstra.sdwan.portal.model.neo4j.Metrics)",
    "data": [],
    "path": "/api/configops-app/metrics"
}

The Controller Method

@ApiOperation("Count of the number of times an API is called")
@GetMapping(value="/metrics")
@PreAuthorize("hasRole('User')")
public ResponseEntity<Metrics> apiCalled(@RequestBody Metrics metrics){ 
    return configOpsAPIService.apiCount(metrics);
}

Please suggest how this error can be resolved.

question from:https://stackoverflow.com/questions/65918002/org-springframework-http-converter-httpmessagenotreadableexception-when-sending

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...