You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using my Jackson-dataformat-avro jar to parse POJO (which are going to accept deserialized json & I don't control schema of those JSON) and subsequently use those POJO to map to a GenericRecord for Avro. The JSON schema has all bad naming conventions like hyphen and underscore. When I try to set up the AvroSchemaWrapper in this way :
ObjectMapper mapper = new ObjectMapper(new AvroFactory());
AvroSchemaGenerator gen = new AvroSchemaGenerator();
mapper.acceptJsonFormatVisitor(Response.class, gen);
AvroSchema schemaWrapper = gen.getGeneratedSchema();
return schemaWrapper.getAvroSchema();
I get exception while initialization of my Java Job saying :
Caused by: org.apache.avro.SchemaParseException: Illegal character in: User-Agent
at org.apache.avro.Schema.validateName(Schema.java:1561)
at org.apache.avro.Schema.access$400(Schema.java:87)
at org.apache.avro.Schema$Field.(Schema.java:541)
at org.apache.avro.Schema$Field.(Schema.java:580)
at com.fasterxml.jackson.dataformat.avro.schema.RecordVisitor.schemaFieldForWriter(RecordVisitor.java:189)
at com.fasterxml.jackson.dataformat.avro.schema.RecordVisitor.optionalProperty(RecordVisitor.java:117)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.depositSchemaProperty(BeanPropertyWriter.java:839)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.acceptJsonFormatVisitor(BeanSerializerBase.java:912)
at com.fasterxml.jackson.dataformat.avro.schema.RecordVisitor.schemaFieldForWriter(RecordVisitor.java:174)
at com.fasterxml.jackson.dataformat.avro.schema.RecordVisitor.optionalProperty(RecordVisitor.java:117)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.depositSchemaProperty(BeanPropertyWriter.java:839)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.acceptJsonFormatVisitor(BeanSerializerBase.java:912)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.acceptJsonFormatVisitor(DefaultSerializerProvider.java:566)
at com.fasterxml.jackson.databind.ObjectMapper.acceptJsonFormatVisitor(ObjectMapper.java:4438)
at com.fasterxml.jackson.databind.ObjectMapper.acceptJsonFormatVisitor(ObjectMapper.java:4417)
at ai.lily.sample.pipeline.SimpleMapper.generateAvroSchemaFromJacksonPOJO(SimpleMapper.java:99)
at ai.lily.sample.pipeline.SimpleMapper.(SimpleMapper.java:29)
Am I doing something wrong , can i (While extracting Avro Schema ) allow parser to not use @JsonProperty to define Avro schema field names ??
The text was updated successfully, but these errors were encountered:
Jackson requires logical property names to be used to match to Avro schema. But it is possible to both define safe property names with @JsonProperty (ones with no hyphens) and maybe also add @JsonAlias for "bad" names to be understood on input. This would allow sort of conversion.
PropertyNamingStrategy may also be used for some automated transformations: it can be applied on POJOs with @JsonNaming, or configured on ObjectMapper. Not sure if that could help.
I am using my Jackson-dataformat-avro jar to parse POJO (which are going to accept deserialized json & I don't control schema of those JSON) and subsequently use those POJO to map to a GenericRecord for Avro. The JSON schema has all bad naming conventions like hyphen and underscore. When I try to set up the AvroSchemaWrapper in this way :
I get exception while initialization of my Java Job saying :
Caused by: org.apache.avro.SchemaParseException: Illegal character in: User-Agent
at org.apache.avro.Schema.validateName(Schema.java:1561)
at org.apache.avro.Schema.access$400(Schema.java:87)
at org.apache.avro.Schema$Field.(Schema.java:541)
at org.apache.avro.Schema$Field.(Schema.java:580)
at com.fasterxml.jackson.dataformat.avro.schema.RecordVisitor.schemaFieldForWriter(RecordVisitor.java:189)
at com.fasterxml.jackson.dataformat.avro.schema.RecordVisitor.optionalProperty(RecordVisitor.java:117)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.depositSchemaProperty(BeanPropertyWriter.java:839)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.acceptJsonFormatVisitor(BeanSerializerBase.java:912)
at com.fasterxml.jackson.dataformat.avro.schema.RecordVisitor.schemaFieldForWriter(RecordVisitor.java:174)
at com.fasterxml.jackson.dataformat.avro.schema.RecordVisitor.optionalProperty(RecordVisitor.java:117)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.depositSchemaProperty(BeanPropertyWriter.java:839)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.acceptJsonFormatVisitor(BeanSerializerBase.java:912)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.acceptJsonFormatVisitor(DefaultSerializerProvider.java:566)
at com.fasterxml.jackson.databind.ObjectMapper.acceptJsonFormatVisitor(ObjectMapper.java:4438)
at com.fasterxml.jackson.databind.ObjectMapper.acceptJsonFormatVisitor(ObjectMapper.java:4417)
at ai.lily.sample.pipeline.SimpleMapper.generateAvroSchemaFromJacksonPOJO(SimpleMapper.java:99)
at ai.lily.sample.pipeline.SimpleMapper.(SimpleMapper.java:29)
Am I doing something wrong , can i (While extracting Avro Schema ) allow parser to not use @JsonProperty to define Avro schema field names ??
The text was updated successfully, but these errors were encountered: