{"record":{"id":"995ae322e903ac2f","repo":"pentaho/pentaho-kettle","slug":"can-t-encode-object-of-class-classname","errorCode":null,"errorMessage":"Can't encode object of class : className","messagePattern":"Can't encode object of class : className","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryMetaStoreDelegate.java","lineNumber":421,"sourceCode":"    }\n    if ( object instanceof Timestamp ) {\n      return \"T:\" + new SimpleTimestampFormat(\n        ValueMetaBase.DEFAULT_TIMESTAMP_FORMAT_MASK ).format( (Timestamp) object );\n    }\n    if ( object instanceof Date ) {\n      return \"D:\" + new SimpleDateFormat( ValueMetaBase.DEFAULT_DATE_FORMAT_MASK ).format( (Date) object );\n    }\n    if ( object instanceof Double ) {\n      return \"N:\" + Double.toString( (Double) object );\n    }\n    if ( object instanceof Long ) {\n      return \"I:\" + Long.toString( (Long) object );\n    }\n    if ( object instanceof Boolean ) {\n      return \"B:\" + ( ( (Boolean) object ) ? \"true\" : \"false\" );\n    }\n\n    throw new KettleException( \"Can't encode object of class : \" + object.getClass().getName() );\n  }\n\n  public ObjectId insertElement( IMetaStoreElementType elementType, IMetaStoreElement element ) throws MetaStoreException {\n    try {\n\n      LongObjectId elementId =\n        repository.connectionDelegate.getNextID(\n          quoteTable( KettleDatabaseRepository.TABLE_R_ELEMENT ),\n          quote( KettleDatabaseRepository.FIELD_ELEMENT_ID_ELEMENT ) );\n      RowMetaAndData table = new RowMetaAndData();\n\n      table.addValue( new ValueMetaInteger(\n        KettleDatabaseRepository.FIELD_ELEMENT_ID_ELEMENT ), elementId\n        .longValue() );\n      table.addValue( new ValueMetaInteger(\n        KettleDatabaseRepository.FIELD_ELEMENT_ID_ELEMENT_TYPE ), Long\n        .valueOf( elementType.getId() ) );\n      table.addValue(","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/repository/kdr/delegates/KettleDatabaseRepositoryMetaStoreDelegate.java#L403-L439","documentation":"encodeAttributeValue only supports String, Double, Long/Integer, and Boolean objects; any other class (Date, BigDecimal, maps, POJOs) throws KettleException \"Can't encode object of class ...\". The metastore attribute store has a fixed value type set.","triggerScenarios":"Calling encodeAttributeValue (via insertAttributes when saving a metastore element) with an attribute value that is not String, Double, Long, Integer, or Boolean.","commonSituations":"Putting Date or BigDecimal values into a metastore element; framework code storing arbitrary objects in element properties; API change returning a boxed type different from what was stored before.","solutions":["Convert unsupported objects before storing: use toString()/ISO-8601 for Date, toPlainString() for BigDecimal","Encode as String and decode on read in your application code","Restrict element attributes to the supported types (String, Double, Long/Integer, Boolean)","Reject unsupported types at your API boundary with a clear validation error"],"exampleFix":"// before\nattributes.put(\"created\", new Date()); // throws\nelement.setProperty(\"created\", attributes.get(\"created\"));\n// after\nelement.setProperty(\"created\", new SimpleDateFormat(\"yyyy-MM-dd'T'HH:mm:ss'Z'\").format(new Date()));","handlingStrategy":"type-guard","validationCode":"boolean encodable(Object v) { return v == null || v instanceof String || v instanceof Double || v instanceof Long || v instanceof Integer || v instanceof Boolean; }","typeGuard":"Object coerceEncodable(Object v) {\n  if (v instanceof java.util.Date) return new java.text.SimpleDateFormat(\"yyyy-MM-dd'T'HH:mm:ss'Z'\").format((java.util.Date) v);\n  if (v instanceof java.math.BigDecimal) return ((java.math.BigDecimal) v).toPlainString();\n  return v;\n}","tryCatchPattern":"try { delegate.encodeAttributeValue(obj); } catch (KettleException e) { logError(\"Unsupported metastore attribute type: \" + obj.getClass(), e); }","preventionTips":["Limit metastore element properties to String/Double/Long/Integer/Boolean","Convert Dates and BigDecimals to strings before storing","Add a boundary validator that rejects non-encodable attribute values early"],"tags":["metastore","encoding","type-mismatch","attribute"],"backgroundTag":"type-mismatch","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"}