Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deserialize arrays #12

Open
Geschan opened this issue Feb 17, 2017 · 7 comments
Open

deserialize arrays #12

Geschan opened this issue Feb 17, 2017 · 7 comments

Comments

@Geschan
Copy link

Geschan commented Feb 17, 2017

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?

@WilliamChelman
Copy link

WilliamChelman commented Mar 2, 2017

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));

@jf3096
Copy link
Owner

jf3096 commented Mar 3, 2017

@Geschan for now the first parameter of the deserialize method accept object. I will consider your case and add this feature soon.

@Vertygo
Copy link

Vertygo commented Mar 12, 2017

+1 for deserializing arrays

@rreid116
Copy link

rreid116 commented Sep 8, 2017

Was there a working solution for deserializing arrays, the solution @WilliamChelman provided produced an error "json is not a function"

@WilliamChelman
Copy link

@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))

@daveo1001
Copy link

+1 for deserialize array

@michaelsync
Copy link

Any update on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants