{"record":{"id":"7c4a397247b8bb3b","repo":"apple/pkl","slug":"could-not-read-annotation-invalid-object-type","errorCode":null,"errorMessage":"Could not read annotation. Invalid object type: ","messagePattern":"Could not read annotation\\. Invalid object type: ","errorType":"exception","errorClass":"PklException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/packages/DependencyMetadata.java","lineNumber":280,"sourceCode":"          }\n          var unit = DurationUnit.parse(symbol);\n          if (unit == null) {\n            throw new PklException(\"Invalid Duration unit symbol: \" + symbol);\n          }\n          if (!(value instanceof Double num)) {\n            throw new FormatException(\"double\", value.getClass());\n          }\n          return new Duration(num, unit);\n        }\n        case \"Pair\" -> {\n          var first = parsePObject(jsObj.get(\"first\"));\n          var second = parsePObject(jsObj.get(\"second\"));\n          return new Pair<>(first, second);\n        }\n      }\n    }\n    // should never be reached\n    throw new PklException(\"Could not read annotation. Invalid object type: \" + obj.getClass());\n  }\n\n  public static Checksums parseChecksums(Object obj) throws JsonParseException {\n    if (!(obj instanceof JsObject jsObj)) {\n      throw new FormatException(\"object\", obj.getClass());\n    }\n    var sha256 = jsObj.getString(\"sha256\");\n    return new Checksums(sha256);\n  }\n\n  public static List<String> parseAuthors(Object obj) throws JsonParseException {\n    if (!(obj instanceof JsArray arr)) {\n      throw new FormatException(\"array\", obj.getClass());\n    }\n    var ret = new ArrayList<String>(arr.size());\n    for (var elem : arr) {\n      if (!(elem instanceof String string)) {\n        throw new FormatException(\"string\", elem != null ? elem.getClass() : Void.class);","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/packages/DependencyMetadata.java#L262-L298","documentation":"A catch-all PklException at the end of parsePObject, reached when the input object matches none of the recognized shapes (not a JsArray, or a JsObject whose \"type\" is not Set/Map/PObject/Pattern/DataSize/Duration/Pair, or a JsObject without a \"type\" string). It reports the Java class of the offending object; the comment notes it 'should never be reached' for well-formed metadata.","triggerScenarios":"Passing a scalar (String, Number, Boolean), a JsObject lacking a \"type\" key, or a JsObject with an unknown type name (e.g. {\"type\":\"List\"}) into parsePObject via obj/first/second.","commonSituations":"A dependency metadata file written by a newer Pkl version with a type this reader does not know, or a hand-crafted JSON structure that skips the \"type\" discriminator.","solutions":["Ensure every object in the metadata JSON has a recognized \"type\" field (Set, Map, PObject, Pattern, DataSize, Duration, Pair)","Regenerate the metadata file using a Pkl version compatible with this library","Check the class name in the message to identify the unexpected object and fix the upstream serializer"],"exampleFix":"// before\n{\"unit\": \"s\", \"value\": 1.0}\n// after\n{\"type\": \"Duration\", \"unit\": \"s\", \"value\": 1.0}","handlingStrategy":"try-catch","validationCode":"Set<String> TYPES = Set.of(\"Set\",\"Map\",\"PObject\",\"Pattern\",\"DataSize\",\"Duration\",\"Pair\");\nboolean hasKnownType(Object o) {\n  return o instanceof Map<?,?> m && m.get(\"type\") instanceof String t && TYPES.contains(t);\n}","typeGuard":"if (!(o instanceof Map<?,?> m) || !(m.get(\"type\") instanceof String)) return fallback(o);","tryCatchPattern":"try {\n  return DependencyMetadata.parsePObject(obj);\n} catch (PklException e) {\n  if (e.getMessage().startsWith(\"Could not read annotation\")) {\n    throw new IOException(\"Metadata contains an object type unsupported by this Pkl version; regenerate metadata\", e);\n  }\n  throw e;\n}","preventionTips":["Keep the reading library version in sync with the Pkl version that wrote the metadata","Always include the \"type\" discriminator on metadata objects","Validate metadata against the published schema before parsing"],"tags":["pkl","json","unrecognized-type"],"backgroundTag":"unexpected-response-shape","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}