[ 
https://issues.apache.org/jira/browse/NIFI-969?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15645580#comment-15645580
 ] 

ASF GitHub Bot commented on NIFI-969:
-------------------------------------

Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1179#discussion_r86877725
  
    --- Diff: 
nifi-nar-bundles/nifi-avro-bundle/nifi-avro-processors/src/test/java/org/apache/nifi/processors/avro/TestConvertAvroToJSON.java
 ---
    @@ -239,6 +239,37 @@ public void 
testSingleSchemalessAvroMessage_wrapSingleMessage_noContainer() thro
         }
     
         @Test
    +    public void 
testSingleSchemalessAvroMessage_wrapSingleMessage_noContainer_StandardJson() 
throws IOException {
    +        final TestRunner runner = TestRunners.newTestRunner(new 
ConvertAvroToJSON());
    +        runner.setProperty(ConvertAvroToJSON.CONTAINER_OPTIONS, 
ConvertAvroToJSON.CONTAINER_NONE);
    +        runner.setProperty(ConvertAvroToJSON.WRAP_SINGLE_RECORD, 
Boolean.toString(true));
    +        Schema schema = new Schema.Parser().parse(new 
File("src/test/resources/user.avsc"));
    +        String stringSchema = schema.toString();
    +        runner.setProperty(ConvertAvroToJSON.SCHEMA, stringSchema);
    +        runner.setProperty(ConvertAvroToJSON.USE_STANDARD_JSON, "true");
    +
    +        final GenericRecord user1 = new GenericData.Record(schema);
    +        user1.put("name", "Alyssa");
    +        user1.put("favorite_number", 256);
    +
    +        final ByteArrayOutputStream out1 = new ByteArrayOutputStream();
    +        final BinaryEncoder encoder = 
EncoderFactory.get().binaryEncoder(out1, null);
    +        final DatumWriter<GenericRecord> datumWriter = new 
GenericDatumWriter<>(schema);
    +        datumWriter.write(user1, encoder);
    +
    +        encoder.flush();
    +        out1.flush();
    +        byte[] test = out1.toByteArray();
    +        runner.enqueue(test);
    +
    +        runner.run();
    +
    +        
runner.assertAllFlowFilesTransferred(ConvertAvroToJSON.REL_SUCCESS, 1);
    +        final MockFlowFile out = 
runner.getFlowFilesForRelationship(ConvertAvroToJSON.REL_SUCCESS).get(0);
    +        
out.assertContentEquals("{\"name\":\"Alyssa\",\"favorite_number\":{\"int\":256},\"favorite_color\":null}");
    --- End diff --
    
    With standard JSON, shouldn't favorite_number be 256, not {"int":256} ?


> Add option to use standard JSON or Avro-JSON to ConvertAvroToJSON
> -----------------------------------------------------------------
>
>                 Key: NIFI-969
>                 URL: https://issues.apache.org/jira/browse/NIFI-969
>             Project: Apache NiFi
>          Issue Type: Improvement
>          Components: Extensions
>    Affects Versions: 0.3.0
>            Reporter: Ryan Blue
>            Assignee: Oleg Zhurakousky
>
> ConvertAvroToJSON uses {{GenericData#toString(GenericRecord)}} to convert to 
> JSON. This produces 
> [Avro-JSON|https://avro.apache.org/docs/1.7.7/spec.html#json_encoding], which 
> probably isn't what most users want because it adds an unexpected layer for 
> Avro union types:
> bq. the union schema {{["null","string",...]}} ... would encode: the string 
> {{"a"}} as {{{"string": "a"}}} ...
> It would be good to have a conversion that doesn't add those layers as an 
> option.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to