from typing import Dict
from typing import Callable
from typing import Any
import json


def build_dumber(encoders: Dict[str, Callable[[Any], Any]]):
  """
  Build a json dumber function from a map of encoders for fields that needs to be encoded differently.

  Args:
    encoders (Dict[str, Callable[[Any], Any]]): The docoder map
  """
  def dumbs(obj: dict, *, default) -> str:
    """
    The json dumbs function for converting dict to json

    Args:
      obj (dict): The dict to be dumped

    Returns:
      str: The converted json string
    """
    # run decoders on the object
    for field, encode in encoders.items():
      # decode the field value
      if field in obj and obj[field] is not None:
        obj[field] = encode(obj[field])
    return json.dumps(obj, default=default)
  return dumbs