-
-
Notifications
You must be signed in to change notification settings - Fork 286
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
[BUG] TypeError in JsonDeserializer when handling Array of Maps #2761
Comments
Hello @ochrstn I think your example isn't valid. Try that: class Test {
@Required()
@CollectionOf(Map)
fields: Array<Map<string, string>> = [];
} See you |
same problem |
So @ochrstn these usage isn't officially supported by tsed in fact, because describing an array of map of string (something else isn't possible with decorators). I'll take a time to give you a workaround. |
Thanks for clarifying. Thats my workaround so far: @AdditionalProperties(true)
class Field {
[key: string]: string;
}
class Test {
@Required()
@CollectionOf(Field)
fields: Array<Field> = [];
} This works for my usecase so far. Any additional ideas? |
Maybe this workaround should works: const schema = array().items(map().additionalProperties(String))
class Test {
@Schema(schema.toJSON())
@CollectionOf(Map)
@OnDeserialize(o => o.map((i) => new Map(Object.entries(i))))
@OnSerialize(o => o.map(i => Object.fromEntries(i.entries())))
fields: Map<string, string>[] = [];
} |
But if you don't care about having an array of map: const schema = array().items(object().additionalProperties(string()))
class Test {
@Schema(schema.toJSON())
@CollectionOf(Object)
fields: Record<string, string>[] = [];
} |
…or Array<Map<string, string>> type Closes: #2761
🎉 This issue has been resolved in version 7.77.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Describe the bug
When using Ts.ED to handle an array of maps, a TypeError is thrown by the JsonDeserializer
To Reproduce
Expected behavior
Should deserialize correctly
Code snippets
No response
Repository URL example
No response
OS
macOS
Node version
v18.18.2
Library version
7.77.0
Additional context
No response
The text was updated successfully, but these errors were encountered: