henrytseng/dataobject-parser

Merge nested objects together

OliverFischer opened this issue · 1 comments

Hi altogether, I have a simple question:

DataObjectParser.prototype.set overwrites property sections complete when adding properties to the resulting model. Is it possible to add a merge mechanism like $obj[$key] = _.merge($obj[$key]||{},$data); in line 35 in dataobject-parser.js? So nested properties can survive in the merge process like in this example:

dataobjParser.set('a',{projectId : 'common',route : 'a',fragment:{key : 'looser', anotherProp : 'I will survive'}})
dataobjParser.set('a', {projectId : 1, route : 'a',fragment:{key : 'winner'}})

I would like to see the the property 'anotherProp' from the first object even when overwriting the second one...

Greetings Olli

Not comfortable with adjusting behavior of set method but we could add a merge method so as to fit your needs.