class-transformer icon indicating copy to clipboard operation
class-transformer copied to clipboard

feat: support dot notation for nested objects in @Expose decorator

Open NoNameProvided opened this issue 7 years ago • 3 comments

Currently @Expose decorator supports only flat re-naming, there were multiple requests to add support nested exposing.

Example:

class Example {
  @Expose('user.fullName')
  name: string = 'Test Name';
}

const raw = { user: { fullName: 'Test Name' }}
const instance = new Example();

plainToClass(Example, raw) // returns Example { name: 'Test Name' }
classToPlain(instance) // returns { user: { fullName: 'Test Name' }}

NoNameProvided avatar Oct 26 '18 18:10 NoNameProvided

Any updates?

ziadalzarka avatar Apr 06 '19 12:04 ziadalzarka

This feature not implemented yet?

sadra avatar May 31 '20 18:05 sadra

I would need this feature in something I'm doing, and I think I will discard the class-transformer for what I'm doing right now, Maybe is better to have the option of an array, more than . notation, something like expose(["user","fullName"])

dotNotation should work for my case, but I think it's allways more safe to use an array.

Dracks avatar Sep 19 '22 17:09 Dracks

This would be really useful for working with json:api objects.

dimas-cyriaco avatar Feb 14 '23 14:02 dimas-cyriaco