You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#124#96 were implemented on 0.9.0, but fail to take into account some scenarios. #126 takes care of this at a Model level. This ticket address the more specific property level handling.
The Problem
There are times when incoming JSON from a service may not be in the the shape we want. By shape, I mean that it's not simply field name transformation that we want to accomplish, it's also morphing the shape of the incoming JSON such that it results in a Model that has a different shape.
Incoming JSON:
const data = {
"first_name": "john",
"source": {
"address_1": "123 main st",
"address_2": "suite 100
}
}
Desired result from SomeModel.fromJson(data, 'source1'):
{
firstName: 'john',
address: '123 main st suite 100"
}
It may also be the case that the incoming JSON comes in multiple shapes depending on the source, but the resulting Model is common to those various sources. For example the following might also be incoming JSON from a different source that would result in SomeModel above.
const data = {
"firstName": "john",
"address": "123 main st suite 100"
}
And it should be the case that you can marshall a Model back to its original shape (someModel.toJson('source1')):
For formatFromJson, val will be the child object source (which fromJson will not recurse into).
For formatToJson, val will be the address string of the model, and a new parameter, obj will be passed in, which is the root of the object being built.
The text was updated successfully, but these errors were encountered:
#124 #96 were implemented on 0.9.0, but fail to take into account some scenarios.
#126 takes care of this at a Model level. This ticket address the more specific property level handling.
The Problem
There are times when incoming JSON from a service may not be in the the shape we want. By shape, I mean that it's not simply field name transformation that we want to accomplish, it's also morphing the shape of the incoming JSON such that it results in a Model that has a different shape.
Incoming JSON:
Desired result from
SomeModel.fromJson(data, 'source1')
:It may also be the case that the incoming JSON comes in multiple shapes depending on the source, but the resulting Model is common to those various sources. For example the following might also be incoming JSON from a different source that would result in
SomeModel
above.And it should be the case that you can marshall a Model back to its original shape (
someModel.toJson('source1')
):or with
someModel.toJson()
:Proposed API:
For
formatFromJson
,val
will be the child objectsource
(whichfromJson
will not recurse into).For
formatToJson
,val
will be the address string of the model, and a new parameter,obj
will be passed in, which is the root of the object being built.The text was updated successfully, but these errors were encountered: