title: How to de-serialize JSON objects in C# which were sent by a JAVA program using jackson?
body: <p>I'm working on a project needing a .NET program and a JAVA program to interoperate via protocol.</p>
  
  <p>The JAVA side uses Jackson to serialize simple JAVA objects (resulting in JSON-Packets having the concrete class as @class members).</p>
  
  <p>But the .NET side uses different conventions for this - here the type is specified by __type members.</p>
  
  <p>Can I massage the .NET side to accept JACKSON formatted packets? Changing the protocol format on the JAVA side would be suboptimal, because the protocol is already used elsewhere, so getting .NET to adapt would be preferred.</p>
  
  <p>Currently I was looking at the .NET DataContractJsonSerializer - but it is also possible to employ a third party library on the .NET side if required.</p>
  
  <p>Can JSON.NET offer this kind of flexibility? BTW, problems like assembly versions are not an issue here, so it is perfectly OK for the protocol to <em>not</em> send that information.</p>
  
  <p><strong>EDIT</strong> to make my intentions clearer, here some example code:</p>
  
  <h2>JAVA side</h2>
  
  <pre><code>package some.pkg;
  
  import com.fasterxml.jackson.annotation.JsonTypeInfo;
  
  @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS)public abstract class EventBase {
  
    public final String superField;
  
    protected EventBase(final String superField) {
      this.superField = superField;
    }
  }
  </code></pre>
  
  <h3>A second JAVA package class</h3>
  
  <pre><code>package some.pkg;
  
  public final class EventA extends EventBase {
  
    public final int intFieldA;
  
    public EventA(final int intFieldA, final String superField) {
      super(superField);
      this.intFieldA = intFieldA;
    }
  
    private EventA() {this(0,null);}//for jackson
  }
  </code></pre>
  
  <h2>JSON generated by Jackson</h2>
  
  <p>A JSON string generated by Jackson will look e.g. like </p>
  
  <pre><code>{
    "@class" : "some.pkg.EventA",
    "superField" : "S1",
    "intFieldA" : 1
  }
  </code></pre>
  
  <h2>.NET</h2>
  
  <p>Here I have equivalent classes (with methods not shown here - this is a request/event protocol, and the request methods are stored in the packets themselves.</p>
  
  <p>So here I expect something akin to</p>
  
  <pre><code>namespace some.pkg
  {
    public sealed class EventA extends EventBase {
  
    public EventA(final int intFieldA, final String superField) : base(superField) {
      this.intFieldA=intFieldA;
    }
  
    [DataMember]
    public int  fieldA { get; private set; }
  }
  </code></pre>
  
  <p>... superclass and other subclasses of EventBase elied.</p>
  
  <p>The problem here for me is Jackson's way of signaling the class, either via @c or via @class, versus Microsoft's standart "__type" attribute, or JSON.NET's "$type".</p>
  
  <p><strong>Edited - Summary</strong></p>
  
  <p>OK, the answer with switching $type versus @class before resp. after the .NET serializer does it's deed works rather nicely (as long as the magical Strings @class and $type are not used elsewhere as payload data).</p>
  
  <p>A look into JSON.NET's sources showed me that the $type descriminator field is a const string, so changing that would require us to use a patched JSON.NET library, which looks to be more work than just changing the offending strings before resp. after the JsonReader/Writer classes do their deed. </p>