json-path/JsonPath · error · UnsupportedOperationException

JsonOrg provider does not support TypeRef! Use a Jackson or

Error message

JsonOrg provider does not support TypeRef! Use a Jackson or Gson based provider

What it means

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.

Source

Thrown at json-path/src/main/java/com/jayway/jsonpath/spi/mapper/JsonOrgMappingProvider.java:27

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JsonOrgMappingProvider implements MappingProvider {
    @Override
    public <T> T map(Object source, Class<T> targetType, Configuration configuration) {
        if(source == null){
            return null;
        }
        if(targetType.equals(Object.class) || targetType.equals(List.class) || targetType.equals(Map.class)){
            return (T) mapToObject(source);
        }
        return (T)source;
    }

    @Override
    public <T> T map(Object source, TypeRef<T> targetType, Configuration configuration) {
        throw new UnsupportedOperationException("JsonOrg provider does not support TypeRef! Use a Jackson or Gson based provider");
    }


    private Object mapToObject(Object source){
        if(source instanceof JSONArray){
            List<Object> mapped = new ArrayList<Object>();
            JSONArray array = (JSONArray) source;

            for (int i = 0; i < array.length(); i++){
                mapped.add(mapToObject(array.get(i)));
            }

            return mapped;
        }
        else if (source instanceof JSONObject){
            Map<String, Object> mapped = new HashMap<String, Object>();
            JSONObject obj = (JSONObject) source;

View on GitHub (pinned to 62a4c9f0f6)

Solutions

  1. Switch the mapping configuration to JacksonMappingProvider or GsonMappingProvider: Configuration.builder().mappingProvider(new JacksonMappingProvider()).build()
  2. Use the class-based read(path, Class<T>) overload with types JsonOrg supports, or read as raw JSONObject/JSONArray and convert manually
  3. Use JsonPath.using(config) everywhere so the intended provider is consistently applied

Example fix

// before
Configuration cfg = Configuration.defaultConfiguration(); // JsonOrg
List<MyDto> list = JsonPath.using(cfg).parse(json).read("$[*]", new TypeRef<List<MyDto>>(){});
// after
Configuration cfg = Configuration.builder()
    .mappingProvider(new JacksonMappingProvider()).build();
List<MyDto> list = JsonPath.using(cfg).parse(json).read("$[*]", new TypeRef<List<MyDto>>(){});
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure provider supports TypeRef before typed reads
if (config.getMappingProvider() instanceof JsonOrgMappingProvider) {
    throw new IllegalStateException("Use Jackson/Gson mapping provider for TypeRef reads");
}

Type guard

boolean supportsTypeRef(Configuration cfg) {
    return !(cfg.getMappingProvider() instanceof JsonOrgMappingProvider);
}

Try / catch

try {
    T v = JsonPath.using(config).parse(json).read(path, new TypeRef<T>(){});
} catch (UnsupportedOperationException e) {
    // provider lacks TypeRef support: switch mapping provider or use Class-based read
}

Prevention

When it happens

Trigger: Calling JsonPath.parse(...).read(path, new TypeRef<List<MyDto>>(){}) (or any TypeRef overload) while the configuration's mapping provider is JsonOrgMappingProvider (org.json based).

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of json-path/JsonPath@62a4c9f0f6 (2026-09-11). Data as JSON: /api/errors/66d60f8e38ac8800. Report an issue: GitHub.