{"record":{"id":"2b7adfa13c428d7d","repo":"json-path/JsonPath","slug":"expected-class-node","errorCode":null,"errorMessage":"Expected class node","messagePattern":"Expected class node","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java","lineNumber":104,"sourceCode":"\n    public NullNode asNullNode() {\n        throw new InvalidPathException(\"Expected null node\");\n    }\n\n    public UndefinedNode asUndefinedNode() {\n        throw new InvalidPathException(\"Expected undefined node\");\n    }\n\n    public boolean isUndefinedNode() {\n        return false;\n    }\n\n    public boolean isClassNode() {\n        return false;\n    }\n\n    public ClassNode asClassNode() {\n        throw new InvalidPathException(\"Expected class node\");\n    }\n\n    //workaround for issue: https://github.com/json-path/JsonPath/issues/613\n    public boolean isOffsetDateTimeNode(){\n        return false;\n    }\n\n    public OffsetDateTimeNode asOffsetDateTimeNode(){\n        throw new InvalidPathException(\"Expected offsetDateTime node\");\n    }\n\n\n    private static boolean isPath(Object o) {\n        if(o == null || !(o instanceof String)){\n            return false;\n        }\n        String str = o.toString().trim();\n        if (str.length() <= 0) {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/filter/ValueNode.java#L86-L122","documentation":"ValueNode's base asClassNode() throws InvalidPathException(\"Expected class node\") when evaluate calls it on a node that is not a ClassNode. ClassNode represents a Java Class operand used by the type-checking operator ('instanceof'-style filters like @ instanceof java.lang.String in newer JsonPath). The base class throws by default; this error means a type-check operand was not a ClassNode.","triggerScenarios":"Using the type-check operator in a filter where the operand is not a class reference — e.g. writing @.value instanceof String (a plain string) instead of a fully qualified class name/type node, or an operand path resolving to a scalar where a ClassNode was expected by evaluate.","commonSituations":"Writing type-check filters with shorthand class names or wrong syntax; documents where the checked value is a scalar so the operator's operand resolution fails; misuse of the internal ValueNode API.","solutions":["Use the correct class-node syntax with the proper type reference supported by your JsonPath version, e.g. $.items[?(@.val instanceof java.lang.String)]","Check the JsonPath version: type-check filter support and syntax changed across versions; use a version that supports the instanceof operator if needed","Rewrite the check without type checks, e.g. verify with a regular comparison or by post-filtering in Java","Catch InvalidPathException and fall back to manual type filtering in application code"],"exampleFix":"// before\n$.items[?(@.val instanceof String)] // shorthand not a class node\n// after\n$.items[?(@.val instanceof java.lang.String)]","handlingStrategy":"validation","validationCode":"String expr = \"$.items[?(@.val instanceof java.lang.String)]\";\nif (!expr.matches(\".*instanceof [a-z]+(\\.[A-Za-z0-9_]+)+.*\")) throw new IllegalArgumentException(\"type check needs a fully qualified class name\");","typeGuard":null,"tryCatchPattern":"try {\n    return JsonPath.parse(json).read(expr);\n} catch (InvalidPathException e) {\n    // fall back to post-filtering by Java type\n    return manualTypeFilter(json);\n}","preventionTips":["Use fully qualified class names in type-check filters","Verify your json-path version supports the instanceof operator before using it","Prefer post-filtering in Java (instanceof) when type checks are complex"],"tags":["jsonpath","filter","type-mismatch","class-node"],"backgroundTag":"type-mismatch","analyzedSha":"62a4c9f0f65ba3f625aa0867d64c528ba72d09ec","analyzedAt":"2026-09-11T11:36:00.448Z","contentChangedAt":"2026-09-11T11:36:00.448Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}