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

    https://github.com/apache/nifi/pull/1788#discussion_r117057133
  
    --- 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 --
    
    The comment in the other PR was that toString() is not guaranteed to be 
stable or output what you'd expect. The two approaches output different JSON 
for example (although my StandardJsonEncoder subclass emulates the current 
GenericData.toString()). However toString() has been fine in the past and for 
that other PR (which was closed without modification), so I'm ok with keeping 
toString() for now as well. If it ever "breaks", we'd have to change it in a 
few places anyway.


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