from enum import Enum


def _defaultMetaSerialize(value):
    """
    Is called by `json.dumps()` whenever it encounters an object it does 
    not know how to serialize. Currently handles:

    1. Any object with a `serialize()` method, which is assumed to be a helper
       method.
    1. `numpy` scalars as well as `ndarray`
    2. Python `Enum` objects which are serialized as strings in the form 
       ``'Enum.{object.__class__.__name__}.{object.name}'``. E.g. ``'Enum.Axis.X'``.
    """
    if hasattr(value, 'serialize'):
        return value.serialize()
    elif hasattr(value, '__array_interface__'):
        # Checking for '__array_interface__' also sanitizes numpy scalars
        # like np.float32 or np.int32
        return value.tolist()
    elif isinstance(value, Enum):
        return 'Enum.{}.{}'.format(value.__class__.__name__, value.name)
    else:
        raise TypeError('Unhandled type for JSON serialization: {}'.format(type(value)))