apple / app-store-server-library-python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inherit enum classes with primiary types

elonzh opened this issue · comments

Currently, the package defines enums by inheriting enum.Enum class, this will cause TypeError when serializing it to json without a default function.

See:

Hello @elonzh, could you please provide an example of this error when using the App Store Server API client?

Here is an example:

import json
from appstoreserverlibrary.models.AutoRenewStatus import AutoRenewStatus
from enum import IntEnum

class AutoRenewStatusWithInt(IntEnum):
    """
    The renewal status for an auto-renewable subscription.
    
    https://developer.apple.com/documentation/appstoreserverapi/autorenewstatus
    """
    OFF = 0
    ON = 1

# OK
print(json.dumps({
    "status": AutoRenewStatusWithInt.ON
}))

# TypeError: Object of type AutoRenewStatus is not JSON serializable
print(json.dumps({
    "status": AutoRenewStatus.ON
}))