-
Notifications
You must be signed in to change notification settings - Fork 27
Description
The standard JSONEncoder that is used to create the JSON input for a MiniZinc model ensures that an IntEnum is always represented using its integer representation: https://github.com/python/cpython/blob/3.9/Lib/json/encoder.py#L309-L313
Normally the JSON representation can be customised in the default member function of MZNJSONEncoder, but because IntEnum inherits from int, the representation is part of the base types of JSONEncoder that is directly implemented in the encoder library (and a C backend)
This is incorrect as an input for a MiniZinc enum, where a JSON object {"e": "some_name"} is expected and an integer will not be accepted.
workaround
A current workaround is to use an Enum in Python, or to use the actual matching integers in the MiniZinc model.
possible solutions
The following solutions could be considered:
- A more customisable JSONEncoder that gives us more freedom to change the JSON representation of
IntEnum - Find a way to consistently change the
_intstrfunction (both in the Python and C implementation): https://github.com/python/cpython/blob/3.9/Lib/json/encoder.py#L271 - Change the data when it is set to be in the required format.
The last solution seems more likely, as I'm currently unaware of a better JSON Encoder alternative and several attempts are the second method have failed.