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

Deserialization issue #566

Closed
vany0114 opened this issue May 6, 2024 · 0 comments
Closed

Deserialization issue #566

vany0114 opened this issue May 6, 2024 · 0 comments

Comments

@vany0114
Copy link

vany0114 commented May 6, 2024

Hi guys, I'm having trouble deserializing a payload.

{
  SiteUID: 'b453462e-80fe-4722-bf82-b4eb2becd99f',
  CheckNumber: 456,
  Guest: {
    FirstName: 'Geo',
    LastName: '',
    PhoneNumbers: [
      {
        PhoneNumberString: '57603291912',
        PhoneNumber: 57603291912,
        Sort: 1,
        Type: 'Mobile',
      },
      {
        PhoneNumberString: '+57603291912',
        PhoneNumber: 57603291912,
        Sort: 2,
        Type: 'Whatever',
      },
    ],
    Addresses: [],
    ...
  },
  Vehicle: {
    Make: 'Ford',
    Model: 'Explorer',
    Color: 'White',
  }
}

The issue is with the Guest object within the payload. The Guest object is not being deserialized properly. The QsrVehicle class is supposed to receive the Guest object in its constructor, but for some reason, it is always undefined. I tried using the "marshal" method with the type annotation, and it worked fine. Interestingly, if I change the Guest object's name to camel case (guest), and update the QsrVehicle class to receive guest instead of Guest (the property name), the deserialization works fine. However, I am not sure why the deserialization works for the SiteUID, Vehicle, and CheckNumber fields, even though they are also in Pascal case.

export class QsrVehicle extends QsrVehicleIdentifier {
  constructor(
    @f.type(GuestVehicle) public Vehicle: GuestVehicle,
    @f.type(Guest) public Guest: Guest,
    @f public SiteUID: string,
    @f public CheckNumber: string
  ) {
    super(Vehicle, Guest, SiteUID);
  }
}

image

I have tried using a custom naming strategy to turn property names into camel case (and obviously I've also changed the class members to camel case), but it didn't work either. I have created a repro example, which you can find at https://github.com/juanda147/deepkit-test/blob/d31b86bfa11a65e30eb68aa06b75d20a3e7deb53/playground/Marshal/DeserializeGenericV2.ts#L345.

Thanks in advance!

@marcj marcj closed this as completed in 16ba17d May 7, 2024
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