Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-11622

Rest-dsl doesn't support post() endpoints with different request body types

    Details

    • Type: Wish
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.18.1
    • Fix Version/s: 2.18.2
    • Component/s: rest
    • Labels:
      None
    • Environment:

      Spring-Boot with Tomcat8 container

    • Estimated Complexity:
      Unknown

      Description

      The rest-dsl doesn't support two post() endpoints with different request body types.

      restConfiguration()
        .component("servlet")
        .contextPath("/api")
        .bindingMode(RestBindingMode.json)
      ;
      
      rest("/user")
        .post("/employee").type(UserPojo.class)
            .route()
            .log("Name: ${body.name}")
            .endRest()
      ;
      
      rest("/country")
        .post("/origin").type(CountryPojo.class)
            .route()
            .log("Name: ${body.country}")
            .endRest()
      ;
      

      Both endpoints (/api/user/employee, /api/country/origin) tries to unmarshal the post body to CountryPojo and a JsonProcessingException is thrown when a UserPojo json is sent to /user/employee.
      The problem is that they share one JascksonDataFormat instance registered with name "json-jackson" and the RestDefinition.type() sets the JascksonDataFormat.unmarshalType so at the end both post() endpoints will try to unmarshal to the same class.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                BalazsSzeti Balazs Szeti
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: