quarkusio/quarkus · error · IllegalArgumentException

Could not serialize the provided output.

Error message

Could not serialize the provided output.

What it means

Funqy's AWS Lambda event output writer wraps any Jackson serialization failure (JacksonException) of the function's return value into a generic IllegalArgumentException so internal details are not exposed in the Lambda response. The original JacksonException is preserved as the cause.

Source

Thrown at extensions/funqy/funqy-amazon-lambda/runtime/src/main/java/io/quarkus/funqy/lambda/event/AwsEventOutputWriter.java:30

 * Responsible for serializing the different data models of the events
 */
public class AwsEventOutputWriter implements LambdaOutputWriter {

    final ObjectMapper mapper;

    public AwsEventOutputWriter(ObjectMapper mapper) {
        // At the moment no special configuration is needed. But we need an ObjectMapper due to different models.
        this.mapper = mapper;
    }

    @Override
    public void writeValue(OutputStream os, Object obj) throws IOException {
        try {
            mapper.writeValue(os, obj);
        } catch (JacksonException e) {
            // to make sure that we do not expose too many details about the issue in the lambda response
            // we have some special treatment for jackson related issues
            throw new IllegalArgumentException("Could not serialize the provided output.", e);
        }
    }

    @Override
    public void writeHeaders(HttpURLConnection conn) {
        conn.setRequestProperty("Content-Type", "application/json");
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Return simple POJOs/records with Jackson-friendly getters; annotate recursive references with @JsonIgnore or @JsonManagedReference/@JsonBackReference
  2. Inspect the JacksonException cause attached to the IllegalArgumentException to find the failing property
  3. If raw output is needed, return a String or byte[] instead of a complex object

Example fix

// before
public Parent find() { Parent p = ...; p.getChild().setParent(p); return p; } // infinite recursion
// after
public Parent find() { Parent p = ...; p.getChild().setParent(null); return p; }
Defensive patterns

Strategy: try-catch

Try / catch

try {
    result = funqFunction(input);
} catch (IllegalArgumentException e) {
    log.error("Function output not serializable", e.getCause());
    return serverErrorResponse();
}

Prevention

When it happens

Trigger: writeValue(OutputStream, Object) is called with a return object Jackson cannot serialize: unserializable types, self-referencing object graphs, failing getters, or invalid Jackson configuration.

Common situations: A funq method returns an object with non-serializable fields (streams, lazy/hydrated entities) or bidirectional references causing infinite recursion; a custom ObjectMapper module throws while writing.

Understand the failure class

Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/5791bd643aa3fab0. Report an issue: GitHub.