I found the problem, it was nothing about what I explained before, my bad ^^!
In fact there exists a kind of bug in Avro ... to be concised, I filled the nested avro record created with a builder and set all the fields:
deviceInfoBuilder = MobtabAvroDeviceInfo.newBuilder();
deviceInfoBuilder.setModelName(mobtabJsonHit.getMobtabJsonDeviceInfo().getModuleName());
deviceInfoBuilder.setOperatingSystemName(mobtabJsonHit.getMobtabJsonDeviceInfo().getOperatingSystemName());
deviceInfoBuilder.setOperatingSystemVersion(mobtabJsonHit.getMobtabJsonDeviceInfo().getOperatingSystemVersion());
deviceInfoBuilder.setType(mobtabJsonHit.getMobtabJsonDeviceInfo().getDeviceType());
deviceInfoBuilder.setAdId(mobtabJsonHit.getMobtabJsonDeviceInfo().getDeviceAdId());
When the information wasn't available (i.e. the nested Jackson was not present), I created an "empty" nested Avro record and provided it to the builder as follows:
private final static MobtabAvroDeviceInfo emptyMobtabAvroDeviceInfo =
new MobtabAvroDeviceInfo(null, null, null, null, null);
deviceInfoBuilder = MobtabAvroDeviceInfo.newBuilder(emptyMobtabAvroDeviceInfo);
And then, I got the following exception:
java.lang.NullPointerException: null of string of fr.mediametrie.internet.pame.meter.avro.MobtabAvroDeviceInfo of fr.mediametrie.internet.pame.meter.avro.MobtabAvroHit
Although my Avro schema enables "null" values ...
{
"name": "device_info",
"type": {
"type": "record",
"name": "MobtabAvroDeviceInfo",
"fields": [
{
"name": "model_name",
"type": ["null", "string"],
"default": null
},
{
"name": "operating_system_name",
"type": ["null", "string"],
"default": null
},
{
"name": "operating_system_version",
"type": ["null", "string"],
"default": null
},
{
"name": "type",
"type": ["null", "string"],
"default": null
},
{
"name": "ad_id",
"type": ["null", "string"],
"default": null
}
]
}
}
To solve the problem, I've just created a new builder without specifying an "empty" nested Avro record in parameter:
deviceInfoBuilder = MobtabAvroDeviceInfo.newBuilder();
To conclude, it seems I cannot create an "empty" nested Avro using default values and provide the builder with but I must let the builder building that object using the default values specified in the schema. Strange, but it works now :)