【问题标题】:Angular HttpClient SerializedName of fields in model模型中字段的 Angular HttpClient SerializedName
【发布时间】:2020-10-31 00:35:12
【问题描述】:

有没有办法在模型类字段中添加一些属性/注释来标记来自服务器的 json 响应中字段的序列化名称(基于 @SerializedName 来自 Gson 的问题)?

例如来自服务器的响应包含 start_datesome_date 之类的字段,我想在我的模型中包含名为 startDateacquisitionDate 的字段。在我的响应模型中的 Spring 服务器字段中使用 @SerializedName("start_date") 进行注释。

我正在像这样使用Angular 10HttpClient

httpClient.get<MyModel[]>(environment.apiUrl + '/getData')
            .pipe(map(models => models.map(m => Object.assign(new MyModel(), m)));

【问题讨论】:

    标签: angular typescript angular-httpclient angular-json


    【解决方案1】:

    我找到并使用了库https://github.com/typestack/class-transformer 此外,如果有人需要,还有类似的库 https://github.com/weichx/cerializehttps://github.com/kmathy/cerializr

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多