title: Different JSON serialization for the same class
body: <p>Common enough problem: a class that I want to serialize in two different ways. In one case I want to include the output of <code>getItems()</code> method and in another case I don't want to see this in the output.</p>
  
  <p>Chose to use Jackson Views as it gives me the maximum flexibility. Created:</p>
  
  <pre><code>public class Views {
      public static class WithOrderItems {
      }
  }
  </code></pre>
  
  <p>Then in the class to be serialized:</p>
  
  <pre><code>@JsonView(Views.WithOrderItems.class)
  public Iterable&lt;OrderItem&gt; getItems() {
      //Code...
  }
  </code></pre>
  
  <p>In the method doing the serialization:</p>
  
  <pre><code>// Expectation: this *should not* include "items" in JSON output
  mapper.writeValueAsString(retObj)
  </code></pre>
  
  <p>returns the same as:</p>
  
  <pre><code>// Expectation: this should include "items" in JSON output
  mapper.writerWithView(Views.WithOrderItems.class).writeValueAsString(retObj)
  </code></pre>
  
  <p>In both cases the entire object is being serialized (it's as if the View is being ignored). Why is this happening?</p>
  
  <p>Most of the documentation, tutorials etc. I can find online are for older versions of Jackson. Is there some setting that I am missing out on? As far as I understand, methods annotated with a view <strong>should not</strong> be included in a default <code>mapper</code>.</p>
  
  <p>My <code>mapper</code> configuration is:</p>
  
  <pre><code>public static ObjectMapper mapper = new ObjectMapper().registerModule(new GuavaModule())
              .registerModule(MoneySerializer.getAsModule());
  
  static {
      mapper.setSerializationInclusion(Include.NON_ABSENT);
  }
  </code></pre>
  
  <p>(The <code>getAsModule()</code> is temporary code. <code>MoneySerializer</code> is for Joda Money objects and isn't being invoked in this case.)</p>
  
  <p>Want to avoid mixins as that means static configuration of what is output and what isn't.</p>
  
  <p>Using:</p>
  
  <ul>
  <li>Jackson: 2.6.1</li>
  <li>Java 7</li>
  <li>GAE SDK 1.9.30</li>
  <li>Objectify 5.1.7</li>
  </ul>