{"record":{"id":"743c2a004ca08c7f","repo":"apple/pkl","slug":"error-serializing-annotation-for-pklproject-ca","errorCode":null,"errorMessage":"Error serializing annotation for PklProject:\n:  cannot render value with unexpected type: ","messagePattern":"Error serializing annotation for PklProject:\n:  cannot render value with unexpected type: ","errorType":"exception","errorClass":"PklException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/packages/DependencyMetadata.java","lineNumber":703,"sourceCode":"        jsonWriter.name(\"value\").value(dataSize.getValue());\n        jsonWriter.endObject();\n      } else if (value instanceof Duration duration) {\n        jsonWriter.beginObject();\n        jsonWriter.name(\"type\").value(\"Duration\");\n        jsonWriter.name(\"unit\").value(duration.getUnit().getSymbol());\n        jsonWriter.name(\"value\").value(duration.getValue());\n        jsonWriter.endObject();\n      } else if (value instanceof Pair<?, ?> pair) {\n        jsonWriter.beginObject();\n        jsonWriter.name(\"type\").value(\"Pair\");\n        jsonWriter.name(\"first\");\n        writeGenericObject(pair.getFirst());\n        jsonWriter.name(\"second\");\n        writeGenericObject(pair.getSecond());\n        jsonWriter.endObject();\n      } else {\n        // PClass and TypeAlias are not supported\n        throw new PklException(\n            \"Error serializing annotation for PklProject:\\n:\"\n                + \"  cannot render value with unexpected type: \"\n                + value.getClass());\n      }\n    }\n  }\n}\n","sourceCodeStart":685,"sourceCodeEnd":711,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/packages/DependencyMetadata.java#L685-L711","documentation":"Thrown by DependencyMetadataWriter when serializing an annotation value whose Java type is not one of the supported generic types (String, Boolean, numbers, Duration, DataSize, Pair, collections, PObject, etc.). PClass and TypeAlias values are explicitly unsupported; the writer cannot render the value into dependency-metadata JSON and aborts with this PklException.","triggerScenarios":"Writing PklProject dependency metadata for a package whose module annotations contain a value of an unsupported type — e.g. a PClass reference or TypeAlias used as an annotation value.","commonSituations":"A package author annotated properties/classes with type references or custom-class values; the metadata writer cannot flatten these to JSON, typically discovered when running pkl project package/publish or dependency resolution.","solutions":["Change the annotation to use a supported value type (String, number, Duration, DataSize, Boolean, Pair, list/map of those)","Remove the unsupported annotation (PClass/TypeAlias reference) from the package's modules","Upgrade Pkl to a version that may support the value type, or file/fix the serializer to handle it"],"exampleFix":"// before\n@Deprecated { replaceWith = SomeClass } // PClass value\n// after\n@Deprecated { replaceWith = \"SomeClass\" } // String value","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  writer.write(project);\n} catch (PklException e) {\n  if (e.getMessage().contains(\"cannot render value with unexpected type\")) {\n    log.error(\"Package contains annotations with unsupported value types (e.g. PClass/TypeAlias refs); replace them with primitives\", e);\n  }\n}","preventionTips":["Use only primitive-serializable values (String, Boolean, numbers, Duration, DataSize, Pair, lists/maps) in annotations","Never use PClass or TypeAlias references as annotation values","Test `pkl project package` on the package before publishing"],"tags":["pkl","serialization","unsupported-type"],"backgroundTag":"unsupported-operation","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}