Make it easier to use JSON libraries other than Jackson alongside REST Docs

Open
#263 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
28/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
java
Domain
api, backend, testing

Research direction

Reproduce the failure with the Gradle spring-restdocs-mockmvc:1.1.0.RELEASE dependency and the dispatcher-servlet.xml configuration shown in the issue. Start at the mvc:message-converters setup and inspect why GsonHttpMessageConverter is absent when REST Docs is added. Done means the existing custom converters remain available and the tests no longer crash.

Written by the indexing model from the issue text.

Description

type: enhancement

My spring project works fine,
but tests crashes when I add spring-restdocs to gradle dependencies.
Just that (no configuration chages, no test code changes) brakes my project.

The problem is that spring-restdocs library make spring framework ignore mvc:message-converters configuration. (I'm not sure what is exactly happened)
I added gson over jackson for JSON as you can see below.
but with spring-restdocs, only I see is messageConverters without GsonHttpMessageConverter.

I have configuration like this: dispatcher-servlet.xml (there are applicationContext.xml and applicationContext-rest.xml as well)

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

<!-- message converter -->
    <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager">
        <mvc:message-converters>
            <ref bean="jaxbMessageConverter" />
            <ref bean="gsonMessageConverter" />
        </mvc:message-converters>
    </mvc:annotation-driven>

    <bean id="gsonMessageConverter" class="org.springframework.http.converter.json.GsonHttpMessageConverter"/>
    <bean id="jaxbMessageConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
        <property name="marshaller" ref="jaxbMarshaller" />
        <property name="unmarshaller" ref="jaxbUnmarshaller" />
        <property name="supportedMediaTypes">
            <list>
                <value>application/xml</value>
                <value>application/xml;charset=UTF-8</value>
            </list>
        </property>
    </bean>

    <bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="packagesToScan">
            <list>
                <value>foo.boo.**.output</value>
            </list>
        </property>
    </bean>
    <bean id="jaxbUnmarshaller" name="unmarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="packagesToScan">
            <list>
                <value>foo.boo.**.model</value>
            </list>
        </property>
    </bean>
</beans>

gradle

dependencies {
    testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc:1.1.0.RELEASE'
}
Dominant language
Java
Stars
1.2k
Forks
731
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spring-projects/spring-restdocs

All issues in spring-projects/spring-restdocs

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.