title: Convert a protobuf to JSON using Jackson?
body: <p>I get the following error while converting a protobuf to JSON using Jackson's ObjectMapper:</p>
  
  <pre><code>com.fasterxml.jackson.databind.exc.InvalidDefinitionException: 
  Direct self-reference leading to cycle (through reference chain:
  MyObjectPb$MyObject["unknownFields"]-&gt;
  com.google.protobuf.UnknownFieldSet["defaultInstanceForType"])
  </code></pre>
  
  <p>MyObjectPb has the following field:     </p>
  
  <pre><code>protected com.google.protobuf.UnknownFieldSet unknownFields
  </code></pre>
  
  <p>As I am working on an existing codebase, I have the following constraints:</p>
  
  <ol>
  <li>I can't modify the source code for MyObjectPb, so I can't use Jackson's ignore annotations in MyObjectPb.</li>
  <li>Neither can I use Gson's libraries to convert the object, as the codebase already uses Jackson for serialization. Adding a new dependency is not recommended. </li>
  </ol>
  
  <p>How do I tell Jackson to ignore (de)serializing the UnknownFieldSet object inside MyObjectPb?</p>
  
  <hr>
  
  <p>I have tried the following, but these approaches do not seem to solve the problem:</p>
  
  <p>a) Configuring the ObjectMapper:</p>
  
  <pre><code>myObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  myObjectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
  </code></pre>
  
  <p>b) Using a Jackson Mixin:</p>
  
  <pre><code>@JsonIgnoreType
  private abstract class UnknownFieldSetIgnoreMixIn {}
  
  myObjectMapper.addMixIn(UnknownFieldSet.class, UnknownFieldSetIgnoreMixIn.class)
  </code></pre>