ART_09
July 24, 2024, 5:30am
1
{
"type": "record",
"name": "AvroSchema",
"namespace": "com.programs.avro.v1",
"fields": [
{
"name": "projPrograms",
"type": {
"type": "array",
"items": {
"type": "record",
"name": "AvroProgramDto",
"namespace": "com.programs.avro.v1",
"fields": [
{
"name": "enrollmentId",
"type": "string"
},
{
"name": "externalStatus",
"type": [
"null",
"string"
]
},
{
"name": "reasonCode",
"type": [
"null",
"string"
]
},
{
"name": "memo",
"type": [
"null",
"string"
]
}
]
}
}
}
]
}
For nullable fields when I give a value and publish this message, I’m seeing those nullable fields as
“externalStatus”:{“string”:“A”},“reasonCode”:{“string”:“43”},“memo”:{“string”:“Enrolled”}. But it shouldn’t have the datatype “string” included in value. How can I resolve this
Hi @ART_09 ,
Can give more information.
Message that you are publishing ?
Are you using avro libraries for serialisation before publishing the message ?
Sample code where you are serialising your message, creating PubsubMessage and publishing the message ?
ART_09
July 24, 2024, 5:58pm
3
this is my dto
class ProjPrograms {
@JsonProperty (“enrollmentId”)
private String enrollmentId;
@JsonProperty (“externalStatus”)
private String externalStatus;
@JsonProperty (“reasonCode”)
private String reasonCode;
@JsonProperty (“memo”)
private String memo;
}
below is my pubsub publisher code
private AvroMessagePublisher avroMessagePublisher;
AvroProjProgramsSchema avroMessage = convertToAvro(projProgramsDto)
AvroMessageContext avroMessageContext = AvroMessageContext.builder()
.setAvroMessage(avroMessage)
.build();
avroMessagePublisher.publishAvroMessage(avroMessageContext); //publishAvroMessage is a pre-defined method in AvroMessagePublisher. Dependency is springBoot Publisher
privateAvroProjProgramsSchema convertToAvro(ProjProgramsDto) {
AvroProjProgramsSchema avroProjProgramsSchema = new AvroProjProgramsSchema();
//here I'm explict conversion of projProgramsDto to avroProjProgramsSchema
return avroProjProgramsSchema;
}