{"record":{"id":"b05bcd2bd0b22ceb","repo":"apache/beam","slug":"cannot-convert-value-to-row","errorCode":null,"errorMessage":"Cannot convert value to Row.","messagePattern":"Cannot convert value to Row\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/firestore/FirestoreUtils.java","lineNumber":307,"sourceCode":"          throw new IllegalArgumentException(\"Map value type cannot be null.\");\n        }\n        Map<String, @Nullable Object> rowMap = new HashMap<>();\n        for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {\n          rowMap.put(String.valueOf(entry.getKey()), convertFromJava(entry.getValue(), valueType));\n        }\n        return rowMap;\n      case ROW:\n        Schema rowSchema = fieldType.getRowSchema();\n        if (rowSchema == null) {\n          throw new IllegalArgumentException(\"Row schema cannot be null.\");\n        }\n        if (value instanceof Map) {\n          return toRow(castToStringKeyMap((Map<?, ?>) value), rowSchema);\n        }\n        if (value instanceof Row) {\n          return value;\n        }\n        throw new IllegalArgumentException(\"Cannot convert value to Row.\");\n      default:\n        throw new IllegalArgumentException(\"Unsupported field type: \" + fieldType);\n    }\n  }\n}\n","sourceCodeStart":289,"sourceCodeEnd":313,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/firestore/FirestoreUtils.java#L289-L313","documentation":"When a field's FieldType is ROW, convertFromJava accepts only a Map (converted via toRow) or an already-built Row. Any other Java type — String, number, list, POJO — for a row-typed field triggers this IllegalArgumentException because the library has no conversion path from that type to Row.","triggerScenarios":"Calling toRow/convertFromJava where a schema field is ROW but the supplied value is neither Map nor Row — e.g. a JSON string, a protobuf message, or a custom object.","commonSituations":"Producing rows from document data where nested documents were represented as JSON strings or protobuf Value objects; upstream type changes not reflected in the converter input.","solutions":["Convert the value to a java.util.Map with String keys before writing the row, or wrap it in a Row matching the field's schema","Use a MapMapper/avro/json conversion (e.g. via SchemaUtils) to produce a proper Row","Change the field type if the value is scalar, or nest correctly if it should be a row"],"exampleFix":"// before\nrowMap.put(\"author\", \"{\\\"name\\\":\\\"Ada\\\"}\"); // throws for ROW field\n// after\nrowMap.put(\"author\", Map.of(\"name\", \"Ada\")); // Map is converted via toRow","handlingStrategy":"type-guard","validationCode":"if (!(v instanceof Map || v instanceof Row)) { throw new IllegalArgumentException(\"ROW field requires Map or Row, got \" + v.getClass()); }","typeGuard":"boolean isRowConvertible(Object v) { return v instanceof Map || v instanceof Row; }","tryCatchPattern":"try { Row row = FirestoreUtils.toRow(value, schema); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Cannot convert value to Row\")) { /* convert to Map/Row upstream or dead-letter */ } else { throw e; } }","preventionTips":["Parse JSON strings into Map<String,Object> before schema conversion","Convert protobuf Struct/Value to Map/Row via dedicated helpers","Test converters with all nested field shapes present in production data"],"tags":["java","firestore","schema","type-mismatch"],"backgroundTag":"type-mismatch","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"}