{"record":{"id":"75d435c22ce1a296","repo":"kestra-io/kestra","slug":"couldn-t-write-the-request-body-as-yaml","errorCode":null,"errorMessage":"Couldn't write the request body as YAML","messagePattern":"Couldn't write the request body as YAML","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/HttpFunction.java","lineNumber":49,"sourceCode":"import io.pebbletemplates.pebble.template.EvaluationContext;\nimport io.pebbletemplates.pebble.template.EvaluationContextImpl;\nimport io.pebbletemplates.pebble.template.PebbleTemplate;\nimport jakarta.inject.Inject;\nimport jakarta.inject.Provider;\nimport jakarta.inject.Singleton;\n\n@Singleton\npublic class HttpFunction<T> implements KestraFunction {\n    public static final String NAME = \"http\";\n\n    private final MessageBodyWriter<T> FALLBACK_CONTENT_WRITER = (type, mediaType, object, outgoingHeaders, outputStream) ->\n    {\n        if (mediaType == MediaType.APPLICATION_YAML_TYPE || mediaType.equals(MediaType.of(\"application/yaml\"))) {\n            try {\n                outputStream.write(JacksonMapper.ofYaml().writeValueAsString(object).getBytes(StandardCharsets.UTF_8));\n                return;\n            } catch (IOException e) {\n                throw new PebbleException(e, \"Couldn't write the request body as YAML\");\n            }\n        }\n\n        throw new PebbleException(new IllegalArgumentException(\"Unsupported content type: \" + mediaType), \"Unsupported content type \");\n    };\n\n    @Inject\n    private DefaultMessageBodyHandlerRegistry defaultMessageBodyHandlerRegistry;\n\n    @Inject\n    private Provider<RunContextFactory> runContextFactoryProvider;\n\n    @Override\n    public Object execute(Map<String, Object> args, PebbleTemplate self, EvaluationContext context, int lineNumber) {\n        throwIfMissingArgs(args, self, lineNumber);\n\n        EvaluationContextImpl evaluationContext = (EvaluationContextImpl) context;\n        Map<String, Object> pebbleVariables = evaluationContext.getScopeChain().getGlobalScopes().stream()","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/HttpFunction.java#L31-L67","documentation":"Thrown by the 'http' Pebble function's fallback MessageBodyWriter when it tries to serialize the request body as YAML and Jackson's YAML mapper raises an IOException. The fallback writer only runs when Micronaut has no registered writer for the body type/content-type pair, so this points to a YAML-specific serialization problem such as non-string map keys, circular references, or a type Jackson cannot introspect.","triggerScenarios":"Calling http(uri, method='POST', body=<object>, contentType='application/yaml') where <object> is not YAML-serializable — e.g. a Map with non-String keys, a self-referencing object, or a type with no accessible properties.","commonSituations":"Passing a raw Pebble map with numeric keys (YAML forbids non-scalar keys), passing an execution/task object that holds circular references, or assuming 'application/yaml' works for an arbitrary Java type when no custom writer is registered.","solutions":["Switch contentType to 'application/json' (the default), which has a registered writer and accepts more object shapes.","Flatten the body into a plain map with only string keys and primitive/list/map values before passing it as body.","If YAML is required, pre-serialize the body to a YAML string yourself and pass it with a contentType that has a writer (e.g. text/plain).","Inspect the wrapped IOException cause to find which field Jackson could not serialize."],"exampleFix":"// before\n{{ http(uri, method='POST', body=myMap, contentType='application/yaml') }}\n// after\n{{ http(uri, method='POST', body=myMap, contentType='application/json') }}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to 'application/json' for the http function body; only use 'application/yaml' for plain string-keyed maps.","Avoid passing complex execution/task objects as the body; extract the fields you need into a new map first.","Ensure map bodies contain only String keys and primitive/list/map values before choosing YAML."],"tags":["pebble","http","yaml","serialization","jackson"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}