Java 将对象转换为JSON字符串时发生JsonMappingException-org.apache.avro.AvroRuntimeException:非数组:

Java 将对象转换为JSON字符串时发生JsonMappingException-org.apache.avro.AvroRuntimeException:非数组:,java,json,jackson,json-deserialization,objectmapper,Java,Json,Jackson,Json Deserialization,Objectmapper,在将Java对象转换为JSON字符串时,我遇到了JsonMappingException。下面是完整的异常消息 com.fasterxml.jackson.databind.JsonMappingException: Not an array: {"type":"record","name":"ClearingSystemMemberIdentification2","namespace":&qu

在将Java对象转换为JSON字符串时,我遇到了JsonMappingException。下面是完整的异常消息

com.fasterxml.jackson.databind.JsonMappingException: Not an array: {"type":"record","name":"ClearingSystemMemberIdentification2","namespace":"com.sam.eps.paymentdomain.avro.pacs002","doc":"Schema for com.sam.eps.iso.pacs002.ClearingSystemMemberIdentification2","fields":[{"name":"clearing_system_identification","type":["null",{"type":"record","name":"ClearingSystemIdentification2Choice","doc":"Schema for com.sam.eps.iso.pacs002.ClearingSystemIdentification2Choice","fields":[{"name":"code","type":["null",{"type":"string","avro.java.string":"String"}],"default":null},{"name":"proprietary","type":["null",{"type":"string","avro.java.string":"String"}],"default":null}]}],"default":null},{"name":"member_identification","type":["null",{"type":"string","avro.java.string":"String"}],"default":null}]} (through reference chain: com.sam.eps.paymentdomain.avro.pacs002.Document["fi_to_fi_payment_status_report"]->com.sam.eps.paymentdomain.avro.pacs002.FIToFIPaymentStatusReportV10["group_header"]->com.sam.eps.paymentdomain.avro.pacs002.GroupHeader91["instructed_agent"]->com.sam.eps.paymentdomain.avro.pacs002.BranchAndFinancialInstitutionIdentification6["financial_institution_identification"]->com.sam.eps.paymentdomain.avro.pacs002.FinancialInstitutionIdentification18["clearing_system_member_identification"]->com.sam.eps.paymentdomain.avro.pacs002.ClearingSystemMemberIdentification2["schema"]->org.apache.avro.Schema$RecordSchema["elementType"])
下面是我用于将java对象转换为JSON字符串的java代码。我尝试过启用ACCEPT_SINGLE_VALUE_AS_ARRAY,ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT,但仍然面临这个问题。不确定是什么导致了JsonMappingException:不是数组问题

private String convertObjectToJson(Object request) throws JsonProcessingException {

        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.registerModule(new JavaTimeModule());
        SimpleModule simpleModule = new SimpleModule();
        simpleModule.addSerializer(OffsetDateTime.class, new JsonSerializer<OffsetDateTime>() {
            @Override
            public void serialize(OffsetDateTime offsetDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
                jsonGenerator.writeString(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(offsetDateTime));
            }
        });
        simpleModule.addSerializer(LocalDate.class, new JsonSerializer<LocalDate>() {
            @Override
            public void serialize(LocalDate localDate, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
                jsonGenerator.writeString(DateTimeFormatter.ISO_LOCAL_DATE.format(localDate));
            }
        });
        objectMapper.registerModule(simpleModule);
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
        objectMapper.enable(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT);
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        return objectMapper.writeValueAsString(request);
    }
私有字符串convertObjectToJson(对象请求)抛出JsonProcessingException{
ObjectMapper ObjectMapper=新的ObjectMapper();
registerModule(新的JavaTimeModule());
SimpleModule SimpleModule=新的SimpleModule();
simpleModule.addSerializer(OffsetDateTime.class,新的JsonSerializer()){
@凌驾
public void serialize(OffsetDateTime OffsetDateTime、JsonGenerator JsonGenerator、SerializerProvider SerializerProvider)引发IOException{
writeString(DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(offsetDateTime));
}
});
simpleModule.addSerializer(LocalDate.class,新的JsonSerializer()){
@凌驾
public void serialize(LocalDate LocalDate、JsonGenerator JsonGenerator、SerializerProvider SerializerProvider)引发IOException{
writeString(DateTimeFormatter.ISO_LOCAL_DATE.format(localDate));
}
});
registerModule(simpleModule);
objectMapper.configure(在未知属性上反序列化feature.FAIL,false);
enable(反序列化功能。接受单个值作为数组);
enable(反序列化功能。接受\u空\u数组\u作为\u空\u对象);
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
返回objectMapper.writeValueAsString(请求);
}

这里有谁遇到过这个问题?org.apache.avro.AvroRuntimeException:不是数组:如果尚未解决它: