Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9080115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:00:02+00:00 2026-06-16T20:00:02+00:00

OK, I have a spring mvc based json web service. This is a test

  • 0

OK, I have a spring mvc based json web service. This is a test app, I have never seen a problem like this when building spring mvc based restful json services. The output of my test service always returns and empty json object followed by && followed by the data i want to return. So the result looks like this:

{} && {“status”:200,”serverTime”:”January 6, 2013 7:35:45 PM EST”}

The code for my controller method to process this very simple GET request is:

    @RequestMapping(value = "/test.json", method = RequestMethod.GET)
public ModelMap test(ModelMap m, HttpServletRequest request,
        Locale locale) {
    Date date = new Date();
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG,
            DateFormat.LONG, locale);

    String formattedDate = dateFormat.format(date);

    m.addAttribute("serverTime", formattedDate);
    m.addAttribute("status", 200);

    return m;
}

I cant for the life of me figure out where that extra empty {} json object is coming from. my spring config looks like this:

<beans:bean
    class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <beans:property name="mediaTypes">
        <beans:map>
            <beans:entry key="html" value="text/html" />
            <beans:entry key="json" value="application/json" />
        </beans:map>
    </beans:property>
    <beans:property name="defaultViews">
        <beans:list>
            <beans:bean
                class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
                <beans:property name="prefixJson" value="true" />
            </beans:bean>
        </beans:list>
    </beans:property>
    <beans:property name="viewResolvers">
        <beans:list>
            <beans:bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
                <beans:property name="viewClass"
                    value="org.springframework.web.servlet.view.JstlView" />
                <beans:property name="prefix" value="/WEB-INF/views/" />
                <beans:property name="suffix" value=".jsp" />
            </beans:bean>
        </beans:list>
    </beans:property>

Any help would be greatly appreciated. I have blown through 6 hours on a sunday trying to figure out why this is happening.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:00:03+00:00Added an answer on June 16, 2026 at 8:00 pm

    From the MappingJacksonJsonView javadoc :

    public void setPrefixJson(boolean prefixJson)
    

    Indicates whether the JSON output by this view should be prefixed with
    “{} && “. Default is false. Prefixing the JSON string in this manner
    is used to help prevent JSON Hijacking. The prefix renders the string
    syntactically invalid as a script so that it cannot be hijacked. This
    prefix does not affect the evaluation of JSON, but if JSON validation
    is performed on the string, the prefix would need to be ignored.

    So did you try with prefixJson set to false ?

    <beans:bean
        class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
        <beans:property name="mediaTypes">
            <beans:map>
                <beans:entry key="html" value="text/html" />
                <beans:entry key="json" value="application/json" />
            </beans:map>
        </beans:property>
        <beans:property name="defaultViews">
            <beans:list>
                <beans:bean
                    class="org.springframework.web.servlet.view.json.MappingJacksonJsonView">
                    <beans:property name="prefixJson" value="false" />
                </beans:bean>
            </beans:list>
        </beans:property>
        <beans:property name="viewResolvers">
            <beans:list>
                <beans:bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
                    <beans:property name="viewClass"
                        value="org.springframework.web.servlet.view.JstlView" />
                    <beans:property name="prefix" value="/WEB-INF/views/" />
                    <beans:property name="suffix" value=".jsp" />
                </beans:bean>
            </beans:list>
        </beans:property>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a REST web service built with Spring MVC, with annotation-based configuration and
I have a localized spring mvc based web application, that has an externalized messages
I have a Spring Web MVC application that I'd like to serve a large,
In my Spring MVC based web-app, I'm manually creating an Errors/BindingResult object after manually
I have a java web application based on Spring MVC. The task is to
I have a Spring MVC based REST service. My controllers have @ExceptionHandler annotated methods
I have a spring mvc 3.1 application based on this tutorial . I've modified
I have web application based on Spring-MVC. I've integrated it with Hibernate 3.6.0. When
I have a Spring MVC based Web Application with Hibernate. Following is the directory
I have a Spring MVC based web application. There are many custom tags written

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.