Properly handle nested types when converting to map.