{"record":{"id":"0d16808a1fe6d2ec","repo":"OpenFeign/feign","slug":"class-is-not-a-type-supported-by-this-encoder","errorCode":null,"errorMessage":"{class} is not a type supported by this encoder.","messagePattern":"(.+?) is not a type supported by this encoder\\.","errorType":"exception","errorClass":"EncodeException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/feign/codec/DefaultEncoder.java","lineNumber":46,"sourceCode":"   *\n   * @param object {@inheritDoc}\n   * @param bodyType {@inheritDoc}\n   * @param template {@inheritDoc}\n   * @return {@inheritDoc}\n   */\n  @Override\n  public boolean canEncode(Object object, Type bodyType, RequestTemplate template) {\n    return bodyType == String.class || bodyType == byte[].class || object == null;\n  }\n\n  @Override\n  public void encode(Object object, Type bodyType, RequestTemplate template) {\n    if (bodyType == String.class) {\n      template.body(object.toString());\n    } else if (bodyType == byte[].class) {\n      template.body((byte[]) object, null);\n    } else if (object != null) {\n      throw new EncodeException(\n          format(\"%s is not a type supported by this encoder.\", object.getClass()));\n    }\n  }\n}\n","sourceCodeStart":28,"sourceCodeEnd":51,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/core/src/main/java/feign/codec/DefaultEncoder.java#L28-L51","documentation":"Feign's DefaultEncoder only encodes String and byte[] bodies; if the body object is non-null and of any other type, it throws EncodeException stating the class is unsupported. It exists as the no-dependency fallback encoder when no JSON encoder is configured.","triggerScenarios":"Calling a POST/PUT method with a POJO, Map, or List body on a Feign.builder() that has no explicit Encoder (so DefaultEncoder is used). Only String and byte[] pass.","commonSituations":"Forgetting to register JacksonEncoder/GsonEncoder on the builder; switching from a Spring-based builder (which had an encoder) to a plain Feign.builder(); assuming form/query objects are auto-encoded.","solutions":["Register a proper encoder: Feign.builder().encoder(new JacksonEncoder()) (add feign-jackson) or GsonEncoder/SpringEncoder","Serialize the body to String or byte[] yourself before passing it","For form data, use @FormParams with a matching encoder (FormEncoder)","Check that the dependency providing the encoder is on the classpath"],"exampleFix":"// before\nFeign.builder().target(Api.class); // api.createUser(user) POJO -> EncodeException\n// after\nFeign.builder().encoder(new JacksonEncoder()).target(Api.class);","handlingStrategy":"type-guard","validationCode":"if (!(body instanceof String) && !(body instanceof byte[])) { requireExplicitEncoder = true; }","typeGuard":"static boolean defaultEncoderHandles(Object body) { return body == null || body instanceof String || body instanceof byte[]; }","tryCatchPattern":"try { api.post(dto); } catch (EncodeException e) { throw new IllegalStateException(\"Register an Encoder (e.g. JacksonEncoder) for \" + dto.getClass(), e); }","preventionTips":["Always register an encoder when request bodies are POJOs","Add feign-jackson/feign-gson dependencies explicitly","Restrict @Body types to String/byte[] if staying on DefaultEncoder","Smoke-test one POST at startup to verify encoding works"],"tags":["encoding","encoder","unsupported-type","json","java"],"backgroundTag":"unsupported-enum-value","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"}