{"record":{"id":"264cf56aeec1e2ee","repo":"pentaho/pentaho-kettle","slug":"i-don-t-know-how-to-convert-a-serializable-to-binary","errorCode":null,"errorMessage":" : I don't know how to convert a serializable to binary.","messagePattern":" : I don't know how to convert a serializable to binary\\.","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java","lineNumber":2411,"sourceCode":"          case STORAGE_TYPE_NORMAL:\n            return convertStringToBinaryString( (String) object );\n          case STORAGE_TYPE_BINARY_STRING:\n            return (byte[]) object;\n          case STORAGE_TYPE_INDEXED:\n            return convertStringToBinaryString( (String) index[( (Integer) object ).intValue()] );\n          default:\n            throw new KettleValueException( toString() + \" : Unknown storage type \" + storageType + \" specified.\" );\n        }\n      case TYPE_NUMBER:\n        throw new KettleValueException( toString() + \" : I don't know how to convert a number to binary.\" );\n      case TYPE_INTEGER:\n        throw new KettleValueException( toString() + \" : I don't know how to convert an integer to binary.\" );\n      case TYPE_BIGNUMBER:\n        throw new KettleValueException( toString() + \" : I don't know how to convert a bignumber to binary.\" );\n      case TYPE_BOOLEAN:\n        throw new KettleValueException( toString() + \" : I don't know how to convert a boolean to binary.\" );\n      case TYPE_SERIALIZABLE:\n        throw new KettleValueException( toString() + \" : I don't know how to convert a serializable to binary.\" );\n\n      default:\n        throw new KettleValueException( toString() + \" : Unknown type \" + type + \" specified.\" );\n    }\n  }\n\n  @Override\n  public byte[] getBinaryString( Object object ) throws KettleValueException {\n    // If the input is a binary string, we should return the exact same binary\n    // object IF\n    // and only IF the formatting options for the storage metadata and this\n    // object are the same.\n    //\n    if ( isStorageBinaryString() && identicalFormat ) {\n      return (byte[]) object; // shortcut it directly for better performance.\n    }\n\n    try {","sourceCodeStart":2393,"sourceCodeEnd":2429,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java#L2393-L2429","documentation":"ValueMetaBase.getBinary() cannot convert TYPE_SERIALIZABLE values (arbitrary Java objects) into binary bytes; KettleValueException is thrown. There is no defined serialization step inside the value meta layer, so serializable fields must be handled with explicit code (e.g. Java serialization or toString).","triggerScenarios":"Calling getBinary(object) on a value meta whose type is ValueMetaInterface.TYPE_SERIALIZABLE, e.g. fields emitted by User Defined Java Class or plugin steps holding raw objects.","commonSituations":"UDJC/script steps pushing Java objects into the stream that a downstream binary/text output tries to read as bytes; generic field serialization utilities; binary file outputs receiving object fields.","solutions":["Explicitly serialize the object with ObjectOutputStream in the producing step and store the byte[] in a TYPE_BINARY field.","Convert the object to a string (toString()/custom formatter) and call getBinary on a TYPE_STRING meta.","Change the field metadata to a concrete supported type at the point where it is created.","Catch KettleValueException and skip/handle serializable fields explicitly in generic serialization loops."],"exampleFix":"// before\nValueMetaInterface vm = new ValueMeta(\"obj\", ValueMetaInterface.TYPE_SERIALIZABLE);\nbyte[] b = vm.getBinary(myObject); // throws\n// after\nByteArrayOutputStream bos = new ByteArrayOutputStream();\nnew ObjectOutputStream(bos).writeObject(myObject);\nValueMetaInterface vmBin = new ValueMeta(\"obj\", ValueMetaInterface.TYPE_BINARY);\nbyte[] b = vmBin.getBinary(bos.toByteArray());","handlingStrategy":"type-guard","validationCode":"if (meta.getType() == ValueMetaInterface.TYPE_SERIALIZABLE) { throw new IllegalArgumentException(\"Field \" + meta.getName() + \" is serializable; serialize explicitly before getBinary()\"); }","typeGuard":"boolean isBinaryReadable(ValueMetaInterface vm) { return vm.getType() == ValueMetaInterface.TYPE_STRING || vm.getType() == ValueMetaInterface.TYPE_BINARY; }","tryCatchPattern":"try { byte[] b = vm.getBinary(value); } catch (KettleValueException e) { byte[] b = value instanceof java.io.Serializable ? serialize(value) : vm.getString(value).getBytes(); }","preventionTips":["Avoid putting raw serializable objects in shared row streams.","Explicitly Java-serialize objects to TYPE_BINARY fields in producing steps.","Gate getBinary() on the declared value type.","Document/validate row layouts crossing step boundaries."],"tags":["kettle","binary","serializable"],"backgroundTag":"incompatible-source-type","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"}