Serialize bean to empty json document using jackson, one class only
<p>I have a web service client that needs to send json data in an HTTP POST.  I have a need to provide an empty json object in one of the fields.  I cannot omit the field, it must be an object, and I should not supply any fields inside this object because that would change the result.  Only an empty object will do.</p>

<p>Can this be done in jackson solely using annotations?  If there is any serialization or mapping configuration, I need that to apply only to this class.  I'm hoping for a magic option to <code>JsonInclude</code> or <code>JsonSerialize</code>.</p>

<p>Desired serialization output:</p>

<pre><code>{
  "field1": "value1",
  "field2": "value2",
  "field3": {}
}
</code></pre>

<p>This is pretty close to my Java class:</p>

<pre><code>@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class BeanClass implements Serializable {
  private static final long serialVersionUID = 1L;

  @JsonProperty("field1")
  private String field1;

  @JsonProperty("field2")
  private String field2;

  @JsonProperty("field3")
  private EmptyBean field3;
}
</code></pre>

<p>And the <code>EmptyBean</code> class pretty much looks like this:</p>

<pre><code>@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class EmptyBean implements Serializable {
  private static final long serialVersionUID = 1L;
}
</code></pre>

<p>A way to turn off the <code>FAIL_ON_EMPTY_BEAN</code> serialization option with an annotation would get this done for me.  <a href="https://stackoverflow.com/a/15261908/729627">This answer</a> looks promising but focuses on configuration which looks like it would apply to my whole application (and I don't want that).</p>

<p>I am hoping to solve this solely through annotations if possible.  But as long as I have a way to change the mapping only for this class, I'll be happy.</p>