gpt4 book ai didi

java - Kafka AvroSchema 未生成,当一个类具有数据类型为对象类的字段时

转载 作者:行者123 更新时间:2023-12-04 17:26:31 25 4
gpt4 key购买 nike

Kafka AvroSchema 未生成,当一个类具有数据类型 作为对象类 的字段时。任何 ? 架构 。 jackson 数据绑定(bind)无法生成 avro 模式的原因是什么。


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;
}
}

最佳答案

我创建了新的 POJO,它在类或子类级别的字段(属性)中没有对象类作为数据类型。

关于java - Kafka AvroSchema 未生成,当一个类具有数据类型为对象类的字段时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62942970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com