BAEL-3819: Set returned content type to application/json (#8759)
* BAEL-3819: Set returned content type to application/json * BAEL-3819: Add json and xml /content endpoints
This commit is contained in:
parent
6516f14696
commit
3e8be17de2
@ -1,11 +1,11 @@
|
|||||||
package com.baeldung.requestresponsebody;
|
package com.baeldung.requestresponsebody;
|
||||||
|
|
||||||
import com.baeldung.services.ExampleService;
|
import com.baeldung.services.ExampleService;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@ -34,4 +34,18 @@ public class ExamplePostController {
|
|||||||
log.debug("POST received - serializing LoginForm: " + loginForm.getPassword() + " " + loginForm.getUsername());
|
log.debug("POST received - serializing LoginForm: " + loginForm.getPassword() + " " + loginForm.getUsername());
|
||||||
return new ResponseTransfer("Thanks For Posting!!!");
|
return new ResponseTransfer("Thanks For Posting!!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/content", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseTransfer postResponseJsonContent(@RequestBody LoginForm loginForm) {
|
||||||
|
log.debug("POST received - serializing LoginForm: " + loginForm.getPassword() + " " + loginForm.getUsername());
|
||||||
|
return new ResponseTransfer("JSON Content!");
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/content", produces = MediaType.APPLICATION_XML_VALUE)
|
||||||
|
@ResponseBody
|
||||||
|
public ResponseTransfer postResponseXmlContent(@RequestBody LoginForm loginForm) {
|
||||||
|
log.debug("POST received - serializing LoginForm: " + loginForm.getPassword() + " " + loginForm.getUsername());
|
||||||
|
return new ResponseTransfer("XML Content!");
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user