{"record":{"id":"21dd6ad9cea99889","repo":"json-path/JsonPath","slug":"cannot-convert-a-source-getclass-getname","errorCode":null,"errorMessage":"Cannot convert a \" + source.getClass().getName() + \" to a \" + targetType + \" use Tapestry's TypeCoercer instead.","messagePattern":"Cannot convert a \" \\+ source\\.getClass\\(\\)\\.getName\\(\\) \\+ \" to a \" \\+ targetType \\+ \" use Tapestry's TypeCoercer instead\\.","errorType":"exception","errorClass":"MappingException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/spi/mapper/TapestryMappingProvider.java","lineNumber":45,"sourceCode":"      return null;\n    }\n    if (targetType.isAssignableFrom(source.getClass())) {\n      return (T) source;\n    }\n    try {\n      if (targetType.isAssignableFrom(ArrayList.class) && configuration.jsonProvider().isArray(source)) {\n        int length = configuration.jsonProvider().length(source);\n        @SuppressWarnings(\"rawtypes\")\n        ArrayList list = new ArrayList(length);\n        for (Object o : configuration.jsonProvider().toIterable(source)) {\n          list.add(o);\n        }\n        return (T) list;\n      }\n    } catch (Exception e) {\n\n    }\n    throw new MappingException(\"Cannot convert a \" + source.getClass().getName() + \" to a \" + targetType\n        + \" use Tapestry's TypeCoercer instead.\");\n  }\n\n  @Override\n  public <T> T map(final Object source, final TypeRef<T> targetType, final Configuration configuration) {\n    throw new UnsupportedOperationException(\n        \"Tapestry JSON provider does not support TypeRef! Use a Jackson or Gson based provider\");\n  }\n\n}\n","sourceCodeStart":27,"sourceCodeEnd":56,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/spi/mapper/TapestryMappingProvider.java#L27-L56","documentation":"TapestryMappingProvider.map() failed to convert the source object to the requested target type using Tapestry's built-in transformations and fell through to this catch-all MappingException. Conversion runs inside try/catch with the exception swallowed, so any failure (no registered coercer, wrong runtime type) surfaces as this generic message. The message hints that Tapestry's TypeCoercer service would handle it if wired up.","triggerScenarios":"Calling TapestryMappingProvider.map(source, targetType, configuration) where source's runtime type has no registered TypeCoercer transformation to targetType — e.g. mapping a JSONObject to a custom POJO, or a String to a type without a coercer. All TypeRef-based calls go to the other overload (error 157).","commonSituations":"Using the Tapestry integration outside a full Tapestry IoC registry where the TypeCoercer service isn't configured with extra coercers; mapping to POJOs/dates that the default coercer set doesn't cover; switching providers from Jackson to Tapestry and losing deserialization power.","solutions":["Verify a Tapestry TypeCoercer transformation exists for source type -> target type; contribute one via Contribution to TypeCoercer if missing.","Convert only types the default coercers support (String, Number, Boolean, Map, List basics).","Read the JSON into Maps/Lists and build your POJO manually.","Switch to JacksonMappingProvider or GsonMappingProvider, which deserialize into arbitrary POJOs.","Register a custom MappingProvider implementation."],"exampleFix":"// before\nMyPojo p = new TapestryMappingProvider().map(jsonObject, MyPojo.class, configuration); // MappingException\n// after\nMyPojo p = new JacksonMappingProvider().map(jsonObject, MyPojo.class, configuration);","handlingStrategy":"try-catch","validationCode":"MappingProvider mp = new TapestryMappingProvider();\nSet<Class<?>> supported = Set.of(String.class, Integer.class, Long.class, Double.class, Boolean.class, Map.class, List.class);\nif (!supported.contains(targetType) && !targetType.isInstance(source))\n    throw new IllegalArgumentException(\"No Tapestry coercer for \" + source.getClass() + \" -> \" + targetType);","typeGuard":"static <T> boolean canMap(Object source, Class<T> targetType) {\n    return source == null || targetType.isInstance(source)\n        || Number.class.isAssignableFrom(targetType) && source instanceof Number;\n}","tryCatchPattern":"try {\n    T value = tapestryProvider.map(source, targetType, configuration);\n} catch (MappingException e) {\n    T value = fallbackProvider.map(source, targetType, configuration); // e.g. JacksonMappingProvider\n}","preventionTips":["Restrict TapestryMappingProvider usage to types covered by the default TypeCoercer registry.","Contribute custom TypeCoercer transformations in the Tapestry module for POJO targets.","Configure a fallback MappingProvider (Jackson/Gson) for complex type conversions.","Avoid swallowing the inner exception chain — log it when debugging conversion failures."],"tags":["json-path","mapping","tapestry","type-conversion"],"backgroundTag":"incompatible-source-type","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"}