Closed yaymukund closed 10 years ago
I have multiple ways of serializing data because of a legacy API server:
Address = Ep.Model.extend({ street: Ep.attr('string'), city: Ep.attr('string'), state: Ep.attr('string') }); // Legacy API server ships JSON like: { matched_addresses: [ {uglyStreet: '...', oldCity: '...', funkyState: '...'} ] }; // Shiny new API server ships what you'd expect: { addresses: [ {street: '...', city: '...', state: '...'} ] };
I'd like both matched_addresses and addresses to deserialize to an Address instance. To do this, I could create a custom serializer:
matched_addresses
addresses
Address
MatchedAddressSerializer = Ep.ModelSerializer.extend({ // Without my PR, this gets overwritten in `serializerFor` typeKey: 'address', deserialize: function(json) { return this._super({ street: json.uglyStreet, city: json.oldCity, state: json.funkyState }); } });
Right now, this isn't possible because serializerFor overwrites typeKey. I just added a check.
serializerFor
typeKey
Thanks for the test!
np, thanks for the help with the testing stuff!
I have multiple ways of serializing data because of a legacy API server:
I'd like both
matched_addresses
andaddresses
to deserialize to anAddress
instance. To do this, I could create a custom serializer:Right now, this isn't possible because
serializerFor
overwritestypeKey
. I just added a check.