apache/beam · error · IllegalArgumentException

Unsupported Beam to JSON type: {}

Error message

Unsupported Beam to JSON type: {}

What it means

JsonUtils.jsonPropertyFromBeamType maps Beam Schema.FieldTypes to JSON-Schema property schemas. The switch only supports a fixed set of Beam types; any other FieldType (e.g. logical types or unmapped types) hits the default branch and throws this IllegalArgumentException. It indicates the Beam-to-JSON conversion does not cover the given type.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/utils/JsonUtils.java:191

      case STRING:
        propertySchema = StringSchema.builder();
        break;
      case BOOLEAN:
        propertySchema = BooleanSchema.builder();
        break;
      case ARRAY:
      case ITERABLE:
        Schema.FieldType fieldType = Optional.ofNullable(beamType.getCollectionElementType()).get();
        propertySchema = ArraySchema.builder().allItemSchema(jsonPropertyFromBeamType(fieldType));
        break;
      case ROW:
        Schema rowSchema = Optional.ofNullable(beamType.getRowSchema()).get();
        propertySchema = jsonSchemaBuilderFromBeamSchema(rowSchema);
        break;

        // add more Beam to JSON types
      default:
        throw new IllegalArgumentException("Unsupported Beam to JSON type: " + beamType);
    }

    if (beamType.getNullable()) {
      propertySchema = propertySchema.nullable(true);
    }

    return propertySchema.build();
  }

  public static Schema beamSchemaFromJsonSchema(String jsonSchemaStr) {
    org.everit.json.schema.ObjectSchema jsonSchema = jsonSchemaFromString(jsonSchemaStr);
    return beamSchemaFromJsonSchema(jsonSchema);
  }

  private static Schema beamSchemaFromJsonSchema(org.everit.json.schema.ObjectSchema jsonSchema) {
    Schema.Builder beamSchemaBuilder = Schema.builder();
    Map<String, org.everit.json.schema.Schema> properties =
        new HashMap<>(jsonSchema.getPropertySchemas());

View on GitHub (pinned to 12126d8942)

Solutions

  1. Change the Beam schema field to a supported type (string, integer, number, boolean, row, array, map as supported)
  2. Add a mapping case in JsonUtils.jsonPropertyFromBeamType for the new Beam type (the comment explicitly says 'add more Beam to JSON types')
  3. Pre-check field types before conversion and skip/translate unsupported ones
  4. Wrap conversion in try-catch for IllegalArgumentException and surface a clearer per-field message

Example fix

// before
Schema.FieldType t = Schema.FieldType.logicalType(new MyCustomType());
JsonUtils.jsonPropertyFromBeamType(t); // throws
// after
Schema.FieldType t = Schema.FieldType.STRING; // or add a case for the logical type in JsonUtils
Defensive patterns

Strategy: validation

Validate before calling

static boolean isJsonMappable(Schema.FieldType t) {
  switch (t.getTypeName()) {
    case STRING: case INT64: case INT32: case DOUBLE: case BOOLEAN:
    case ROW: case ARRAY: case MAP: return true;
    default: return false;
  }
}
// reject fields up-front:
schema.getFields().stream()
  .filter(f -> !isJsonMappable(f.getType()))
  .forEach(f -> { throw new IllegalArgumentException("Field " + f.getName() + " unsupported for JSON"); });

Type guard

static boolean isPrimitiveOrStructured(Schema.FieldType t) {
  return t.getTypeName().isPrimitiveType() || t.getTypeName() == Schema.TypeName.ROW;
}

Try / catch

try {
  JsonSchema js = jsonPropertyFromBeamType(beamType);
} catch (IllegalArgumentException e) {
  log.warn("Skipping unmappable Beam type: {}", e.getMessage());
}

Prevention

When it happens

Trigger: Calling JsonUtils.toJsonObject/schema conversion APIs (e.g. JsonUtils.fromBeamSchema paths that build JSON Schema) with a Beam field whose FieldType is not one of the explicitly mapped types (BYTES, logical types, or other unsupported kinds).

Common situations: Adding a new field type (e.g. a custom logical type) to a Beam schema that is then exported to JSON Schema; schema evolution introducing a type the JSON converter predates.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/fad062c3104ec1fa. Report an issue: GitHub.