{"record":{"id":"85d587e418cb99cc","repo":"apple/pkl","slug":"cannot-convert-s-to-s-because-no-conversion","errorCode":null,"errorMessage":"Cannot convert `%s` to `%s` because no conversion was found.","messagePattern":"Cannot convert `(.+?)` to `(.+?)` because no conversion was found\\.","errorType":"exception","errorClass":"ConversionException","httpStatus":null,"severity":"error","filePath":"pkl-config-java/src/main/java/org/pkl/config/java/mapper/ValueMapperImpl.java","lineNumber":114,"sourceCode":"    @SuppressWarnings(\"unchecked\")\n    var implConverter = (Converter<S, T>) convertersMap.get(implKey);\n    if (implConverter != null) {\n      // TODO: give converter a chance to copy itself to avoid pollution of its inline caches\n      convertersMap.put(key, implConverter);\n      return implConverter;\n    }\n\n    // create implType converter\n    for (ConverterFactory factory : factories) {\n      @SuppressWarnings({\"unchecked\", \"rawtypes\"})\n      Optional<Converter<S, T>> newConverter = (Optional) factory.create(sourceType, implType);\n      if (newConverter.isPresent()) {\n        convertersMap.put(key, newConverter.get());\n        return newConverter.get();\n      }\n    }\n\n    throw new ConversionException(\n        String.format(\n            \"Cannot convert `%s` to `%s` because no conversion was found.\",\n            sourceType.getQualifiedName(), targetType.getTypeName()));\n  }\n\n  @Override\n  public ValueMapperBuilder toBuilder() {\n    return ValueMapperBuilder.unconfigured()\n        .setConversions(conversions)\n        .setConverterFactories(factories)\n        .setTypeMappings(typeMappings);\n  }\n}\n","sourceCodeStart":96,"sourceCodeEnd":128,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-config-java/src/main/java/org/pkl/config/java/mapper/ValueMapperImpl.java#L96-L128","documentation":"After exhausting the registered converters and any type-mapping-based converter construction, getConverter gives up and throws ConversionException stating that no conversion path exists from the Pkl source type to the requested Java target type.","triggerScenarios":"valueMapper.map(pklValue, targetType) where the Pkl value's type cannot be converted to targetType — no registered Converter, no applicable TypeMapping, and no default conversion (e.g. mapping a Pkl ListING to a custom POJO without a registered converter).","commonSituations":"Mapping Pkl modules to custom Java classes without registering a converter or type mapping; requesting an incompatible target (Pkl Int to java.time.Duration); typos in the target class.","solutions":["Register a Converter for the (source, target) pair via ValueConverter/converters configuration.","Register a TypeMapping so the value maps onto a supported implementation type.","Use a supported target type (List, Map, String, numbers, java.time types, etc.)."],"exampleFix":"// before\nmapper.map(pklObject, MyPojo.class); // no converter\n// after\nmapper.registerConverter(new Converter<PklObject, MyPojo>() { ... });\nmapper.map(pklObject, MyPojo.class);","handlingStrategy":"try-catch","validationCode":"if (!SUPPORTED_TARGETS.contains(targetType)) throw new IllegalArgumentException(\"register a converter for \" + targetType);","typeGuard":null,"tryCatchPattern":"try { return mapper.map(value, targetType); } catch (ConversionException e) { return fallbackConversion(value); }","preventionTips":["Register converters/type mappings for custom classes at ValueMapper setup time","Prefer built-in supported target types when possible","Cover each mapping target with a test that maps a representative Pkl value"],"tags":["java","conversion","value-mapper","unsupported-conversion"],"backgroundTag":"unsupported-conversion","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}