How to pass JSON Object and return Object from Spring rest controller
To return the status and also the object you can try to do it like this:
@PostMapping(path = "/submitData", consumes = "application/json")
public ResponseEntity<Report> callDataService(@RequestBody Map<String, String> json) {
Gson gson = new GsonBuilder().create();
InputData inputData = gson.fromJson(json.get("inputData"), InputData.class);
Report report = dataService.getReport(inputData);
return ResponseEntity.ok(report);
}
Retrieving a JSON body from DB gives extra special characters - Spring Boot
TL;DR
Just annotated private String responseBody;
with @JsonRawValue
as follows:
@JsonRawValue
private String responseBody;
Explanation
Because the value of responseBody
is a JSON string and @RestController
is going to serialize the return object of moreInfo
into HttpResponse automatically. That's why you got "extra special characters" in your response body!
Therefore, the simplest way (by using Jackson
) is to annotate those fields which you don't want to be serialized again with @JsonRawValue
.
For more information, please refer to @JsonRawValue.
Related Topics
Pdf to Byte Array and Vice Versa
Checking for Null on a Collection in Jpql Queries
The Group Coordinator Is Not Available-Kafka
How to Set the Timeout for a Jax-Ws Webservice Client
Java Package Does Not Exist Error
How to Launch Command in Batch File With Space
Keycloak - Create Realms/Users/Groups Programmatically
How to Prevent Xss Attacks or Untrusted Data in Rest API Json Using Java
Counting Unique Characters in a String
How to Pass External Jar File to Spring Boot Project
Selenium Webdriver: Clicking on Elements Within an Svg Using Xpath
Springboot Data - No Property Registration Found
Mockito - Nullpointerexception When Stubbing Method
Spring @Requestbody and Enum Value
Getresourceasstream Returns Null When Reading Properties File
How to Pass the Same Object Across Multiple Classes Java
Multipartexception: Current Request Is Not a Multipart Request