question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

id field not a long

See original GitHub issue

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; in my model, but that didn’t help. How can I change the type of the id?

Issue Analytics

  • State:open
  • Created 9 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
gabriel01commented, Dec 9, 2014

Same problem here. I have to agree to tanzim. Even better would be something like sugarId to make it more unique?!

0reactions
tanzimcommented, Oct 17, 2014

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 ?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found