{"record":{"id":"4b86a028785dd7dd","repo":"OpenFeign/feign","slug":"e-getmessage-4b86a0","errorCode":null,"errorMessage":"${e.getMessage()}","messagePattern":"\\$\\{e\\.getMessage\\(\\)\\}","errorType":"exception","errorClass":"EncodeException","httpStatus":null,"severity":"error","filePath":"jackson3/src/main/java/feign/jackson3/Jackson3Encoder.java","lineNumber":61,"sourceCode":"        JsonMapper.builder()\n            .changeDefaultPropertyInclusion(\n                incl -> incl.withValueInclusion(JsonInclude.Include.NON_NULL))\n            .enable(SerializationFeature.INDENT_OUTPUT)\n            .addModules(modules)\n            .build());\n  }\n\n  public Jackson3Encoder(JsonMapper mapper) {\n    this.mapper = mapper;\n  }\n\n  @Override\n  public void encode(Object object, Type bodyType, RequestTemplate template) {\n    try {\n      JavaType javaType = mapper.getTypeFactory().constructType(bodyType);\n      template.body(mapper.writerFor(javaType).writeValueAsBytes(object), Util.UTF_8);\n    } catch (JacksonException e) {\n      throw new EncodeException(e.getMessage(), e);\n    }\n  }\n\n  @Override\n  public boolean canEncode(Object object, Type bodyType, RequestTemplate template) {\n    return Util.isJsonContentType(template);\n  }\n}\n","sourceCodeStart":43,"sourceCodeEnd":70,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/jackson3/src/main/java/feign/jackson3/Jackson3Encoder.java#L43-L70","documentation":"Feign's Jackson3Encoder wraps any JacksonException thrown while serializing the request body into a feign EncodeException, keeping the original Jackson message as the message. This means the ObjectMapper could not convert your object into JSON bytes for the given declared body type. It is a wrapper around an underlying serialization problem, not a network issue.","triggerScenarios":"Calling encode() on Jackson3Encoder when mapper.writerFor(javaType).writeValueAsBytes(object) throws a JacksonException - e.g. serializing an object with no accessible properties, an invalid JavaType derived from a generic Type, self-referential structures exceeding max depth, or a custom serializer throwing.","commonSituations":"Encoding POJOs without getters and without field visibility configured; using types like Object or raw generics that Jackson cannot resolve; missing jackson-databind serializers for third-party types (Instant, Optional without modules); cyclic object graphs.","solutions":["Read the wrapped cause (getCause()) - the JacksonException message names the exact property/class that failed","Ensure the DTO has public getters or annotate/enable field visibility (mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY))","Register needed Jackson modules (JavaTimeModule, Jdk8Module, etc.) on the ObjectMapper passed to Jackson3Encoder.create","Verify the Type passed to encode matches the actual runtime object's type (avoid raw Object bodies)","If serializing a third-party type, add a custom JsonSerializer or a mixin"],"exampleFix":"// before\nFeign.builder().encoder(new Jackson3Encoder(new ObjectMapper()));\n// after\nObjectMapper mapper = new ObjectMapper();\nmapper.registerModule(new JavaTimeModule());\nmapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);\nFeign.builder().encoder(new Jackson3Encoder(mapper));","handlingStrategy":"try-catch","validationCode":"// before encoding\nif (object == null) throw new IllegalArgumentException(\"body must not be null\");\nif (!mapper.canSerialize(object.getClass())) {\n  throw new IllegalStateException(\"ObjectMapper cannot serialize \" + object.getClass());\n}","typeGuard":"static boolean isEncodable(ObjectMapper mapper, Object o) {\n  return o != null && mapper.canSerialize(o.getClass());\n}","tryCatchPattern":"try {\n  encoder.encode(object, bodyType, template);\n} catch (EncodeException e) {\n  Throwable root = e;\n  while (root.getCause() != null) root = root.getCause();\n  throw new IllegalStateException(\"Jackson serialization failed: \" + root.getMessage(), e);\n}","preventionTips":["Register all required Jackson modules (JavaTimeModule, Jdk8Module, ParameterNamesModule) at client construction","Ensure DTOs have accessible getters or configure property visibility once on the shared ObjectMapper","Avoid returning raw Object or unbounded generic types as request bodies","Break cyclic object references or use @JsonManagedReference/@JsonBackReference","Unit-test encoding of every DTO type before wiring the Feign client"],"tags":["jackson","serialization","feign","encoder"],"backgroundTag":"json-marshal-failed","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"}