title: java spring MappingJacksonJsonView not doing toString on mongodb ObjectId
body: <p>I am using the MappingJacksonJsonView in my SpringMVC application to render JSON from my controllers. I want the ObjectId from my object to render as .toString but instead it serializes the ObjectId into its parts. It works just fine in my Velocity/JSP pages:</p>
  
  <pre><code>Velocity:
      $thing.id
  Produces:
      4f1d77bb3a13870ff0783c25
  
  
  Json:
      &lt;script type="text/javascript"&gt;
           $.ajax({
               type: 'GET',
               url: '/things/show/4f1d77bb3a13870ff0783c25',
               dataType: 'json',
               success : function(data) {
                  alert(data);
               }
           });
      &lt;/script&gt;
  Produces:
      thing: {id:{time:1327331259000, new:false, machine:974358287, timeSecond:1327331259, inc:-260555739},…}
          id: {time:1327331259000, new:false, machine:974358287, timeSecond:1327331259, inc:-260555739}
              inc: -260555739
              machine: 974358287
              new: false
              time: 1327331259000
              timeSecond: 1327331259
          name: "Stack Overflow"
  
  
  XML:
      &lt;script type="text/javascript"&gt;
           $.ajax({
               type: 'GET',
               url: '/things/show/4f1d77bb3a13870ff0783c25',
               dataType: 'xml',
               success : function(data) {
                  alert(data);
               }
           });
      &lt;/script&gt;
  Produces:
      &lt;com.place.model.Thing&gt;
          &lt;id&gt;
              &lt;__time&gt;1327331259&lt;/__time&gt;
              &lt;__machine&gt;974358287&lt;/__machine&gt;
              &lt;__inc&gt;-260555739&lt;/__inc&gt;
              &lt;__new&gt;false&lt;/__new&gt;
          &lt;/id&gt;
          &lt;name&gt;Stack Overflow&lt;/name&gt;
      &lt;/com.place.model.Thing&gt;
  </code></pre>
  
  <p>Is there a way to stop MappingJacksonJsonView from getting that much information out of the ObjectId? I just want the .toString() method, not all the details.</p>
  
  <p>Thanks.</p>
  
  <p>Adding the Spring config:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  public class MyConfiguration {
  
      @Bean(name = "viewResolver")
      public ContentNegotiatingViewResolver viewResolver() {
          ContentNegotiatingViewResolver contentNegotiatingViewResolver = new ContentNegotiatingViewResolver();
          contentNegotiatingViewResolver.setOrder(1);
          contentNegotiatingViewResolver.setFavorPathExtension(true);
          contentNegotiatingViewResolver.setFavorParameter(true);
          contentNegotiatingViewResolver.setIgnoreAcceptHeader(false);
          Map&lt;String, String&gt; mediaTypes = new HashMap&lt;String, String&gt;();
          mediaTypes.put("json", "application/x-json");
          mediaTypes.put("json", "text/json");
          mediaTypes.put("json", "text/x-json");
          mediaTypes.put("json", "application/json");
          mediaTypes.put("xml", "text/xml");
          mediaTypes.put("xml", "application/xml");
          contentNegotiatingViewResolver.setMediaTypes(mediaTypes);
          List&lt;View&gt; defaultViews = new ArrayList&lt;View&gt;();
          defaultViews.add(xmlView());
          defaultViews.add(jsonView());
          contentNegotiatingViewResolver.setDefaultViews(defaultViews);
          return contentNegotiatingViewResolver;
      }
  
      @Bean(name = "xStreamMarshaller")
      public XStreamMarshaller xStreamMarshaller() {
          return new XStreamMarshaller();
      }
  
      @Bean(name = "xmlView")
      public MarshallingView xmlView() {
          MarshallingView marshallingView = new MarshallingView(xStreamMarshaller());
          marshallingView.setContentType("application/xml");
          return marshallingView;
      }
  
      @Bean(name = "jsonView")
      public MappingJacksonJsonView jsonView() {
          MappingJacksonJsonView mappingJacksonJsonView = new MappingJacksonJsonView();
          mappingJacksonJsonView.setContentType("application/json");
          return mappingJacksonJsonView;
      }
  }
  </code></pre>
  
  <p>And my controller:</p>
  
  <pre><code>@Controller
  @RequestMapping(value = { "/things" })
  public class ThingController {
  
      @Autowired
      private ThingRepository thingRepository;
  
      @RequestMapping(value = { "/show/{thingId}" }, method = RequestMethod.GET)
      public String show(@PathVariable ObjectId thingId, Model model) {
          model.addAttribute("thing", thingRepository.findOne(thingId));
          return "things/show";
      }
  }
  </code></pre>