def build(self) -> type:
        """
        Build a subclass of `MappingJSONEncoder`.
        :return: the built subclass
        """
        def _get_property_mappings(encoder: MappingJSONEncoder) -> List[JsonPropertyMapping]:
            return _get_all_property_mappings(encoder, self.mappings, self.superclasses)

        def get_serializable_cls(encoder: MappingJSONEncoder) -> type:
            return self.target_cls

        def default(encoder: MappingJSONEncoder, serializable):
            if serializable is None:
                # Fix for #18
                return None
            elif isinstance(serializable, List):
                # Fix for #8
                return [encoder.default(item) for item in serializable]
            else:
                # Sort subclasses so subclass' default method is called last
                superclasses_as_list = list(self.superclasses)
                superclasses_as_list.sort(key=lambda superclass: 1 if superclass == MappingJSONEncoder else -1)

                encoded_combined = {}
                for superclass in superclasses_as_list:
                    encoded = superclass.default(encoder, serializable)
                    encoded_combined.update(encoded)

                return encoded_combined

        return type(
            "%sDynamicMappingJSONEncoder" % self.target_cls.__name__,
            self.superclasses,
            {
                "_get_property_mappings": _get_property_mappings,
                "_get_serializable_cls": get_serializable_cls,
                "default": default
            }
        )
def build ( self ) -> type : def _get_property_mappings ( encoder : MappingJSONEncoder ) -> List [ JsonPropertyMapping ] : return _get_all_property_mappings ( encoder , self . mappings , self . superclasses ) def get_serializable_cls ( encoder : MappingJSONEncoder ) -> type : return self . target_cls def default ( encoder : MappingJSONEncoder , serializable ) : if serializable is None : return None elif isinstance ( serializable , List ) : return [ encoder . default ( item ) for item in serializable ] else : superclasses_as_list = list ( self . superclasses ) superclasses_as_list . sort ( key = lambda superclass : 1 if superclass == MappingJSONEncoder else - 1 ) encoded_combined = { } for superclass in superclasses_as_list : encoded = superclass . default ( encoder , serializable ) encoded_combined . update ( encoded ) return encoded_combined return type ( "%sDynamicMappingJSONEncoder" % self . target_cls . __name__ , self . superclasses , { "_get_property_mappings" : _get_property_mappings , "_get_serializable_cls" : get_serializable_cls , "default" : default } )
Build a subclass of `MappingJSONEncoder`.
        :return: the built subclass