OpenFeign/feign · error · EncodeException
is not a type supported by this encoder.
Error message
%s is not a type supported by this encoder.
What it means
JsonEncoder.encode() only serializes objects that are already org.json JSONObject or JSONArray instances; anything else throws an EncodeException saying the bodyType is not supported. Unlike Jackson/Gson encoders it performs no reflection-based data binding.
Solutions
- Build the request body as an org.json JSONObject or JSONArray before encoding
- Switch to JacksonEncoder or GsonEncoder for POJO/Map serialization
- Write a custom Encoder that converts POJOs/Maps into JSONObject and delegates
Example fix
// before api.createUser(user); // user is a POJO -> EncodeException // after api.createUser(new JSONObject(pojoToMap(user))); // or: Feign.builder().encoder(new JacksonEncoder())
Defensive patterns
Strategy: type-guard
Validate before calling
if (!(body instanceof JSONObject) && !(body instanceof JSONArray)) {
throw new IllegalArgumentException("JsonEncoder requires JSONObject/JSONArray, got " + body.getClass());
} Type guard
boolean encodable(Object o){ return o instanceof JSONObject || o instanceof JSONArray; } Try / catch
try { encoder.encode(body, bodyType, template); }
catch (EncodeException e) { throw new IllegalStateException("Wrap body in JSONObject or use JacksonEncoder", e); } Prevention
- Always construct request bodies as org.json types with JsonEncoder
- Prefer JacksonEncoder/GsonEncoder for POJOs and Maps
- Add a unit test asserting the encoder supports each request body type
When it happens
Trigger: Calling a POST/PUT Feign method whose body parameter is a POJO, Map, List, or String while using JsonEncoder as the encoder.
Common situations: Assuming JsonEncoder behaves like JacksonEncoder; sending request bodies after migrating encoders; passing a Map that was never wrapped in a JSONObject.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- is not a type supported by this encoder.
- ${jsonException.getMessage()}
- This form encoder has no delegate encoder, so it can only…
- Output closing error
- Writing file's ' ' content error
AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10).
Data as JSON: /api/errors/2039b544ede0bf3d.
Report an issue: GitHub.
Appendix: source
Thrown at json/src/main/java/feign/json/JsonEncoder.java:65
* .target(GitHub.class, "https://api.github.com");
*
* JSONObject contributor = new JSONObject();
*
* contributor.put("login", "radio-rogal");
* contributor.put("contributions", 0);
* github.create("openfeign", "feign", contributor);
* </pre>
*/
public class JsonEncoder implements Encoder, PredicatedEncoder {
@Override
public void encode(Object object, Type bodyType, RequestTemplate template)
throws EncodeException {
if (object == null) return;
if (object instanceof JSONArray || object instanceof JSONObject) {
template.body(object.toString());
} else {
throw new EncodeException(format("%s is not a type supported by this encoder.", bodyType));
}
}
@Override
public boolean canEncode(Object object, Type bodyType, RequestTemplate template) {
return Util.isJsonContentType(template);
}
}
View on GitHub (pinned to e2a1e27560)