Serializing model ids as numbers


#1

I’m in the process of hooking Ember Data up to an API that uses numbers for IDs. Payloads from the API are deserialized without a problem, but unfortunately when models are sent to the API all ids are serialized as strings.

I understand this is because the store treats all ids as strings internally, but is there any easy way to convert them back to numbers during serialization?

As I need model ids (when included), relationship ids (i.e. belongsTo and hasMany) and the ids within embedded models to all be numbers the only way I can see to do this is to override DS.RESTSerializer's serialize method - this works, but having to reimplement all the serialization logic seems a bit unnecessary.

Am I missing an easier solution? Any suggestions?


#2

FWIW it looks like there used to be a serializeId method that did pretty much what i’m after but it was removed in this commit: https://github.com/emberjs/data/commit/1c55815c37e9946300708634c91c44414dd9a695.


#3

What is the current solution for this issue? How do you handle it?