question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Enum on nested class causes stack loop error when serialized

See original GitHub issue

Information

  • 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:closed
  • Created 2 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
Romakitacommented, Oct 2, 2021

🎉 This issue has been resolved in version 6.73.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

0reactions
Romakitacommented, Oct 9, 2021

🎉 This issue has been resolved in version 7.0.0-alpha.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found