Support Questions
Find answers, ask questions, and share your expertise

Input values are converted to String after going through Record Reader / Record Writer

Input values are converted to String after going through Record Reader / Record Writer

New Contributor

Hello community,

We are experiencing an invalid scenario in our implementation.

After receiving an input JSON with integer values from ListenHTTP processor, the values are sent to a Kafka processor which uses JsonTreeReader 1.4.0 as record reader and JsonRecordSetWriter 1.4.0 as record writer.

After this processing, integer values from JSON are converted to String.

Is this the correct behavior?

Is there a way to keep the original format?

input:

{

"sample": 123

}

output:

{

"sample": "123"

}

Thanks,

Tiago

3 REPLIES 3
Highlighted

Re: Input values are converted to String after going through Record Reader / Record Writer

Super Guru

Can you share your input/output schemas? My guess is that in the schema, the data type is specified as "string" rather than "int".

Highlighted

Re: Input values are converted to String after going through Record Reader / Record Writer

New Contributor

Sure, schema is something similar to:

"fields": [ { "name": "sample", "type": "string"}]

I understand now that the type of field will define the output type of our writer.

A new question came out, is it possible to have the record invalidated since the sample came as 123 int instead of "123" string?

We would like to avoid the type coercion provided by JsonTreeReader:

https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-record-serialization-services...

Highlighted

Re: Input values are converted to String after going through Record Reader / Record Writer

Super Guru

You should be able to use ValidateRecord using the original schema, if types are coerced by a reader/writer (which I think might be a bug if they do), then they should fail validation (assuming the same bug/behavior is not in both places).