Skip to content

Support serialization for enums #6

@alonbl

Description

@alonbl

Hi,

I have the following typescript:

export enum ResponseCode {
  OK = 'OK',
  ERROR = 'ERROR',
  NOT_LOGGED_IN = 'NOT_LOGGED_IN',
}

The conversion is:

class ResponseCode(Enum):
    OK = 'OK'
    ERROR = 'ERROR'
    NOT_LOGGED_IN = 'NOT_LOGGED_IN'

The result cannot be serialized into json using standard tools as Enum is not serializable.

TypeError: Object of type ResponseCode is not JSON serializable

For integers the IntEnum can be used as base class and is working.

For string based enums, the following is working:

class ResponseCode(str, Enum):
    OK = 'OK'
    ERROR = 'ERROR'
    NOT_LOGGED_IN = 'NOT_LOGGED_IN'

Please consider supporting.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions