Code example for Gson

Methods: toJson

0
     */ 
    public void insertPantryItem(Ingredient ingredient) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put(COLUMN_PANTRY_ID, ingredient.getName());
        values.put(COLUMN_PANTRY_DATA, mGson.toJson(ingredient));
        db.insert(TABLE_PANTRY, null, values);
    } 
 
    /** 
     * Delete a recipe from the database. 
     * 
     * @param name name of the ingredient to delete. 
     */ 
    public void deletePantryItem(String name) {
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(TABLE_PANTRY, COLUMN_PANTRY_ID + "=?", new String[]{name});
    } 
 
}