id field not a long
See original GitHub issueI’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; in my model, but that didn’t help. How can I change the type of the id?
Issue Analytics
- State:
- Created 9 years ago
- Comments:6
Top Results From Across the Web
Id field as long type - solr - Stack Overflow
Is there any way to make my id field type long? I need it this way to avoid too much mapping. solr ·...
Read more >Solved: Max Length for User ID field - ServiceNow Community
Solved: Wondering what the max length I can extend the user ID field too. By default it is set to 40. I have...
Read more >Owner Id Field Value Too large max length:18 Error
When I run a query on this it gives me a value for this user that is 20 characters long, in fact it...
Read more >Missing ID field in SharePoint - Power Platform Community
Solved: The ID field is auto-filled and viewable after submitting my PowerApps form in the app however, the field/column does not appear in...
Read more >000643: Invalid unique ID field.—ArcGIS Pro | Documentation
This error is triggered when (1) the unique ID field specified is not of type integer (short or long) or (2) the values...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Same problem here. I have to agree to tanzim. Even better would be something like sugarId to make it more unique?!
IMO, the use of id as the name of the id field in sugar record is rather problematic. Lots of database design use id as a field name and they aren’t always an integer type, so using id as the default for records seems wrong. So today, if I have a record that’s like
class Employee { String id; … }
Querying for an Employee crashes the underlying SQLite implementation in Android. A sensible thing would be to to use _id instead of id for the auto generated id field in Sugar? What do you think @whoshuu ?