are there any pitfalls when return @Entity from @RestController instead of DTO ? like this: Answer I’d say yes. By returning an entity, you are going to have tight coupling of your response contract and the database entity. So in future if you want to make modifications to either your response/entity, you might run into multiple issues. For example, let’s
Tag: spring-restcontroller
Spring @Valid annotation not working as validating dto fields?
I have checked many other questions about it but I cannot find the solution, where am I missing ? Here is the controller method: And my dto is: My problem is (maybe @Valid is actually working I am not sure), when I debug it with the postman request: I am expecting some kind of message like “Id cannot be null”
How create unit test in Spring REST in POST Cotroller
I have a Spring Boot Controller with POST. Method works fine. I tested it by POSTMAN and from postgresql I recieved JSON. But I need test it. I created test: when I run a test, I received error like below: What am I doing wrong? Answer The problem is this line: Right now you are sending the object in the
Custom Data Binding in Spring
I have a situation here. Suppose, I’m receiving this JSON in the @RequestBody, Which I’m binding to a POJO, like so. Now, ResourceRefRequest, is as follows, and, RefReqItem, is as follows, Things are pretty well, as I expect them to be. The only problem is, refReqItem.resourceId is null, for all refs. I want to populate each of, refReqItem.resourceId, in the
Why does root path in my controller maps to index.html in spring boot web application?
I’m testing a controller for a Spring Boot application. I want to map a resource to a path, which should be a part of my API. My controller is pretty specific about path: Here ‘web-interface’ is a property, as specified in application.yml file Expected behavior: path: localhost:8080/admin maps to index.html resource root path: localhost:8080/ maps to nothing, i.e. 404 error.
whitelabel error page 404 spring boot microservices Rest Controller
I am new to Spring Boot and Microservices. I have created RestController and tried to check using RequestMapping test but it give us error as 404, whitelabel error page. Below is pom.xml : Below is the code for the controller Below is Spring boot main class Server Start up logs are mentioned below : Any help will be appreciated. Thanx
How to pass JSON Object and return Object from Spring rest controller
I have an entity class like below: Here is my rest controller: I have two questions: How can I send the report as well as Http Status back as a response? How to send the data to controller? I have created the following test case: When I run this the test case failed and I was able to pin point
How to return custom response in Spring with several attributes other than the List
I’m trying to get a custom response back from a spring rest controller back to the user, containing a list of all registered users and other keys such as sucess, etc. I tried the following approach but the Json array is completly escaped as a string… I get something like this and wanted something like: Is there any way I
Is it possible to split request params in Spring controllers?
I have a request like: I would like to split those params to bind a List<String> sort in my controller or List<SortParam> where SortParam is the class with fields like: name (String) and ask (boolean). So the final controller would look like this: or Is there a way to make it? UPDATE: The standard way of passing parameters does not
Rest Controller method not getting called in spring boot
I am implementing rest webservice via a spring boot application. POM application.properties Application launcher class Controller I see Did not find handler method for [/services/account] message in the console when I fire http://localhost:8082/services/account URL in the browser as shown below I dont see message – ACCOUNT METHOD CALLED in the console meaning controller method is not getting invoked.Can you please