OpenFeign/feign · error · EncodeException

is not a type supported by this encoder.

Error message

{class} is not a type supported by this encoder.

What it means

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.

Solutions

  1. Register a proper encoder: Feign.builder().encoder(new JacksonEncoder()) (add feign-jackson) or GsonEncoder/SpringEncoder
  2. Serialize the body to String or byte[] yourself before passing it
  3. For form data, use @FormParams with a matching encoder (FormEncoder)
  4. Check that the dependency providing the encoder is on the classpath

Example fix

// before
Feign.builder().target(Api.class); // api.createUser(user) POJO -> EncodeException
// after
Feign.builder().encoder(new JacksonEncoder()).target(Api.class);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(body instanceof String) && !(body instanceof byte[])) { requireExplicitEncoder = true; }

Type guard

static boolean defaultEncoderHandles(Object body) { return body == null || body instanceof String || body instanceof byte[]; }

Try / catch

try { api.post(dto); } catch (EncodeException e) { throw new IllegalStateException("Register an Encoder (e.g. JacksonEncoder) for " + dto.getClass(), e); }

Prevention

When it happens

Trigger: 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.

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

Related errors


AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10). Data as JSON: /api/errors/0d16808a1fe6d2ec. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/feign/codec/DefaultEncoder.java:46

   *
   * @param object {@inheritDoc}
   * @param bodyType {@inheritDoc}
   * @param template {@inheritDoc}
   * @return {@inheritDoc}
   */
  @Override
  public boolean canEncode(Object object, Type bodyType, RequestTemplate template) {
    return bodyType == String.class || bodyType == byte[].class || object == null;
  }

  @Override
  public void encode(Object object, Type bodyType, RequestTemplate template) {
    if (bodyType == String.class) {
      template.body(object.toString());
    } else if (bodyType == byte[].class) {
      template.body((byte[]) object, null);
    } else if (object != null) {
      throw new EncodeException(
          format("%s is not a type supported by this encoder.", object.getClass()));
    }
  }
}

View on GitHub (pinned to e2a1e27560)