jersey
  1. jersey
  2. JERSEY-2497

No source injected for custom type in FormDataParam

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.7
    • Fix Version/s: 2.11
    • Component/s: media
    • Labels:
      None

      Description

      Hi,

      I declared a POST method in my service with MULTIPART_DATA_TYPE as MediaType. I tried to send a List of custom types (not FormDataBodyPart or FormDataContentDisposition) to this service, but the service is not validated (no injection source found for type java.util.List) though the List is correctly serialized on the client side (I'm using JSON object serialized with jackson). I would expect the List to parsed as a JSON object, like another parameter with a custom type included in my method.

        Activity

        Hide
        sberoard added a comment - - edited

        I have fixed my problem, i send you the patch, i think List should be managed like simple types : FormDataBodyPart or FormDataContentDisposition or custom type

        Show
        sberoard added a comment - - edited I have fixed my problem, i send you the patch, i think List should be managed like simple types : FormDataBodyPart or FormDataContentDisposition or custom type
        Hide
        sberoard added a comment -

        diff --git a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/FormDataParamValueFactoryProvider.java b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/FormDataParamValueFactoryProvider.java
        index b5563af..d5f5a72 100644
        — a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/FormDataParamValueFactoryProvider.java
        +++ b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/FormDataParamValueFactoryProvider.java
        @@ -345,6 +345,8 @@
        return new ListFormDataBodyPartValueFactory(parameter.getSourceName());
        } else if (FormDataContentDisposition.class == c)

        { return new ListFormDataContentDispositionValueFactory(parameter.getSourceName()); + }

        else

        { + return new FormDataParamValueFactory(parameter, get(parameter)); }

        } else if (FormDataBodyPart.class == parameterRawType) {
        return new FormDataBodyPartValueFactory(parameter.getSourceName());

        Show
        sberoard added a comment - diff --git a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/FormDataParamValueFactoryProvider.java b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/FormDataParamValueFactoryProvider.java index b5563af..d5f5a72 100644 — a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/FormDataParamValueFactoryProvider.java +++ b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/FormDataParamValueFactoryProvider.java @@ -345,6 +345,8 @@ return new ListFormDataBodyPartValueFactory(parameter.getSourceName()); } else if (FormDataContentDisposition.class == c) { return new ListFormDataContentDispositionValueFactory(parameter.getSourceName()); + } else { + return new FormDataParamValueFactory(parameter, get(parameter)); } } else if (FormDataBodyPart.class == parameterRawType) { return new FormDataBodyPartValueFactory(parameter.getSourceName());
        Hide
        Michal Gajdos added a comment -

        Can you please show us the client side of your use case and the resource method you're trying to inject?

        Show
        Michal Gajdos added a comment - Can you please show us the client side of your use case and the resource method you're trying to inject?
        Hide
        sberoard added a comment -

        Hi Michal,

        I cannot send you the source because I don't have the right to do this, but I can provide a generic snippet to show:
        On client side:
        AnotherCustomObject anotherObject = new AnotherCustomObject();
        List<CustomObject> myList = new ArrayList<CustomObject>();

        FormDataMultiPart mp = new FormDataMultiPart();
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("another_object").fileName("another_object").build(),anotherObject, MediaType.APPLICATION_JSON_TYPE));
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("list").fileName("list").build(),myList, MediaType.APPLICATION_JSON_TYPE));
        // send the request

        On server side, the resource method:
        @POST
        @Consumes(MediaType.MULTIPART_FORM_DATA)
        @Produces(MediaType.APPLICATION_JSON)
        @Path("path")
        public List<YetAnotherObject> process(@FormDataParam(value="another_object") AnotherCustomObject, @FormDataParam(value="list") List<CustomObject> myList)

        { // implementation }

        For your information, with the source code above, i have the exception "No injection source found for java.util.List"
        If I replace in the resource method, List<CustomObject> by ArrayList<CustomObject>, it works without problem.
        If I use my patch with the original code, it works without problem.

        Show
        sberoard added a comment - Hi Michal, I cannot send you the source because I don't have the right to do this, but I can provide a generic snippet to show: On client side: AnotherCustomObject anotherObject = new AnotherCustomObject(); List<CustomObject> myList = new ArrayList<CustomObject>(); FormDataMultiPart mp = new FormDataMultiPart(); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("another_object").fileName("another_object").build(),anotherObject, MediaType.APPLICATION_JSON_TYPE)); mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("list").fileName("list").build(),myList, MediaType.APPLICATION_JSON_TYPE)); // send the request On server side, the resource method: @POST @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) @Path("path") public List<YetAnotherObject> process(@FormDataParam(value="another_object") AnotherCustomObject, @FormDataParam(value="list") List<CustomObject> myList) { // implementation } For your information, with the source code above, i have the exception "No injection source found for java.util.List" If I replace in the resource method, List<CustomObject> by ArrayList<CustomObject>, it works without problem. If I use my patch with the original code, it works without problem.
        Hide
        Michal Gajdos added a comment -

        OK, thank you, this is enough.

        Show
        Michal Gajdos added a comment - OK, thank you, this is enough.

          People

          • Assignee:
            Michal Gajdos
            Reporter:
            sberoard
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: