{"record":{"id":"7ce14fbbdd4ca2e3","repo":"json-path/JsonPath","slug":"typeref-not-supported-typename","errorCode":null,"errorMessage":"TypeRef not supported: \" + typeName","messagePattern":"TypeRef not supported: \" \\+ typeName","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JakartaMappingProvider.java","lineNumber":380,"sourceCode":"                    return method;\r\n                }\r\n            }\r\n            clazz = clazz.getSuperclass();\r\n        }\r\n        return null;\r\n    }\r\n\r\n    private Class<?> getRawClass(Type targetType) {\r\n        if (targetType instanceof Class) {\r\n            return (Class<?>) targetType;\r\n        } else if (targetType instanceof ParameterizedType) {\r\n            return (Class<?>) ((ParameterizedType) targetType).getRawType();\r\n        } else if (targetType instanceof GenericArrayType) {\r\n            String typeName = targetType.getTypeName();\r\n            throw new MappingException(\"Cannot map JSON element to \" + typeName);\r\n        } else {\r\n            String typeName = targetType.getTypeName();\r\n            throw new IllegalArgumentException(\"TypeRef not supported: \" + typeName);\r\n        }\r\n    }\r\n\r\n    private Type getFirstTypeArgument(Type targetType) {\r\n        if (targetType instanceof ParameterizedType) {\r\n            Type[] args = ((ParameterizedType) targetType).getActualTypeArguments();\r\n            if (args != null && args.length > 0) {\r\n                if (args[0] instanceof Class) {\r\n                    return (Class<?>) args[0];\r\n                } else if (args[0] instanceof ParameterizedType) {\r\n                    return (ParameterizedType) args[0];\r\n                }\r\n            }\r\n        }\r\n        return null;\r\n    }\r\n\r\n    /**\r","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JakartaMappingProvider.java#L362-L398","documentation":"In getRawClass(), any Type that is neither Class, ParameterizedType, nor GenericArrayType — e.g. a wildcard type (?), a type variable (T), or a TypeVariable embedded in a TypeRef — is unsupported. The provider throws IllegalArgumentException(\"TypeRef not supported: <typeName>\") because it cannot determine the concrete raw class to databind into.","triggerScenarios":"Passing a TypeRef or Type whose underlying type is a wildcard (List<?>) or an unresolved type variable (T) — e.g. new TypeRef<List<?>>(){} or generic helper methods that forward T — into read(path, typeRef) on JakartaMappingProvider.","commonSituations":"Generic wrapper methods like <T> T read(String path) forwarding T to TypeRef; using wildcard generics in TypeRef declarations; erasure surprises where the resolved TypeVariable instead of a Class reaches the mapper.","solutions":["Replace wildcard or type-variable generics with concrete classes in the TypeRef: new TypeRef<List<Book>>(){}, not new TypeRef<List<?>>(){}.","In generic helper methods, pass the concrete Class/TypeRef from the call site rather than the erased T.","Read into List<Map<String,Object>> and convert manually if the element type is dynamic.","Catch IllegalArgumentException and provide a fallback target type."],"exampleFix":"// before\nList<?> items = jsonPath.read(\"$.items\", new TypeRef<List<?>>() {}); // IllegalArgumentException: TypeRef not supported\n// after\nList<Map<String, Object>> items = jsonPath.read(\"$.items\", new TypeRef<List<Map<String, Object>>>() {});","handlingStrategy":"type-guard","validationCode":"static boolean isConcreteType(java.lang.reflect.Type t) {\n    return t instanceof Class\n        || (t instanceof ParameterizedType\n            && java.util.Arrays.stream(((ParameterizedType) t).getActualTypeArguments())\n                .allMatch(a -> a instanceof Class || a instanceof ParameterizedType));\n}","typeGuard":"boolean usableTypeRef(java.lang.reflect.Type t) {\n    return !(t instanceof javax.lang.model.type.WildcardType)\n        && !(t instanceof java.lang.reflect.TypeVariable);\n}","tryCatchPattern":"try {\n    return jsonPath.read(path, typeRef);\n} catch (IllegalArgumentException e) {\n    return jsonPath.read(path, new TypeRef<List<Map<String, Object>>>() {});\n}","preventionTips":["Use fully concrete generics in TypeRef; never ? or bare type variables.","Do not forward erased generic parameters T from helper methods into TypeRef.","Prefer List<Map<String,Object>> when the element type is only known at runtime."],"tags":["json","generics","typeref","json-path"],"backgroundTag":"unsupported-operation","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"}