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

    https://github.com/apache/nifi/pull/1788#discussion_r116511189
  
    --- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-content-viewer/src/main/java/org/apache/nifi/web/StandardContentViewerController.java
 ---
    @@ -103,11 +108,27 @@ protected void doGet(HttpServletRequest request, 
HttpServletResponse response) t
                     } else if ("application/avro-binary".equals(contentType) 
|| "avro/binary".equals(contentType) || 
"application/avro+binary".equals(contentType)) {
                         final StringBuilder sb = new StringBuilder();
                         sb.append("[");
    -                    final DatumReader<GenericData.Record> datumReader = 
new GenericDatumReader<>();
    +                    // Use Avro conversions to display logical type values 
in human readable way.
    +                    final GenericData genericData = new GenericData(){
    +                        @Override
    +                        protected void toString(Object datum, 
StringBuilder buffer) {
    +                            // Since these types are not quoted and 
produce a malformed JSON string, quote it here.
    +                            if (datum instanceof LocalDate || datum 
instanceof LocalTime || datum instanceof DateTime) {
    +                                
buffer.append("\"").append(datum).append("\"");
    +                                return;
    +                            }
    +                            super.toString(datum, buffer);
    +                        }
    +                    };
    +                    genericData.addLogicalTypeConversion(new 
Conversions.DecimalConversion());
    +                    genericData.addLogicalTypeConversion(new 
TimeConversions.DateConversion());
    +                    genericData.addLogicalTypeConversion(new 
TimeConversions.TimeConversion());
    +                    genericData.addLogicalTypeConversion(new 
TimeConversions.TimestampConversion());
    +                    final DatumReader<GenericData.Record> datumReader = 
new GenericDatumReader<>(null, null, genericData);
                         try (final DataFileStream<GenericData.Record> 
dataFileReader = new DataFileStream<>(content.getContentStream(), datumReader)) 
{
                             while (dataFileReader.hasNext()) {
                                 final GenericData.Record record = 
dataFileReader.next();
    -                            final String formattedRecord = 
record.toString();
    +                            final String formattedRecord = 
genericData.toString(record);
    --- End diff --
    
    So as not to forget/ignore the conversation, do you mind taking a look at 
the comments in #1179 ?  As your anonymous GenericData class demonstrates, the 
toString() method is less than ideal for rendering Avro as JSON. I have a link 
in the other PR for an implementation of StandardJsonEncoder that mimics the 
GenericData.toString()
     output 
(https://github.com/mattyb149/nifi/commit/879efb7572888cf4bd863e1938a3a798bd87ff0c),
 feel free to use that and add your date/time rendering as needed. If not, 
that's fine too, just let me know and I'll continue the review, thanks!



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to