{"record":{"id":"66d60f8e38ac8800","repo":"json-path/JsonPath","slug":"jsonorg-provider-does-not-support-typeref-use-a-j","errorCode":null,"errorMessage":"JsonOrg provider does not support TypeRef! Use a Jackson or Gson based provider","messagePattern":"JsonOrg provider does not support TypeRef! Use a Jackson or Gson based provider","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JsonOrgMappingProvider.java","lineNumber":27,"sourceCode":"import java.util.HashMap;\nimport java.util.List;\nimport java.util.Map;\n\npublic class JsonOrgMappingProvider implements MappingProvider {\n    @Override\n    public <T> T map(Object source, Class<T> targetType, Configuration configuration) {\n        if(source == null){\n            return null;\n        }\n        if(targetType.equals(Object.class) || targetType.equals(List.class) || targetType.equals(Map.class)){\n            return (T) mapToObject(source);\n        }\n        return (T)source;\n    }\n\n    @Override\n    public <T> T map(Object source, TypeRef<T> targetType, Configuration configuration) {\n        throw new UnsupportedOperationException(\"JsonOrg provider does not support TypeRef! Use a Jackson or Gson based provider\");\n    }\n\n\n    private Object mapToObject(Object source){\n        if(source instanceof JSONArray){\n            List<Object> mapped = new ArrayList<Object>();\n            JSONArray array = (JSONArray) source;\n\n            for (int i = 0; i < array.length(); i++){\n                mapped.add(mapToObject(array.get(i)));\n            }\n\n            return mapped;\n        }\n        else if (source instanceof JSONObject){\n            Map<String, Object> mapped = new HashMap<String, Object>();\n            JSONObject obj = (JSONObject) source;\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JsonOrgMappingProvider.java#L9-L45","documentation":"JsonOrgMappingProvider cannot convert to generic typed targets: its map(Object, TypeRef<T>, Configuration) implementation unconditionally throws UnsupportedOperationException. Type-based generic deserialization requires a databind library, so the message directs users to Jackson or Gson based providers.","triggerScenarios":"Calling JsonPath.parse(...).read(path, new TypeRef<List<MyDto>>(){}) (or any TypeRef overload) while the configuration's mapping provider is JsonOrgMappingProvider (org.json based).","commonSituations":"Using Configuration.defaultConfiguration() or explicitly setting the JsonOrg provider and then attempting typed reads; copying code that worked under Jackson/Gson config to a JsonOrg setup; building TypeRef support expectations from a provider-agnostic API.","solutions":["Switch the mapping configuration to JacksonMappingProvider or GsonMappingProvider: Configuration.builder().mappingProvider(new JacksonMappingProvider()).build()","Use the class-based read(path, Class<T>) overload with types JsonOrg supports, or read as raw JSONObject/JSONArray and convert manually","Use JsonPath.using(config) everywhere so the intended provider is consistently applied"],"exampleFix":"// before\nConfiguration cfg = Configuration.defaultConfiguration(); // JsonOrg\nList<MyDto> list = JsonPath.using(cfg).parse(json).read(\"$[*]\", new TypeRef<List<MyDto>>(){});\n// after\nConfiguration cfg = Configuration.builder()\n    .mappingProvider(new JacksonMappingProvider()).build();\nList<MyDto> list = JsonPath.using(cfg).parse(json).read(\"$[*]\", new TypeRef<List<MyDto>>(){});","handlingStrategy":"try-catch","validationCode":"// ensure provider supports TypeRef before typed reads\nif (config.getMappingProvider() instanceof JsonOrgMappingProvider) {\n    throw new IllegalStateException(\"Use Jackson/Gson mapping provider for TypeRef reads\");\n}","typeGuard":"boolean supportsTypeRef(Configuration cfg) {\n    return !(cfg.getMappingProvider() instanceof JsonOrgMappingProvider);\n}","tryCatchPattern":"try {\n    T v = JsonPath.using(config).parse(json).read(path, new TypeRef<T>(){});\n} catch (UnsupportedOperationException e) {\n    // provider lacks TypeRef support: switch mapping provider or use Class-based read\n}","preventionTips":["Configure JacksonMappingProvider or GsonMappingProvider whenever you use TypeRef","Never assume Configuration.defaultConfiguration() supports generic typed reads","Add a startup config check that fails fast when the provider lacks TypeRef support"],"tags":["json-path","unsupported-operation","typeref","json-org"],"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"}