Announcement Announcement Module
Collapse
No announcement yet.
Wierd JSON results from REST calls - "{} &&" Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wierd JSON results from REST calls - "{} &&"

    All of my JSON results from all of my RESTful calls are preceded with:
    "{} &&"

    This is very strange as the rest of the results show fine.

    Controller code:
    Code:
    /**
     * Controller method to get all categories in the database.  This includes all active and inactive categories.
     * @return List<Category>
     */
    @RequestMapping(method=RequestMethod.GET,value="/categories")
    public List<Category> getAllCategories() {
    	return this.categoryService.getAll();
    }
    View Resolver in servlet.xml
    Code:
    <bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"/>
    
    <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
      <property name="mediaTypes">
        <map>
          <entry key="json" value="application/json"/>
        </map>
      </property>
      <property name="defaultViews">
        <list>
          <bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
            <property name="prefixJson" value="true"/>
          </bean>
        </list>
      </property>
    </bean>
    Call to this controller:
    Code:
    http://localhost:8080/JSON/categories
    Results from this call:
    Code:
    {} && {"categoryList":[{"id":1,"name":"fun","description":"Fun in the city"},{"id":2,"name":"restaurants","description":"Eating establishments"},{"id":3,"name":"outdoor","description":"Explore the outdoors"},{"id":4,"name":"culture","description":"Learn about art","active":true}]}
    As you can see the results from the call are preceded with "{} &&" and I'm not sure where that's coming from or if that will impact the consumption of the JSON data by the client.

    Any insights?

  • #2
    Hi, try to specify the UTF-8 encoding in the client.
    Last edited by venosov; Mar 26th, 2012, 09:08 AM.

    Comment


    • #3
      Set the value prefixJson to false and it will fix your issue.

      Comment

      Working...
      X