{"record":{"id":"15e7d0ad12274e2e","repo":"apache/pulsar","slug":"unable-to-create-avro-schema-for-class-pojo-getna","errorCode":null,"errorMessage":"Unable to create Avro schema for class <pojo.getName()>","messagePattern":"Unable to create Avro schema for class <pojo\\.getName\\(\\)>","errorType":"exception","errorClass":"SchemaSerializationException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/util/SchemaUtil.java","lineNumber":110,"sourceCode":"                validateDefaults.set(savedValidateDefaults);\n            }\n        } else {\n            throw new RuntimeException(\"Schema definition must specify pojo class or schema json definition\");\n        }\n    }\n\n    public static Schema extractAvroSchema(SchemaDefinition schemaDefinition, Class pojo) {\n        try {\n            return parseAvroSchema(pojo.getDeclaredField(\"SCHEMA$\").get(null).toString());\n        } catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException ignored) {\n            ReflectData reflectData = schemaDefinition.getAlwaysAllowNull()\n                     ? new ReflectData.AllowNull()\n                     : new ReflectData();\n            AvroSchema.addLogicalTypeConversions(reflectData, schemaDefinition.isJsr310ConversionEnabled(), false);\n            try {\n                return reflectData.getSchema(pojo);\n            } catch (RuntimeException e) {\n                throw new SchemaSerializationException(\n                        \"Unable to create Avro schema for class \" + pojo.getName(), e);\n            }\n        }\n    }\n}\n","sourceCodeStart":92,"sourceCodeEnd":116,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/util/SchemaUtil.java#L92-L116","documentation":"extractAvroSchema asks Avro's ReflectData (AllowNull or not) to generate a schema for the given pojo class. If Avro throws a RuntimeException while generating the schema, it is wrapped in a SchemaSerializationException with the class name. This means the class itself is not representable as an Avro schema under reflection.","triggerScenarios":"Schema.AVRO(SomePojo.class) where the pojo has unrepresentable types, is an interface/abstract class, lacks a no-arg constructor, or has fields Avro reflection cannot map (e.g. nested generics Avro cannot handle).","commonSituations":"Pojo with fields of unsupported types (Object, interfaces, exotic collections); nested pojo missing public no-arg constructor; nullable handling mismatch when allowNull is disabled; JSR310 types without jsr310ConversionEnabled.","solutions":["Fix the pojo to be Avro-reflectable: public class, public no-arg constructor, fields of Avro-supported types.","Add @AvroSchemaCompatible / use org.apache.avro.reflect annotations (@AvroIgnore, @AvroEncode) on problematic fields.","Enable JSR310 conversion if using java.time types: SchemaDefinition.builder().withJsr310ConversionEnabled(true).","Alternatively provide the schema as explicit JSON instead of reflection."],"exampleFix":"// before\nclass Event { private Event() {} private Object payload; }\nSchema<Event> s = Schema.AVRO(Event.class);\n// after\nclass Event { public Event() {} private byte[] payload; }\nSchema<Event> s = Schema.AVRO(Event.class);","handlingStrategy":"validation","validationCode":"boolean avroReflectable(Class<?> c) {\n    try {\n        c.getDeclaredConstructor().setAccessible(true);\n        return !c.isInterface() && !Modifier.isAbstract(c.getModifiers());\n    } catch (NoSuchMethodException e) {\n        return false; // needs public no-arg constructor\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    Schema<Event> s = Schema.AVRO(Event.class);\n} catch (SchemaSerializationException e) {\n    log.error(\"Pojo not Avro-reflectable: \" + e.getMessage(), e);\n}","preventionTips":["Give pojos public no-arg constructors and Avro-supported field types","Annotate un-mappable fields with @AvroIgnore","Enable withJsr310ConversionEnabled(true) for java.time types","Prefer generating schema JSON at build time for complex types"],"tags":["avro","schema","pojo","serialization"],"backgroundTag":"avro-schema-generation-failed","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}