{"record":{"id":"427d34c4a64fd528","repo":"apache/pulsar","slug":"failed-to-serialize-input-with-error-s-please-c","errorCode":null,"errorMessage":"Failed to serialize input with error: %s. Please checkif input data conforms with the schema of the input topic.","messagePattern":"Failed to serialize input with error: (.+?)\\. Please checkif input data conforms with the schema of the input topic\\.","errorType":"http","errorClass":"RestException","httpStatus":400,"severity":"error","filePath":"pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java","lineNumber":1220,"sourceCode":"                if (msg == null) {\n                    break;\n                }\n                if (msg.getProperties().containsKey(\"__pfn_input_msg_id__\")\n                        && msg.getProperties().containsKey(\"__pfn_input_topic__\")) {\n                    MessageId newMsgId = MessageId.fromByteArray(\n                            Base64.getDecoder().decode((String) msg.getProperties().get(\"__pfn_input_msg_id__\")));\n\n                    if (msgId.equals(newMsgId)\n                            && msg.getProperties().get(\"__pfn_input_topic__\")\n                            .equals(TopicName.get(inputTopicToWrite).toString())) {\n                        return new String(msg.getData());\n                    }\n                }\n                curTime = System.currentTimeMillis();\n            }\n            throw new RestException(Status.REQUEST_TIMEOUT, \"Request Timed Out\");\n        } catch (SchemaSerializationException e) {\n            throw new RestException(Status.BAD_REQUEST, String.format(\n                    \"Failed to serialize input with error: %s. Please check\"\n                            + \"if input data conforms with the schema of the input topic.\",\n                    e.getMessage()));\n        } catch (IOException e) {\n            throw new RestException(Status.INTERNAL_SERVER_ERROR, e.getMessage());\n        } finally {\n            if (reader != null) {\n                reader.closeAsync();\n            }\n            if (producer != null) {\n                producer.closeAsync();\n            }\n        }\n    }\n\n    @Override\n    public FunctionState getFunctionState(final String tenant,\n                                          final String namespace,","sourceCodeStart":1202,"sourceCodeEnd":1238,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java#L1202-L1238","documentation":"When the trigger payload cannot be serialized for the input topic's schema (SchemaSerializationException), triggerFunction returns HTTP 400 with 'Failed to serialize input with error: %s. Please check if input data conforms with the schema of the input topic.' The message bytes you sent don't match the topic's declared schema.","triggerScenarios":"Posting text/JSON to an input topic with Avro/Protobuf schema; sending data that violates the topic's schema (wrong types, missing required fields); schema changed on the topic after the trigger script was written.","commonSituations":"Testing an Avro-schema topic with plain strings from curl; schema registry updates (topic schema evolved, old payloads rejected); passing numeric data as strings for typed schemas.","solutions":["Read the embedded SchemaSerializationException message in the response to see the exact encode failure, then fix the payload to conform to the topic schema.","Check the topic's schema (pulsar-admin schemas get) and craft the test payload accordingly (e.g., valid JSON for JSON schema, base64 Avro for Avro).","If the schema changed recently, update the payload generator or restore the expected schema version.","Trigger via a client that encodes with the topic's Schema object rather than raw bytes."],"exampleFix":"// before\ncurl -X POST --data-binary 'not-json' .../functions/.../f?topic=avroTopic\n// after: send schema-conformant payload\ncurl -X POST --data-binary '{\"id\":\"1\",\"value\":42}' .../functions/.../f?topic=jsonTopic","handlingStrategy":"validation","validationCode":"// Encode the payload with the topic's schema before triggering\nSchemaRecord record = new SchemaRecord(\"1\", 42);\nbyte[] encoded = schema.encode(record); // throws immediately if it doesn't conform\nassert encoded.length > 0;","typeGuard":null,"tryCatchPattern":"try { triggerFunction(..., payload, null); }\ncatch (PulsarAdminException e) {\n  if (e.getResponseStatus() == 400 && e.getMessage().contains(\"Failed to serialize\"))\n    throw new SchemaMismatchException(\"payload violates topic schema: \" + e.getMessage());\n  throw e;\n}","preventionTips":["Fetch the topic schema (pulsar-admin schemas get) and generate payloads from it","Use a Pulsar client producer with the topic's Schema to author test payloads instead of raw strings","Re-run payload conformance checks whenever a topic schema is updated"],"tags":["schema","serialization","pulsar-functions","bad-request"],"backgroundTag":"schema-serialization-failed","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}