Parsing a String id with SugarORM and GSON
android, gson, json, sugarorm
Solution
Replace the key "id" in the string to be "nutrition_day_id". You can use the id json and the id sql.
jsonObject.getJSONObject("nutrition_day").toString().replace("\"id\"","\"nutrition_day_id\"")
Problem
I'm using `GSON` to create a `SugarRecord` object from a json response. The API I'm using returns a field called "id", but the type of "id" is a string, not a long (the backend is using mongo). Below is the code I'm using: ``` Gson gson = new Gson(); // Or use new GsonBuilder().create(); NutritionPlan target = gson.fromJson(jsonObject.getJSONObject("nutrition_day").toString(), NutritionPlan.class); ``` Below is my json response: ``` { "nutrition_day": { "id": "5342b4163865660012ab0000", "start_on": "2014-04-08", "protein_target": 157, "sodium_limit": 2000 } ``` Is there a good way to handle this scenario? I tried ``` @Ignore long id; ``` and ``` @SerializedName("id") String nutrition_plan_id; ``` in my model, but neither helped. Anyone familiar with Sugar ORM, and know how to deal with an `id` field that isn't a long?