hello (sorry for my english)
I'm working on angularjs front end website consuming web service producing json with SPRING MVC. The spring mvc use JsonIdentityInfo option for seralization so each object are writed only one time in the json and each other time a reference is used, example her there is 2 "computer" using the same object "component", so spring put an id to the first component ("@componentID": 2) and for the second component juste the id ( 2 ) :
[
{
"@computerID": 1,
"component": {
"@componentID": 2,
"processor": 2,
"ram": "8g",
"harddrive": "wd"
}
},
{
"@computerID": 3,
"component": 2
}
]
what i want :
[
{
"@computerID": 1,
"owner" : "Mister B",
"component": {
"@componentID": 2,
"processor": 2,
"ram": "8g",
"harddrive": "wd"
}
},
{
"@computerID": 3,
"owner" : "Mister A",
"component": {
"@componentID": 2,
"processor": 2,
"ram": "8g",
"harddrive": "wd"
}
}
]
I make many search for a code who do this but i didn't find anythink.
I can't edit the web service for removing this behavor. Can i edit the json on client side with javascript or jquery (or another librairie) to replace references with the real referenced object ? ( the data are in fact more complex and deeper, i have 3 level of sub object in object).
thanks a lot.
Split all the array members into new arrays: those with a full
component
attribute (not just a number) and those without. Loop through the remaining original members which should have just numericalcomponent
attributes, then look up the corresponding@componentID
from the "good" array, and do some copying and moving.You'll note I actually made THREE arrays, but only two end up populated:
final
has your good new objects, and the other one (bad
) is a catch-all for objects without a component attribute, or for whose component number a corresponding @componentID cannot be found.