title: Jackson JSON serialization - specify recursion level
body: <p>I'm using SpringMVC 3.2.4 and am looking to use Jackson2 to serialize an object to a JSON output.</p>
  
  <p>The object has a recursive property.  If I try to serialize it using a default Jackson ObjectMapper, I get a recursion error.  I realize that I can use <code>@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class)</code> to prevent the recursion, however, I actually want the recursion to make it easier to parse in a mustache template.  However, I would like to limit the recursion level.</p>
  
  <p>Is there anyway to specify to the Jackson serializer to recurse only 1 level?  If I need to create my own serializer, can I register it such that it is only used for a specific object class?</p>
  
  <p>As indicate by a couple of comments, there is already another question on SO that very closely relates to this one: <a href="https://stackoverflow.com/questions/10191671/jackson-json-serialization-recursion-avoidance-by-level-defining">Jackson JSON serialization, recursion avoidance by level defining</a>.  However, in that question, the accepted answer (as well as the others), all indicate how to avoid recursion by Jackson by using <code>@JsonIdentityInfo</code>.  In this particular case, I am not looking to limit it; rather I want it.  However, I just want to limit the depth of the recursion.</p>
  
  <p>Additionally, the referenced SO question provides links to some Jackson documentation; I have already the docs, but the Jackson docs, quite frankly, are quite lacking.  They indicate how to register a serializer, but do not indicate how it needs to be structured.  Nor, are there any indications as to how to determine the recursive level of the serializer.  Finally, there is no indication if/how one can register a serializer for Jackson in Spring to apply to specific types of classes.</p>