Skip to content

Regression: @ResponseBody with Map result returns JSON array twice in case of synchronizeOnSession=true [SPR-13983] #18555

Closed

Description

@spring-projects-issues

Toshimitsu Nakanishi opened SPR-13983 and commented

@RequestMapping(value = "/json/", produces = "application/json")
@ResponseBody
public Map<String, Object> test(WebRequest request) {
    Map<String, Object> map = new LinkedHashMap<>();
    map.put("result", Boolean.TRUE);
    return map;
}

built with spring 4.2.5, json result is returned 2 arrays.
4.2.4 is correct.


Affects: 4.2.5

Issue Links:

Referenced from: commits spring-attic/spring-framework-issues@49c0466

Activity

  1. spring-projects-issues commented on Feb 26, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    Toshimitsu Nakanishi I have tried to reproduce this behavior by creating a fresh new project with start.spring.io, configuring the project to use Spring Framework 4.2.5 with <spring.version>4.2.5.RELEASE</spring.version>, and creating a @Controller with the code you provided, but I see the same correct behavior for both 4.2.4 and 4.2.5.

    Could you give me more details (Jackson version used for example) and maybe provide a repro project? You can use spring-framework-issues templates (without Spring Boot) or start.spring.io.

  2. spring-projects-issues commented on Feb 26, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Toshimitsu Nakanishi commented

    my Jackson version is 2.4.2.
    project includes jackson-core-2.4.2.jar and jackson-databind-2.4.2.jar.
    build by JVM 1.8.74.

    with 4.2.5 controller returned response was
    {"result":true}{"result":true}

    with 4.2.4 controller returned response was only
    {"result":true}

  3. spring-projects-issues commented on Feb 26, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    I just tried with Jackson 2.4.2 and can't reproduce the issue. Could you please provide a repro project to help identifying where this strange behavior come from?

  4. spring-projects-issues commented on Feb 26, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Toshimitsu Nakanishi commented

    When adapter.setSynchronizeOnSession(true); all of Controllers are run 2 times 1 request.
    when comment out adapter.setSynchronizeOnSession(true);. all of Controllers are run 1 times while by 1 request.

    @Component
    public class SynchronizeOnSessionPostProcessor implements BeanPostProcessor {
    
    	/**
    	 * postProcessBeforeInitialization
    	 */
    	@Override
    	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
    		return bean;
    	}
    
    	/**
    	 * postProcessAfterInitialization
    	 */
    	@Override
    	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    
    		// do synchronize each http request
    		if (bean instanceof RequestMappingHandlerAdapter) {
    
    			RequestMappingHandlerAdapter adapter = (RequestMappingHandlerAdapter) bean;
    
    			adapter.setSynchronizeOnSession(true);
    
    		}
    
    		return bean;
    
    	}
    
    }
  5. spring-projects-issues commented on Feb 26, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    Sorry but I think a really need a repro project to see what's going on, could you please provide it even as just a zip attached to this issue or as a GitHub repository?

  6. spring-projects-issues commented on Feb 26, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Toshimitsu Nakanishi commented

    repro project zip

    100% reproduce.

    check out project file.

    reproduce operation.

    1. access /test1/json/test
      -> result was {"result": true}
      This is correct.

    2. access /test1/html/test
      -> result was test.
      this method works controller to jsp.

    3. re-access /test1/json/test
      -> result was {"result": true}{"result": true}
      controller method was executed 2 times.

    but, if comment out adapter.setSynchronizeOnSession(true);
    works good.

  7. spring-projects-issues commented on Feb 26, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    Thanks for your repro project, I confirm it is reproducible with your project + instructions. I will keep you informed of what I find.

  8. spring-projects-issues commented on Feb 29, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    Likely to be a duplicate of #18572

  9. spring-projects-issues commented on Feb 29, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    I have added a repo project with repo instructions that:

    • Show not issue with Spring Framework 4.2.4
    • Show the issue with Spring Framework 4.2.5
    • Seems to not work (no output) with Spring Framework 4.2.x branch (last commit tested 0349abc565da1523daa84d42d5950ab2ebf12df2.
  10. spring-projects-issues commented on Feb 29, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Sébastien Deleuze commented

    This issue is fixed (validated with the repo project) by #18572 related commits, on latest 4.2.x branch 0349abc565da1523daa84d42d5950ab2ebf12df2 and 8a44560d82b40af65a3b79c3a5c3915ae2e3d5b7.

  11. added
    type: bug
    status: duplicate
    in: web
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webstatus: duplicate

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions