{"record":{"id":"5a336e3ab793b1e1","repo":"pentaho/pentaho-kettle","slug":"i-don-t-know-how-to-convert-a-number-to-binary","errorCode":null,"errorMessage":" : I don't know how to convert a number to binary.","messagePattern":" : I don't know how to convert a number to binary\\.","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java","lineNumber":2403,"sourceCode":"            return (byte[]) index[( (Integer) object ).intValue()];\n          default:\n            throw new KettleValueException( toString() + \" : Unknown storage type \" + storageType + \" specified.\" );\n        }\n      case TYPE_DATE:\n        throw new KettleValueException( toString() + \" : I don't know how to convert a date to binary.\" );\n      case TYPE_STRING:\n        switch ( storageType ) {\n          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","sourceCodeStart":2385,"sourceCodeEnd":2421,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java#L2385-L2421","documentation":"ValueMetaBase.getBinary() does not define a byte representation for TYPE_NUMBER (double) values, so it throws KettleValueException. Only string-typed values can be converted to the internal binary-string representation; numeric fields must first be converted to strings.","triggerScenarios":"Calling getBinary(object) on a value meta whose type is ValueMetaInterface.TYPE_NUMBER, e.g. in a custom step or output plugin that requests raw bytes of a numeric field.","commonSituations":"Text/binary file output steps misconfigured to emit number fields as binary; plugin code assuming getBinary is universal; serialization helpers applied to numeric fields.","solutions":["Convert the number to a string first (str = vmNumber.getString(value)) and call getBinary on a TYPE_STRING meta.","Change the field metadata to TYPE_STRING before requesting binary output.","Use getString()/getString(row) with a format mask instead of byte-level access.","Catch KettleValueException and handle numeric fields with explicit formatting."],"exampleFix":"// before\nValueMetaInterface vm = new ValueMeta(\"n\", ValueMetaInterface.TYPE_NUMBER);\nbyte[] b = vm.getBinary(3.14); // throws\n// after\nString s = vm.getString(3.14);\nValueMetaInterface vmStr = new ValueMeta(\"n\", ValueMetaInterface.TYPE_STRING);\nbyte[] b = vmStr.getBinary(s);","handlingStrategy":"type-guard","validationCode":"if (meta.getType() == ValueMetaInterface.TYPE_NUMBER) { throw new IllegalArgumentException(\"Field \" + meta.getName() + \" is numeric; convert to String 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 = vm.getString(value).getBytes(StandardCharsets.UTF_8); }","preventionTips":["Convert numerics to formatted strings before byte output.","Gate getBinary() calls on meta type checks.","Use getString() with conversion masks for numeric formatting.","Test binary outputs against all field types in the row."],"tags":["kettle","binary","type-mismatch"],"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"}