{"record":{"id":"7855f8ce7444bd0e","repo":"pentaho/pentaho-kettle","slug":"i-don-t-know-how-to-convert-a-date-to-binary","errorCode":null,"errorMessage":" : I don't know how to convert a date to binary.","messagePattern":" : I don't know how to convert a date to binary\\.","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java","lineNumber":2390,"sourceCode":"  @Override\n  public byte[] getBinary( Object object ) throws KettleValueException {\n    if ( object == null ) {\n      return null;\n    }\n    switch ( type ) {\n      case TYPE_BINARY:\n        switch ( storageType ) {\n          case STORAGE_TYPE_NORMAL:\n            return (byte[]) object;\n          case STORAGE_TYPE_BINARY_STRING:\n            return (byte[]) object;\n          case STORAGE_TYPE_INDEXED:\n            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:","sourceCodeStart":2372,"sourceCodeEnd":2408,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java#L2372-L2408","documentation":"Kettle cannot convert a value of TYPE_DATE into binary bytes in ValueMetaBase.getBinary(). Binary output is only supported for string-typed values (via convertStringToBinaryString); date values have no defined byte encoding, so KettleValueException is thrown. The field name is included via toString() to help locate the offending field.","triggerScenarios":"Calling getBinary(object) (or any code path requesting raw bytes, e.g. serialization helpers) on a value meta whose type is ValueMetaInterface.TYPE_DATE.","commonSituations":"Trying to write a date field out as a binary/text-file field expecting bytes; misconfigured Select Values or text output steps that cast fields to binary; plugin code assuming getBinary works for all types.","solutions":["Convert the date to a string first (formatDate or a Select Values type change to String), then call getBinary on the string-typed meta.","Change the field metadata to TYPE_STRING before requesting binary data.","Store the date as a long (getTime()) in an INTEGER field if byte-level representation is required.","Catch KettleValueException and handle date fields with an explicit formatter instead of getBinary()."],"exampleFix":"// before\nValueMetaInterface vm = new ValueMeta(\"d\", ValueMetaInterface.TYPE_DATE);\nbyte[] b = vm.getBinary(dateValue); // throws\n// after\nValueMetaInterface vmStr = new ValueMeta(\"d\", ValueMetaInterface.TYPE_STRING);\nString s = vm.formatDate((Date) dateValue);\nbyte[] b = vmStr.getBinary(s);","handlingStrategy":"type-guard","validationCode":"if (meta.getType() == ValueMetaInterface.TYPE_DATE) { throw new IllegalArgumentException(\"Field \" + meta.getName() + \" is a date; 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) { String s = vm.getString(value); byte[] b = s != null ? s.getBytes() : null; }","preventionTips":["Only call getBinary() on string/binary-typed metas.","Format dates to strings before byte-level output.","Use getString() as the universal accessor, then encode bytes yourself.","Normalize field types with Select Values before binary outputs."],"tags":["kettle","binary","date-conversion"],"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"}