{"record":{"id":"959d25d8882f7d28","repo":"pentaho/pentaho-kettle","slug":"i-don-t-know-how-to-convert-a-boolean-to-binary","errorCode":null,"errorMessage":" : I don't know how to convert a boolean to binary.","messagePattern":" : I don't know how to convert a boolean to binary\\.","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java","lineNumber":2409,"sourceCode":"      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\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    }","sourceCodeStart":2391,"sourceCodeEnd":2427,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java#L2391-L2427","documentation":"ValueMetaBase.getBinary() does not support TYPE_BOOLEAN values; boolean has no defined binary-string encoding, so KettleValueException is thrown. Convert the boolean to a string (e.g. \"true\"/\"false\" or \"Y\"/\"N\") before requesting bytes.","triggerScenarios":"Calling getBinary(object) on a value meta whose type is ValueMetaInterface.TYPE_BOOLEAN.","commonSituations":"Binary file output including boolean flag fields; generic row serialization code; plugins calling getBinary on every field regardless of type.","solutions":["Convert the boolean to a string first (vm.getString(value)) and call getBinary on a TYPE_STRING meta.","Change the field metadata to TYPE_STRING for binary output.","Encode the boolean as an integer (0/1) in an INTEGER field if a byte-level representation is needed.","Catch KettleValueException and handle boolean fields with explicit encoding."],"exampleFix":"// before\nValueMetaInterface vm = new ValueMeta(\"flag\", ValueMetaInterface.TYPE_BOOLEAN);\nbyte[] b = vm.getBinary(Boolean.TRUE); // throws\n// after\nString s = vm.getString(Boolean.TRUE);\nValueMetaInterface vmStr = new ValueMeta(\"flag\", ValueMetaInterface.TYPE_STRING);\nbyte[] b = vmStr.getBinary(s);","handlingStrategy":"type-guard","validationCode":"if (meta.getType() == ValueMetaInterface.TYPE_BOOLEAN) { throw new IllegalArgumentException(\"Field \" + meta.getName() + \" is a boolean; 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":["Encode booleans as strings or 0/1 integers before binary output.","Check meta.getType() before calling getBinary().","Define a consistent boolean encoding convention across steps.","Test outputs with boolean fields present 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"}