-
Notifications
You must be signed in to change notification settings - Fork 511
Alias names / Different keynames after serialization #121
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
Comments
Hi @weeco! Thanks for the detailed report! In your example, you use Based on your description, I would expect the inputs being @Alias({ from: 'cardName' }, { toClassOnly: true })
@Transform(cardResolver)
public id: number; Effect: // input => value
{ id: 342 } => { id: 342 }
// input => value (via alias then transform)
{ cardName: 'name-of-car' } => { id: 342 } Did I understand you correctly? If this is your desired goal, there is no way of doing this at the moment. However, this request makes sense and there is already a similar request in #99. So this can be implemented, but later, first I want to finish class-validator and move to class-transformer after. |
Yes you understood it perfectly well, that's exactly the desired behaviour. |
Wonder if this can be done, 2 years pasted and it feels like it'd be a handy feature :) |
Posting on issues asking whether it will be added will never make the process faster. Today I spent 10 hours answering questions which at least a third of them doesn't even take the time to read the documentation. So if you want to make this feature get implemented faster, you can always
|
The use case:
I use this library for a REST API wrapper where I map the returned JSON responses to my classes. I am struggling with just one specific case.
The REST Api returns a
cardName
, but unfortunately nocardId
which could be used to retrieve thecardName
. However I can resolve thecardId
by a given cardName and I highly prefer to store cardIds instead of the cardNames in my database.The code:
The problem:
This requirement is a challenge though, because now the library is supposed to handle two different schemas. One is the REST Api which returns the cardName and the other is my database which returns the cardId.
While my
@Transform
function is not an issue (it can handle both json inputs and recognizes the difference using the type), I need some sort ofalias
, since the input json can be either:or
My question:
Can I achieve this with the given library features or does it make sense to add an alias feature?
The text was updated successfully, but these errors were encountered: