weichx / cerialize

Easy serialization through ES7/Typescript annotations
MIT License
257 stars 28 forks source link

is it works with HttpClient ? #92

Open Calion54 opened 5 years ago

Calion54 commented 5 years ago

Hi, I'm using HttpClient from Angular 6 and I would like to use your librairie to transform snakecase to camelcase but it's doesn't works...

My Model :

export class Set {
  @autoserializeAs('set_id') setId: string;
  @serialize year: number;
  @serialize number: number;
  @serialize theme: string;
  @serialize name: string;
  @serialize image: string;
}

My service :

  getSet(setId): Observable<Set> {
    return this.httpClient.get<Set>(this.setsUrl + setId + '/');
  }

is it possible or not ???

weichx commented 5 years ago

I don't know anything about HttpClient or Angular but I don't see why it wouldn't work. You probably need to actually call Serialize/Deserialize though, your sample doesn't invoke Cerialize

adsau59 commented 5 years ago

it works, amazing script dude keep up the good work 😄

you can close close the issue now

prudnikov commented 5 years ago

@Calion54 you can call map operator to deserialize. I suppose Set is you data class.

getSet(setId): Observable<Set> {
  return this.httpClient.get<JsonObject>(this.setsUrl + setId + '/')
    .pipe(map(data => Deserialize<Set>(data, Set)));
}