I have code that looks something like this using Fast API:
class EnumTestT(Enum):
test_t_value = 0
object = {
test: test_t_value
}
enum_mapping = {
test_t_value: "Test"
}
def enum_encoder(val: EnumTestT) -> str:
return enum_mapping[val]
custom_encoder = {
EnumTestT: enum_encoder
}
@app.get("/test")
async def test_get():
return jsonable_encoder(object, custom_encoder=custom_encoder)
The issue is that jsonable_encoder
applies custom encoders after the defaults. Is there any way to apply them before the default encoders. Because for an Enum
and any derived classes the value of the enum is reported instead of the mapped value.