0

I have my ContentNegotiatingViewResolver setup and it works fine when I have a request like that: htttp://localhost:8080/api/getSubscriptions.json (it returns JSON) or htttp://localhost:8080/api/getSubscriptions.xml (it returns XML).

But, when I try do this request (adding the parameters), htttp://localhost:8080/api/getSubscriptions?company=vivi&key=123456&carrier=1.json the returns is always XML.

<mvc:annotation-driven/>

<bean id="contentNegotiationManager" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="ignoreAcceptHeader" value="true"/>

    <property name="mediaTypes">
        <map>
            <entry key="json" value="application/json" />
            <entry key="xml" value="application/xml" />
        </map>
    </property>
</bean>

This is the code of my controller:

@RequestMapping(value = "getSubscriptions", produces={"application/json", "application/xml"} )
public @ResponseBody Model getSubscriptions(
                              @RequestParam(value = "company", required = true) String company,
                              @RequestParam(value = "carrier", required = true) String carrier,
                              @RequestParam(value = "key",     required = true) String key,
                              HttpServletRequest httpRequest) throws Exception { ... }

Please, what is missing to Spring recognize my media type (json/xml) when I'm using parameters in my request?

1 Answers1

0

Try this url instead:

htttp://localhost:8080/api/getSubscriptions.json?company=vivi&key=123456&carrier=1
MattSenter
  • 3,060
  • 18
  • 18