{"record":{"id":"d848869c2b8a75af","repo":"floci-io/floci","slug":"awsboolean-cannot-serialize-non-boolean-value","errorCode":null,"errorMessage":"AWSBoolean cannot serialize non-boolean value: {}","messagePattern":"AWSBoolean cannot serialize non-boolean value: (.+?)","errorType":"validation","errorClass":"CoercingSerializeException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/github/hectorvent/floci/services/appsync/graphql/scalars/AppSyncScalars.java","lineNumber":277,"sourceCode":"                return str;\n            }\n            @Override\n            public String parseLiteral(Object input) {\n                if (!(input instanceof StringValue sv)) return null;\n                return parseValue(sv.getValue());\n            }\n        })\n        .build();\n\n    public static final GraphQLScalarType AWS_BOOLEAN = GraphQLScalarType.newScalar()\n        .name(\"AWSBoolean\")\n        .description(\"A boolean value\")\n        .coercing(new Coercing<Boolean, Boolean>() {\n            @Override\n            public Boolean serialize(Object dataFetcherResult) {\n                if (dataFetcherResult == null) return null;\n                if (dataFetcherResult instanceof Boolean b) return b;\n                throw new CoercingSerializeException(\"AWSBoolean cannot serialize non-boolean value: \" + dataFetcherResult.getClass().getSimpleName());\n            }\n            @Override\n            public Boolean parseValue(Object input) {\n                if (input instanceof Boolean b) return b;\n                throw new CoercingParseValueException(\"AWSBoolean cannot parse non-boolean value: \" + input);\n            }\n            @Override\n            public Boolean parseLiteral(Object input) {\n                if (input instanceof graphql.language.BooleanValue bv) return bv.isValue();\n                throw new CoercingParseLiteralException(\"AWSBoolean must be a boolean literal\");\n            }\n        })\n        .build();\n\n    public static final GraphQLScalarType AWS_LONG = GraphQLScalarType.newScalar()\n        .name(\"AWSLong\")\n        .description(\"A 64-bit signed integer\")\n        .coercing(new Coercing<Long, Long>() {","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/floci-io/floci/blob/62ff490619e7bd3554597c28c704081b4c15add5/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/scalars/AppSyncScalars.java#L259-L295","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Map to a real boolean in the resolver before returning: rs.getBoolean(\"flag\") or Boolean.parseBoolean on known string encodings","Change the data-source read to a typed boolean accessor instead of getObject","If the source truly stores 0/1 or \"Y\"/\"N\", write an explicit mapping function in the resolver","Consider the built-in Boolean scalar if lenient coercion is actually desired"],"exampleFix":"// before\nMap<String,Object> item = Map.of(\"active\", 1); // Integer -> serialize throws\n\n// after\nMap<String,Object> item = Map.of(\"active\", ((Number) raw).intValue() != 0); // true","handlingStrategy":"type-guard","validationCode":"// Resolver side: guarantee the value you return is Boolean\nObject v = source.get(\"active\");\nboolean b = (v instanceof Boolean bo) ? bo\n    : (v instanceof Number n) ? n.intValue() != 0\n    : Boolean.parseBoolean(String.valueOf(v));\nreturn b;","typeGuard":"const isAwsBooleanSerializable = (v: unknown): v is boolean => typeof v === 'boolean';","tryCatchPattern":"catch (CoercingSerializeException e) { // your resolver returned a non-boolean: fix the mapping, don't catch-and-continue in production }","preventionTips":["Map datasource 0/1 and \"Y\"/\"N\" encodings to boolean in resolvers","Use typed accessors (getBoolean) instead of getObject","Add a contract test asserting AWSBoolean fields are java.lang.Boolean"],"tags":["graphql","appsync","awsboolean","serialize","resolvers"],"backgroundTag":null,"analyzedSha":"62ff490619e7bd3554597c28c704081b4c15add5","analyzedAt":"2026-08-14T14:25:23.764Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}