I have this payload and set this payload to avro classes
{
"tradeQuantity":13,
"tradeMarket":"sssss",
"stockName":"teststock",
"tradeType":"testtype",
"price":12.2,
"amount":12.5,
"address":{
"stret" : "aaa",
"city" : "bbb"
}
}
classes
StockHistory stockHistory= new StockHistory();
stockHistory.setStockName(model.getStockName());
stockHistory.setTradeType(model.getTradeType());
stockHistory.setPrice(model.getPrice());
stockHistory.setAmount(model.getAmount());
stockHistory.setTradeId(new Random(1000).nextInt());
stockHistory.setTradeMarket(model.getTradeMarket());
stockHistory.setTradeQuantity(model.getTradeQuantity());
Address address = new Address();
address.setCity("sss");
address.setStreetaddress("aaaa");
stockHistory.setAddress(address);
when converting to an object mapper like
ObjectMapper mapper = new ObjectMapper();
mapper.addMixIn(StockHistory.class, IgnoreSchemaProperty.class);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
Its works when only have stockHistory without address but for nested objects how we can handle its throwing an exception
org.apache.avro.AvroRuntimeException: Not an array: {"type":"record","name":"Address","namespace":"com.spring.cloud.streams.avro","fields":[{"name":"streetaddress","type":["null","string"],"default":null},{"name":"city","type":["null","string"],"default":null}]}
when using Google GSON converting object to JSON its working but I am not sure is that correct approach or not
Can anyone suggest how we can handle nested avro classes/object using objectMapper while converting to json