415 unsupported media type in java jersey

前端 未结 1 1070
醉话见心
醉话见心 2020-12-04 03:19

I am having problem with below code saying 415 unsupported MEDIA type and The server refused this request because the request entity is in a format not supported

相关标签:
1条回答
  • 2020-12-04 03:43

    The problem is your method parameter type MultivaluedHashMap

    public Activity createActivityParams(MultivaluedHashMap<String, String> formse){
    

    The provider that handle application/x-www-form-urlencoded and MultivaluedMap, only supports MultivaluedMap or MultivaluedMap<String, String> injections. You can see in the source code

    @Override
    public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
        // Only allow types MultivaluedMap<String, String> and MultivaluedMap.
        return type == MultivaluedMap.class
                && (type == genericType || mapType.equals(genericType));
    }
    

    So just change the method parameter to MultivaluedMap<String, String>

    0 讨论(0)
提交回复
热议问题