{"record":{"id":"35c3c47dcee9522c","repo":"pentaho/pentaho-kettle","slug":"error-serializing-row-to-byte-array","errorCode":null,"errorMessage":"Error serializing row to byte array","messagePattern":"Error serializing row to byte array","errorType":"exception","errorClass":"java.lang.RuntimeException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/RowMeta.java","lineNumber":1130,"sourceCode":"  }\n\n  /**\n   * Serialize a row of data to byte[]\n   *\n   * @param metadata the metadata to use\n   * @param row      the row of data\n   * @return a serialized form of the data as a byte array\n   */\n  public static byte[] extractData( RowMetaInterface metadata, Object[] row ) {\n    try {\n      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();\n      DataOutputStream dataOutputStream = new DataOutputStream( byteArrayOutputStream );\n      metadata.writeData( dataOutputStream, row );\n      dataOutputStream.close();\n      byteArrayOutputStream.close();\n      return byteArrayOutputStream.toByteArray();\n    } catch ( Exception e ) {\n      throw new RuntimeException( \"Error serializing row to byte array\", e );\n    }\n  }\n\n  /**\n   * Create a row of data bases on a serialized format (byte[])\n   *\n   * @param data     the serialized data\n   * @param metadata the metadata to use\n   * @return a new row of data\n   */\n  public static Object[] getRow( RowMetaInterface metadata, byte[] data ) {\n    try {\n      ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( data );\n      DataInputStream dataInputStream = new DataInputStream( byteArrayInputStream );\n      return metadata.readData( dataInputStream );\n    } catch ( Exception e ) {\n      throw new RuntimeException( \"Error de-serializing row of data from byte array\", e );\n    }","sourceCodeStart":1112,"sourceCodeEnd":1148,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/RowMeta.java#L1112-L1148","documentation":"RowMeta.createOriginalRow/serialization helper wraps any exception raised while writing a row's binary representation (metadata.writeData on a DataOutputStream) into a RuntimeException. The library throws it because binary row serialization is used in clustering/step-internal transport and any failure means the row cannot be transmitted. The original exception is preserved as the cause.","triggerScenarios":"Calling RowMeta.getData() (serialize row to byte[]) when a value in the row cannot be written by its ValueMeta (e.g. corrupt or mismatched value object for the declared type), or an I/O error on the underlying ByteArrayOutputStream (rare).","commonSituations":"Rows built manually with values not matching their ValueMeta types; custom ValueMeta implementations with broken writeData; serialization across kettle versions where the binary format changed.","solutions":["Inspect the cause (e.getCause()) to find which value/meta failed to serialize","Verify each Object[] value matches the declared type in RowMeta (Integer for TYPE_INTEGER, Long where required, etc.)","Rebuild the RowMeta from a real data source instead of hand-crafting it","Check that producer and consumer steps use the same Pentaho/Kettle version"],"exampleFix":"// before\nRowMetaInterface meta = ...; meta.addValueMeta(new ValueMetaString(\"f\"));\nbyte[] b = RowMeta.getData(meta, new Object[]{ 42 }); // Long into string meta\n// after\nbyte[] b = RowMeta.getData(meta, new Object[]{ \"42\" }); // value matches meta type","handlingStrategy":"try-catch","validationCode":"// Java: validate values match meta before serializing\nfor (int i = 0; i < meta.size(); i++) {\n  ValueMetaInterface vm = meta.getValueMeta(i);\n  Object v = row[i];\n  if (v != null) {\n    Class<?> expect = vm.getNativeDataTypeClass();\n    if (expect != null && !expect.isInstance(v))\n      throw new IllegalArgumentException(\"Field \" + vm.getName() + \" expects \" + expect + \" but got \" + v.getClass());\n  }\n}","typeGuard":"boolean matchesMeta(ValueMetaInterface vm, Object v) {\n  if (v == null) return true;\n  Class<?> expect = vm.getNativeDataTypeClass();\n  return expect == null || expect.isInstance(v);\n}","tryCatchPattern":"try {\n  byte[] data = RowMeta.getData(meta, row);\n} catch (RuntimeException e) {\n  Throwable cause = e.getCause();\n  throw new IllegalStateException(\"Row serialization failed: \" + cause.getMessage(), cause);\n}","preventionTips":["Always build rows via transformations or RowMeta-aware factories, not by hand","Keep producer and consumer PDI versions aligned in clustered setups","Log e.getCause() when this wrapper fires — the real error is inside","Unit-test custom ValueMeta implementations' writeData/readData round-trips"],"tags":["serialization","row-metadata","kettle"],"backgroundTag":"json-marshal-failed","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}