Skip to content
This repository has been archived by the owner on Apr 22, 2022. It is now read-only.

checkValid on array types more strict then read path #201

Open
krisgeus opened this issue Apr 4, 2018 · 3 comments
Open

checkValid on array types more strict then read path #201

krisgeus opened this issue Apr 4, 2018 · 3 comments
Labels

Comments

@krisgeus
Copy link
Contributor

krisgeus commented Apr 4, 2018

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.

@asnare asnare added the bug label Apr 4, 2018
@tatianafrank
Copy link

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?

@tatianafrank
Copy link

@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?

@tatianafrank
Copy link

I found this work around by using this format in mapping.groovy: map eventParameters().path('$.countries.*') onto 'ccountries'

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants