divolte-collector
divolte-collector copied to clipboard
checkValid on array types more strict then read path
The documentation specifies this:
If the Avro type specifies an array, any JSON value compatible with the type of the array elements will be wrapped as a single-element array.
Together with this avro schema definition
{ "name": "arrayOfStringField",
"type": [
"null",
{
"type": "array",
"items": "string"
}
],
"default": null
}
And this mapping
map eventParameters().value('fieldName') onto 'arrayOfStringField'
I get this error on divolte startup
SchemaMappingException: Cannot map the result of eventParameters().value(fieldName) onto field arrayOfStringField: type must be compatible with class java.lang.String
The record mapper is correctly configured to support this
static final AvroGenericRecordMapper AVRO_MAPPER =
new AvroGenericRecordMapper(
new ObjectMapper().reader()
.with(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,
DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)
.without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
So it’s the configuration validating being too… vigilant. AvroGenericRecordMapper:76 is where the problem lies.
Seems we need a specific checkArrayValid or something.
I'm having the same issue.. I have single level array of string that Im passing from a custom event and im trying to map to a field with type array of strings but its giving me the same error when i try to spin up my divolte container.. what is the solution?
@asnare did you find a work around or can you tell me how I should write the mapping for my array of strings field in mapping.groovy? Im using divolte v0.9 and the line for that field is "map eventParameter('countries') onto 'countries' " but that isnt working. Is there some parsing that needs to be done first?
I found this work around by using this format in mapping.groovy: map eventParameters().path('$.countries.*') onto 'ccountries'