floci-io/floci · error · CoercingSerializeException

AWSBoolean cannot serialize non-boolean value: {}

Error message

AWSBoolean cannot serialize non-boolean value: {}

What it means

Thrown by the AWSBoolean scalar's serialize when the resolver/data-fetcher returned a non-null value that is not a Boolean (e.g. a String or Integer) for a field typed AWSBoolean. Unlike graphql-java's built-in Boolean scalar, this strict scalar refuses to coerce truthy strings or numbers on the output path.

Source

Thrown at src/main/java/io/github/hectorvent/floci/services/appsync/graphql/scalars/AppSyncScalars.java:277

                return str;
            }
            @Override
            public String parseLiteral(Object input) {
                if (!(input instanceof StringValue sv)) return null;
                return parseValue(sv.getValue());
            }
        })
        .build();

    public static final GraphQLScalarType AWS_BOOLEAN = GraphQLScalarType.newScalar()
        .name("AWSBoolean")
        .description("A boolean value")
        .coercing(new Coercing<Boolean, Boolean>() {
            @Override
            public Boolean serialize(Object dataFetcherResult) {
                if (dataFetcherResult == null) return null;
                if (dataFetcherResult instanceof Boolean b) return b;
                throw new CoercingSerializeException("AWSBoolean cannot serialize non-boolean value: " + dataFetcherResult.getClass().getSimpleName());
            }
            @Override
            public Boolean parseValue(Object input) {
                if (input instanceof Boolean b) return b;
                throw new CoercingParseValueException("AWSBoolean cannot parse non-boolean value: " + input);
            }
            @Override
            public Boolean parseLiteral(Object input) {
                if (input instanceof graphql.language.BooleanValue bv) return bv.isValue();
                throw new CoercingParseLiteralException("AWSBoolean must be a boolean literal");
            }
        })
        .build();

    public static final GraphQLScalarType AWS_LONG = GraphQLScalarType.newScalar()
        .name("AWSLong")
        .description("A 64-bit signed integer")
        .coercing(new Coercing<Long, Long>() {

View on GitHub (pinned to 62ff490619)

Solutions

  1. Map to a real boolean in the resolver before returning: rs.getBoolean("flag") or Boolean.parseBoolean on known string encodings
  2. Change the data-source read to a typed boolean accessor instead of getObject
  3. If the source truly stores 0/1 or "Y"/"N", write an explicit mapping function in the resolver
  4. Consider the built-in Boolean scalar if lenient coercion is actually desired

Example fix

// before
Map<String,Object> item = Map.of("active", 1); // Integer -> serialize throws

// after
Map<String,Object> item = Map.of("active", ((Number) raw).intValue() != 0); // true
Defensive patterns

Strategy: type-guard

Validate before calling

// Resolver side: guarantee the value you return is Boolean
Object v = source.get("active");
boolean b = (v instanceof Boolean bo) ? bo
    : (v instanceof Number n) ? n.intValue() != 0
    : Boolean.parseBoolean(String.valueOf(v));
return b;

Type guard

const isAwsBooleanSerializable = (v: unknown): v is boolean => typeof v === 'boolean';

Try / catch

catch (CoercingSerializeException e) { // your resolver returned a non-boolean: fix the mapping, don't catch-and-continue in production }

Prevention

When it happens

Trigger: A resolver backing an AWSBoolean field returns "true" (String), 1 (Integer), or an enum-like object from the data source instead of java.lang.Boolean, and the response serialization step calls the scalar's serialize.

Common situations: Backing data store (DynamoDB-style, relational column, JSON document) modeling booleans as 0/1 or "Y"/"N"/"true" strings; resolvers passing raw map values through without mapping; schema changed a field to AWSBoolean but code still emits strings.

Related errors


AI-assisted analysis of floci-io/floci@62ff490619 (2026-08-14). Data as JSON: /api/errors/d848869c2b8a75af. Report an issue: GitHub.