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:
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.
The standard
JSONEncoderthat is used to create the JSON input for a MiniZinc model ensures that anIntEnumis always represented using its integer representation: https://github.com/python/cpython/blob/3.9/Lib/json/encoder.py#L309-L313Normally the JSON representation can be customised in the
defaultmember function ofMZNJSONEncoder, but becauseIntEnuminherits fromint, the representation is part of the base types ofJSONEncoderthat 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
Enumin Python, or to use the actual matching integers in the MiniZinc model.possible solutions
The following solutions could be considered:
IntEnum_intstrfunction (both in the Python and C implementation): https://github.com/python/cpython/blob/3.9/Lib/json/encoder.py#L271The 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.