deserialize arrays
I tried to deserialize an array of items like this:
this.authHttp.get('/items')
.map(response => deserialize(Item[], response.json()))
.catch(this.handleError)
.subscribe(data => console.log(data));
But the compiler didn't like it. How can I fix this?
You could try something like
this.authHttp.get('/items')
.map(response => response.json().map(item => deserialize(Item, item)))
.catch(this.handleError)
.subscribe(data => console.log(data));
@Geschan for now the first parameter of the deserialize method accept object. I will consider your case and add this feature soon.
+1 for deserializing arrays
Was there a working solution for deserializing arrays, the solution @WilliamChelman provided produced an error "json is not a function"
@rreid116 The this.authHttp.get('/items') return a promise with a response object with the json method on it but you might not be using that particular service / library, do you ? The point of the answer is that, if you have an array (and I mean a real Array, not a string representation), you could always do something like:
let myArray = [...];
let myMappedArray = myArray.map(obj => deserialize(MyClass, obj))
+1 for deserialize array
Any update on this issue?