Results 1 to 5 of 5

Thread: @RequestBody parameter with type of Object receives a SimpleSessionStatus object

  1. #1
    Join Date
    Jan 2012
    Posts
    3

    Default @RequestBody parameter with type of Object receives a SimpleSessionStatus object

    Hi all,

    If I annotate an Object typed parameter with @RequestBody I get the SimpleSessionState object instead of the properly parsed body of the request.

    Example:
    Code:
    	public List<NetResponse> requester(HttpServletRequest request, HttpServletResponse response, Locale locale,
    			@RequestBody Object bodyData) {
    if (bodyData instanceof Map){
       processMap((Map)bodyData);
    }
    if (bodyData instanceof Collection){
       processCollection((Collection)bodyData);
    }
    
    }
    I've traced the problem to the following line method in the org.springframework.web.method.support.InvocableHa ndlerMethod class.
    Code:
    args[i] = resolveProvidedArgument(parameter, providedArgs);
    			if (args[i] != null) {
    continue;
    }
    Code for actual Spring framework method.
    Code:
    private Object[] getMethodArgumentValues(NativeWebRequest request,*
    			ModelAndViewContainer mavContainer,*
    			Object... providedArgs) throws Exception {
    		MethodParameter[] parameters = getMethodParameters();
    		Object[] args = new Object[parameters.length];
    		for (int i = 0; i < parameters.length; i++) {
    			MethodParameter parameter = parameters[i];
    			parameter.initParameterNameDiscovery(this.parameterNameDiscoverer);
    			GenericTypeResolver.resolveParameterType(parameter, getBean().getClass());
    
    
    
    
    			args[i] = resolveProvidedArgument(parameter, providedArgs);
    			if (args[i] != null) {
    				continue;
    			}
    			if (this.argumentResolvers.supportsParameter(parameter)) {
    				args[i] = this.argumentResolvers.resolveArgument(parameter, mavContainer, request, dataBinderFactory);
    			}
    			else {
    				throw new IllegalStateException("Cannot resolve argument index=" + parameter.getParameterIndex() + ""
    						+ ", name=" + parameter.getParameterName() + ", type=" + parameter.getParameterType()
    						+ " in method " + toString());
    			}
    		}
    		return args;
    	}
    Because the parameter is of type Object it matches any providedArgs and the one that's provided in this case is the SimpleSessionStatus object.

    Shouldn't the parameter checking look at the Annotations first so that an Object typed parameter can be used?



    Thanks
    Robert Brown

  2. #2

    Default

    What are you trying to do here, are you just trying to pass a request parameter into your method ?

  3. #3
    Join Date
    Jan 2012
    Posts
    3

    Default

    I'm trying to pass the request body to the method, and have that body parsed by the MessageConverter (in my case a JSON converter) into an object. In this case it is expecting that object to either be a Map or a Collection so I can't specify a particular object type in the parameters. The body of the request will contain a json formatted object. (an Ext.direct request from the ExtJS framework in particular). That object is either a single request or an array of requests. If it's a single request the JSON converter will convert it into a Map, if it's an array of request it becomes a list of maps. Using Ext.direct you can't tell it to use a different url for single vs batch requests so it either sends a single object or a list of objects and your servlet has to work it out.

    The root of the problem though is that it checks the Type of the parameter first instead of letting the annotation take precedence so a parameter of type object will always match the SimpleSessionStatus object passed into the function.

    Note, it would probably do the same thing if I specified a @RequestParam annotation on an Object typed parameter.

    I think it's a bug introduced in 3.x somewhere because the code I'm running is from a library that has an example that works running on 2.5.

    Thanks
    Robert Brown

  4. #4
    Join Date
    Aug 2006
    Location
    Brooklyn
    Posts
    556

    Default

    This should not happen in 3.1.0.RELEASE. Make sure it's what you have rather than a milestone or a release candidate. In 3.1.0.RELEASE the SimpleSessionStatus gets resolved through an argument resolver (rather than as a provided arg).

  5. #5
    Join Date
    Jan 2012
    Posts
    3

    Default

    Ho Rossen,

    I was using the M2 release. I'll get the latest and and retest.

    Thanks
    Bob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •