{"record":{"id":"29a254b7cdbf0eb8","repo":"apache/beam","slug":"does-not-support-converting-avro-format-value-getclass","errorCode":null,"errorMessage":"Does not support converting avro format: \" + value.getClass().getName()","messagePattern":"Does not support converting avro format: \" \\+ value\\.getClass\\(\\)\\.getName\\(\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java","lineNumber":1173,"sourceCode":"        throw new RuntimeException(\"Does not support converting DECIMAL type value\");\n      case STRING:\n        return convertAvroString(value);\n      case BYTES:\n        return convertAvroBytes(value);\n      default:\n        throw new RuntimeException(beamType + \" is not primitive type.\");\n    }\n  }\n\n  private static @Nullable Object convertAvroString(@Nullable Object value) {\n    if (value == null) {\n      return null;\n    } else if (value instanceof Utf8) {\n      return ((Utf8) value).toString();\n    } else if (value instanceof String) {\n      return value;\n    } else {\n      throw new RuntimeException(\n          \"Does not support converting avro format: \" + value.getClass().getName());\n    }\n  }\n\n  private static @Nullable Object convertAvroBytes(@Nullable Object value) {\n    if (value == null) {\n      return null;\n    } else if (value instanceof ByteBuffer) {\n      ByteBuffer bf = (ByteBuffer) value;\n      byte[] result = new byte[bf.limit()];\n      bf.get(result);\n      return result;\n    } else {\n      throw new RuntimeException(\n          \"Does not support converting avro format: \" + value.getClass().getName());\n    }\n  }\n","sourceCodeStart":1155,"sourceCodeEnd":1191,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryUtils.java#L1155-L1191","documentation":"Thrown by convertAvroString when the Avro value for a Beam STRING field is neither null, Avro Utf8, nor java.lang.String. The BigQuery Avro path expects string-typed columns decoded to Utf8/String; any other runtime type (e.g. Integer, ByteBuffer, Map from a mis-decoded record) is rejected. Usually indicates a mismatch between the declared Avro schema and the actual decoded values.","triggerScenarios":"Avro GenericData.Record decoded with a GenericDatumReader without string conversion where values arrive as unexpected types, or BigQuery export/avro schema mismatch where a non-string Avro value feeds a STRING Beam field — e.g. value is Integer/Long/ByteBuffer.","commonSituations":"Custom avro decoding pipelines feeding records into BigQueryIO conversion; Avro reader/writer schema mismatch; data loaded into BigQuery with wrong types then exported as Avro.","solutions":["Configure the Avro decoder with string conversion: new GenericDatumReader<GenericRecord>(schema, schema, new GenericData().addStringConversion(...)) or configure GenericData.StringType.String so values decode as Utf8.","Verify the Avro schema field for the STRING column is actually of type string, not bytes/int.","Check for reader/writer schema mismatch when decoding the GenericRecord.","As a fallback, extend/fork convertAvroString to coerce Number/ByteBuffer values via String.valueOf."],"exampleFix":"// before\nGenericDatumReader<GenericRecord> r = new GenericDatumReader<>(schema);\n// after\nGenericData gd = new GenericData();\ngd.setStringType(GenericData.StringType.String);\nGenericDatumReader<GenericRecord> r = new GenericDatumReader<>(schema, schema, gd);","handlingStrategy":"type-guard","validationCode":"// Java: normalize string values before conversion\nObject normalizeString(Object v) {\n  if (v instanceof Utf8) return v.toString();\n  if (v instanceof String || v == null) return v;\n  if (v instanceof Number) return v.toString();\n  throw new IllegalArgumentException(\"Expected avro string, got \" + v.getClass());\n}","typeGuard":"// Java\nstatic boolean isAvroString(Object v) {\n  return v == null || v instanceof Utf8 || v instanceof String;\n}","tryCatchPattern":"try { s = convertAvroFormat(stringField, v, opts); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Does not support converting avro format\")) { s = String.valueOf(v); } else throw e; }","preventionTips":["Decode Avro with StringType.String conversion so CHAR/VARCHAR values become Utf8/String.","Confirm the Avro schema types match the BigQuery export schema before reading.","Beware reader/writer schema mismatch when decoding GenericRecords."],"tags":["java","beam","bigquery","avro","string"],"backgroundTag":"unexpected-response-shape","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}