{"record":{"id":"a3cea708b092b625","repo":"OpenFeign/feign","slug":"cannot-convert-to-type-type-gettypename","errorCode":null,"errorMessage":"Cannot convert to type: ${type.getTypeName()}","messagePattern":"Cannot convert to type: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"jackson-jr/src/main/java/feign/jackson/jr/JacksonJrDecoder.java","lineNumber":137,"sourceCode":"  @Override\n  public Object convert(Object object, Type type) throws IOException {\n    String json = mapper.asString(object);\n    if (type instanceof ParameterizedType) {\n      ParameterizedType pt = (ParameterizedType) type;\n      Type rawType = pt.getRawType();\n      Type[] args = pt.getActualTypeArguments();\n      if (rawType.equals(List.class)) {\n        return mapper.listOfFrom((Class<?>) args[0], json);\n      }\n      if (rawType.equals(Map.class)) {\n        return mapper.mapOfFrom((Class<?>) args[1], json);\n      }\n      type = rawType;\n    }\n    if (type instanceof Class) {\n      return mapper.beanFrom((Class<?>) type, json);\n    }\n    throw new IOException(\"Cannot convert to type: \" + type.getTypeName());\n  }\n\n  @Override\n  public boolean canDecode(Response response, Type type) {\n    return Util.isJsonContentType(response);\n  }\n}\n","sourceCodeStart":119,"sourceCodeEnd":145,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/jackson-jr/src/main/java/feign/jackson/jr/JacksonJrDecoder.java#L119-L145","documentation":"JacksonJrDecoder.convert (the Encoder-side conversion of an object to the requested Type) throws IOException when the target type is neither a handled ParameterizedType nor a plain Class — mapper.beanFrom can only target concrete classes. It mirrors findTransformer's DecodeException but on the object-to-JSON conversion path.","triggerScenarios":"Calling JacksonJrEncoder/convert with a target Type that resolves to something other than a Class (interface, generic type variable, array of generics in unsupported shapes).","commonSituations":"Serializing objects typed to interfaces without concrete classes; generic method signatures where Type resolution yields TypeVariable; using jackson-jr encoder with types the full Jackson module would support.","solutions":["Pass a concrete bean Class as the target type.","Use the full feign-jackson encoder/decoder for complex generic types.","Convert the object to a concrete DTO before encoding.","Provide a custom Encoder for the unsupported type."],"exampleFix":"// before\nencoder.encode(obj, MyApiInterface.class, template); // interface type\n// after\nencoder.encode(obj, UserDto.class, template); // concrete bean class","handlingStrategy":"type-guard","validationCode":"static boolean jacksonJrCanEncode(Type type) {\n  if (type instanceof ParameterizedType) type = ((ParameterizedType) type).getRawType();\n  return type instanceof Class;\n}","typeGuard":"static boolean isConcreteClass(Type type) {\n  if (type instanceof ParameterizedType) type = ((ParameterizedType) type).getRawType();\n  return type instanceof Class && !((Class<?>) type).isInterface() && !type.equals(Object.class);\n}","tryCatchPattern":"try {\n  encoder.encode(obj, type, template);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Cannot convert to type\")) {\n    throw new IllegalArgumentException(\"Target type must be a concrete bean class for jackson-jr\", e);\n  }\n  throw e;\n}","preventionTips":["Pass concrete DTO classes to encoders","Avoid encoding objects typed as interfaces","Switch to the full Jackson module for generic-rich types"],"tags":["jackson-jr","encoder","type-mismatch","serialization"],"backgroundTag":"type-mismatch","analyzedSha":"e2a1e27560a1e68840c34f031afca88b36096e30","analyzedAt":"2026-09-10T12:37:37.238Z","contentChangedAt":"2026-09-10T12:37:37.238Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}