title: Using foreign key in import JSON Android Realm
body: <p>I have a problem with importing data from json to Android Realm. I get "Could not map | Expected JsonObject instead of Integer" error.</p>
  
  <p>I know it works when I put the json object instead of foreign key but I want to use foreign key.
  This is my schema: <a href="http://sqlfiddle.com/#!9/933be/1" rel="nofollow">Database</a></p>
  
  <p>And this is my models:</p>
  
  <p><strong>Category:</strong></p>
  
  <pre><code>@RealmClass
  public class Category extends RealmObject {
      @PrimaryKey
      private int id;
      private String name;
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p><strong>Product:</strong></p>
  
  <pre><code>@RealmClass
  public class Product extends RealmObject {
      @PrimaryKey
      private int id;
      private String name;
      private Category category;
  
      public int getId() {
          return id;
      }
  
      public void setId(int id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public Category getCategory() {
          return category;
      }
  
      public void setCategory(Category category) {
          this.category = category;
      }
  }
  </code></pre>
  
  <p>And this is my json file for importing file:</p>
  
  <p><strong>categories.json:</strong></p>
  
  <pre><code>[
    {
      "id": 1,
      "name": "Price"
    },
    {
      "id": 2,
      "name": "Site"
    }
  ]
  </code></pre>
  
  <p><strong>products.json:</strong></p>
  
  <pre><code>[
    {
      "id": 1,
      "name": "Price Product",
      "category": 1
    },
    {
      "id": 2,
      "name": "Site Product",
      "category": 2
    }
  ]
  </code></pre>
  
  <p><strong>Import.java</strong></p>
  
  <pre><code>Realm db = Realm.getInstance(mContext);
  db.beginTransaction();
  try {
       db.createOrUpdateAllFromJson(Category.class, App.loadJSONFromAsset(mContext, "categories"));
       db.createOrUpdateAllFromJson(Product.class, App.loadJSONFromAsset(mContext, "products"));
       db.commitTransaction();
   } catch (Exception e) {
       db.cancelTransaction();
       e.printStackTrace();
   }
   db.close();
  </code></pre>
  
  <p>if I change the <strong>products.json</strong> to below json, it works.</p>
  
  <pre><code>[
    {
      "id": 1,
      "name": "Price Product",
      "category": {
        "id": 1,
        "name": "Price"
      }
    },
    {
      "id": 2,
      "name": "Site Product",
      "category": {
        "id": 1,
        "name": "Site"
      }
    }
  ]
  </code></pre>