Kafka AvroSchema not generated ,when a Class which has field with datatype as Object class

Viewed 221

Kafka AvroSchema not generated ,when a Class which has field with datatype as Object class . Any ? Schema . What can we the reason that jackson databind not able to generate avro schema.


        ObjectMapper mapperss = new ObjectMapper(new AvroFactory());
        AvroSchemaGenerator gen = new AvroSchemaGenerator();
        try {
            mapperss.acceptJsonFormatVisitor(Sample.class, gen);
        } catch (JsonMappingException jme){
            jme.printStackTrace();
        }
        AvroSchema schemaWrapper = gen.getGeneratedSchema();
        org.apache.avro.Schema avroSchema = schemaWrapper.getAvroSchema();
        String asJson = avroSchema.toString(true);
        System.out.println("Schema Generated " + asJson);
import java.io.Serializable;
import javax.validation.Valid;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;

@JsonInclude(Include.NON_EMPTY)
@JsonIgnoreProperties(
    ignoreUnknown = true
)
public class Sample implements Serializable {
    @JsonProperty("additionalFields")
    @Valid
    private Object additionalFields = null;
  public Sample() {
    }

    public Sample additionalFields(Object additionalFields) {
        this.additionalFields = additionalFields;
        return this;
    }

    public Object getAdditionalFields() {
        return this.additionalFields;
    }

    public void setAdditionalFields(Object additionalFields) {
        this.additionalFields = additionalFields;
    }
}
2 Answers

I created new POJO which do not have Object Class as DataType in fields (attribute) at Class or Subclass level.

What can be the reason that jackson databind not able to generate avro schema

Related