title: Spring MVC AJAX and JSON using Custom View Resolver, and Custom View
body: <p>custom view:</p>
  
  <pre><code>public class MyView extends AbstractView {
     .... awesome stuff ...
  }
  </code></pre>
  
  <p>controller:</p>
  
  <pre><code>@RequestMapping(value="mylocation")
  public ModelAndView dosomething() {
  ...
     modelAndView.setView( new MyView() );
     return modelAndView;
  }
  </code></pre>
  
  <p>For some reason this doesn't work... The only view resolver I have is the following:</p>
  
  <pre><code>&lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
            p:prefix="/WEB-INF/jsp/"
            p:suffix=".jsp" &gt;
          &lt;property name="exposedContextBeanNames"&gt;
              &lt;list&gt;
                  &lt;value&gt;spEnv&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>this code doesn't work because it's trying to create some JSP view based on... I'm not sure, the path of my form submission; and there obviously is no JSP view for it, I'm expecting JSON to be returned actually, but for some reason this isn't working, it's just trying to forward me to some JSP, so I'm guessing that I need to specify how to handle this in my XML... but I've seen about 1000 different ways that people return JSON, and all of them are very confusing to me, I'm just looking for the simplest way, so I can take it from there</p>
  
  <p>edit: I added an answer which is a good start, but it allows you to type ".json" after any URL and it will do some really bad things if as the controller I'm not expecting it, so I need to somehow have this view resolver only apply to secured URLs</p>