[BUG] Enum on nested class causes stack loop error when serialized
See original GitHub issueInformation
- Version: 6.64.1
I try to use an enum property on my nested model and I have a “RangeError: Maximum call stack size exceeded” when I serialize it. I don’t have error when the enum property is just plain text not a type.
Example
My model:
import { Enum, Property, Required } from "@tsed/schema";
export enum EnumValue {
One = "one",
Two = "two",
}
export class NestedEnum {
@Required()
@Enum(EnumValue)
value: EnumValue;
}
export class TestNestedEnum {
@Property()
nested: NestedEnum;
}
export class NestedEnum2 {
@Required()
@Enum("one", "two")
value: "one" | "two";
}
export class TestNestedEnum2 {
@Property()
nested: NestedEnum2;
}
My controller:
import {Controller, Get} from "@tsed/common";
import {Tags} from "@tsed/schema";
import { EnumValue, NestedEnum, TestNestedEnum, NestedEnum2, TestNestedEnum2 } from "../models/TestNestEnum";
@Controller("/enum")
@Tags("enum")
export class TestEnumController {
@Get("/bug")
async getBug(): Promise<TestNestedEnum> {
const test = new TestNestedEnum();
const nested = new NestedEnum();
nested.value = EnumValue.One;
test.nested = nested;
return test;
}
@Get("/ok")
async getOK(): Promise<TestNestedEnum2> {
const test = new TestNestedEnum2();
const nested = new NestedEnum2();
nested.value = EnumValue.One;
test.nested = nested;
return test;
}
}
If I call /enum/ok no problem, but /enum/bug throws this error when the model is serialized:
[ERROR] [TSED] - RangeError: Maximum call stack size exceeded
at serialize (...\node_modules\@tsed\json-mapper\src\utils\serialize.ts:132:23)
at ...\node_modules\@tsed\json-mapper\src\utils\serialize.ts:100:14
at Array.reduce (<anonymous>)
at toObject (...\node_modules\@tsed\json-mapper\src\utils\serialize.ts:97:35)
at serialize (...\node_modules\@tsed\json-mapper\src\utils\serialize.ts:154:68)
at ...\node_modules\@tsed\json-mapper\src\utils\serialize.ts:100:14
at Array.reduce (<anonymous>)
...
Acceptance criteria
- A nested enum can be serialized
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
Top Results From Across the Web
Possible compiler bug related to deeply nested enums
In searching for a solution we stumbled across an old Swift bug which sounded very similar. EXC_BAD_ACCESS crashes, only on device, involving ......
Read more >Private field of enum class cannot be accessed by Nested enum
When a nested enum class tries to access the outer, it gets an error message about being unable to access a non-static field...
Read more >Bug descriptions — spotbugs 4.7.3 documentation
This Serializable class is an inner class. Any attempt to serialize it will also serialize the associated outer instance. The outer instance is...
Read more >Bug Patterns - Error Prone
Importing nested classes/static methods/static fields with commonly-used names can make code harder to read, because it may not be clear from the context ......
Read more >Java static code analysis: Fields in a "Serializable" class ...
This rule raises an issue on non- Serializable fields, and on collection fields when they are not private (because they could be assigned...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
🎉 This issue has been resolved in version 6.73.2 🎉
The release is available on:
v6.73.2
Your semantic-release bot 📦🚀
🎉 This issue has been resolved in version 7.0.0-alpha.2 🎉
The release is available on:
v7.0.0-alpha.2
Your semantic-release bot 📦🚀