title: Generating Java interface with SWIG
body: <p>I'm using SWIG to make a Java wrapper of a C++ library (about Json (de)serialization) to use it on Android. I defined an abstract class in C++, representing an object which can be (de)serialized :</p>
  
  <pre><code>class IJsonSerializable {
  public:
      virtual void serialize(Value &root) = 0; 
      virtual void deserialize(Value &root) = 0; 
  };</code></pre>
  
  <p>Now, I'm trying to generate from this class a Java interface. Here's my SWIG interface:</p>
  
  <pre><code>%module JsonSerializable
  %{
  #include "JsonSerializable.hpp"
  %}
  
  %import "JsonValue.i"
  
  class IJsonSerializable {
  public:
      virtual void serialize(Value &root) = 0; 
      virtual void deserialize(Value &root) = 0;
  };</code></pre>
  
  <p>But the generated Java code is (obviously, as I was not able to find out how to tell SWIG that's an interface) a simple class, with the two methods and a default constructor/destructor:</p>
  
  <pre><code>public class IJsonSerializable {
    private long swigCPtr;
    protected boolean swigCMemOwn;
  
    public IJsonSerializable(long cPtr, boolean cMemoryOwn) {
      swigCMemOwn = cMemoryOwn;
      swigCPtr = cPtr;
    }  
  
    public static long getCPtr(IJsonSerializable obj) {
      return (obj == null) ? 0 : obj.swigCPtr;
    }  
  
    protected void finalize() {
      delete();
    }  
  
    public synchronized void delete() {
      if (swigCPtr != 0) {
        if (swigCMemOwn) {
          swigCMemOwn = false;
          JsonSerializableJNI.delete_IJsonSerializable(swigCPtr);
        }  
        swigCPtr = 0; 
      }  
    }  
  
    public void serialize(Value root) {
      JsonSerializableJNI.IJsonSerializable_serialize(swigCPtr, this, Value.getCPtr(root), root);
    }  
  
    public void deserialize(Value root) {
      JsonSerializableJNI.IJsonSerializable_deserialize(swigCPtr, this, Value.getCPtr(root), root);
    }  
  
  }</code></pre>
  
  <p>How can I generate a valid interface with SWIG ?</p>