Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic type is not used sometimes [SPR-15364] #19928

Closed
spring-projects-issues opened this issue Mar 20, 2017 · 1 comment
Closed

Generic type is not used sometimes [SPR-15364] #19928

spring-projects-issues opened this issue Mar 20, 2017 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Mar 20, 2017

Vitaly Merenkov opened SPR-15364 and commented

Hello, I'm trying to create a hierarchy of REST controllers for objects which could be parents for another objects and not. I have a lot of sub types for parents and children and do not want to duplicate the same resources in every controller even with delegate pattern.

The sample code is attached. I can't reproduce an issue by some reason in this code as in real environment, but in any case it works not as expected.

The base controller from which every controller should be inherited:

public class BaseRESTController<Request extends BaseRequest> {

    @RequestMapping(method = RequestMethod.POST)
    public String create(@RequestBody List<Request> requests) {
        System.out.println("Create parents " + requests);
        return "OK";
    }
}

The base controller for objects which could have children:

public class BaseRESTControllerWithChildren<PRequest extends BaseRequest, CRequest extends ChildRequest> extends BaseRESTController<PRequest> {
    @RequestMapping(path = "/{id}/children", method = RequestMethod.POST)
    public String createResources(@PathVariable(name = "id") String containerID, @RequestBody List<CRequest> requests) {
        System.out.println("Create children " + requests);
        return "OK";
    }
}

The implementation which works as expected:

@RestController
@RequestMapping(path = "/working")
public class WorkingRESTController extends BaseRESTController<ParentRequest>{
    
}

Request example:

[
  {
    "base": "string",
    "field1": "string"
  }
]

Output from logs:

Create parents [test.complexgenericrest.ParentRequest@1dca0c02]

The implementation which doesn't work as expected:

@RestController
@RequestMapping(path = "/not-working")
public class NOTWorkingRESTController extends BaseRESTControllerWithChildren<ParentRequest, ChildRequest> {
    
}

Request example:

[
  {
    "base": "string",
    "field1": "string"
  }
]

Output from logs:

Create parents [test.complexgenericrest.BaseRequest@16641e47]

In second case I have incorrect request type. In real environment I have this error in logs:

2017-03-20 16:52:05.918  WARN 10944 --- [io-8090-exec-10] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Unrecognized field "type" (class mycompany.BaseRequest), not marked as ignorable (6 known properties: "domain-id", "name", "description", "fault-status", "monitoring-profile-id", "external-id"])
 at [Source: java.io.PushbackInputStream@4a4c323e; line: 9, column: 14] (through reference chain: java.util.ArrayList[0]->mycompany.BaseRequest["type"]); nested exception is com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "type" (class mycompany.BaseRequest), not marked as ignorable (6 known properties: "domain-id", "name", "description", "fault-status", "monitoring-profile-id", "external-id"])
 at [Source: java.io.PushbackInputStream@4a4c323e; line: 9, column: 14] (through reference chain: java.util.ArrayList[0]->mycompany.BaseRequest["type"])

The interesting part is that documentation generated by springfox is correct in any case.

Please suggest what should I change in configuration or fix this issue. I think it is related to #19039.


Attachments:

Issue Links:

@spring-projects-issues spring-projects-issues added type: bug A general bug status: waiting-for-triage An issue we've not yet triaged or decided on and removed type: bug A general bug labels Jan 11, 2019
@rstoyanchev rstoyanchev added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Nov 8, 2021
@sdeleuze sdeleuze self-assigned this Oct 24, 2023
@sdeleuze sdeleuze added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 24, 2023
@sdeleuze
Copy link
Contributor

Sorry for the delay, I can't find the reference of the related issue but I think this was fixed at some point, and I have verified with your reproducer that the /not-working endpoint is now working as expected with Spring Framework 6.0.13.

@sdeleuze sdeleuze closed this as not planned Won't fix, can't repro, duplicate, stale Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants