【问题标题】:Flutter json_serializable different reference key name switch requestFlutter json_serializable 不同引用键名切换请求
【发布时间】:2021-06-10 16:49:11
【问题描述】:

我在问一个问题,但没有找到类似的帖子。

我解释一下,我使用json_serializable,但是webservice通过不同的名称键提供了一些相同类型对象的信息,例如:

@JsonSerializable(explicitToJson: true)
class Group {
  Group(
      this.id,
      this.name,
      this.owner,
      this.description);

  int id;
  String name;
  User owner; //Here owner are only "id" and "name"
  String? description;

...
}

@JsonSerializable()
class User {
  User(this.uid, this.nom, this.mail, this.prenom);

  String? uid;
  late String mail;
  String nom;
  String? prenom;

...

所以“id”和“uid”是不同的键,但值相同,“name”和“nom”的含义相同。

有什么方法可以指示生成器这可以是相同值的不同键名..?

【问题讨论】:

    标签: flutter json-serializable


    【解决方案1】:

    我的解决方案是设置两个不同的变量,其中一个可以为 NULL

    【讨论】:

      猜你喜欢
      • 2022-01-13
      • 2021-09-24
      • 2012-08-29
      • 1970-01-01
      • 2021-08-04
      • 2019-10-11
      • 2019-09-18
      • 2019-05-18
      • 1970-01-01
      相关资源
      最近更新 更多