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 json doesn' work for a class with parent constructor #40

Open
pierre03 opened this issue Apr 3, 2018 · 0 comments
Open

Comments

@pierre03
Copy link

pierre03 commented Apr 3, 2018

Hello,
Here is my problem, i have a json object, which is like that:

{"commandId":"1","result":"ok","devices":[{"PluginId":"Device 1","DisplayName":"Device 1"},{"PluginId":"Device 2","DisplayName":"Device 2"}],"message":""}

The commandId and result is defined in GeneralResponse, for the other parameters, here is the class:

export class PluginParam {
  @JsonProperty('**PluginId**')
  public **pluginId**: string;
  @JsonProperty('**DisplayName**')
  public **displayName**: string;

  constructor() {
    this.PluginId = undefined;
    this.DisplayName = undefined;
  }
}
export class GetDevicesResponse extends GeneralResponse {
  @JsonProperty({clazz: PluginParam, name: 'devices'})
  public devices: PluginParam[];
  public message: string;
  constructor() {
    super();
    this.devices = void 0;
    this.message = void 0;
  }
}

When i get the jsonobject, i do this to use it:

processGetDevice(object: GetDevicesResponse): void {
  console.log('processGetDevice, devices', object.devices);
  console.log('processGetDevice', object);
  console.log('processGetDevice, devices 0 ', object.devices[0].PluginId);
  if (object.result === 'ok' || object.devices.length > 0) {
    this.selectedDevice = object.devices[0].PluginId;
      } else if (object.result === 'error') {
    this.toasterService.pop('error', 'processGetDevice', object.message);
  }
}

But i can not get the pluginId and the displayName, it seems that the JsonProperty doesn't work here.
When i replace pluginId by PluginId and displayName by DisplayName, everything is ok.
Do you have any idea, please? Is it related to the function super()?
Thank you.

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

1 participant