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

Daniel Stieglitz edited comment on NIFI-11959 at 9/11/23 6:35 PM:
------------------------------------------------------------------

[~mattyb149] I was able to trace this bug to code you had added for NIFI-4957 

lines 488-495 in JoltTransformRecord and lines 396-402 in JoltTransformJSON
{code:java}
private String readTransform(final PropertyValue propertyValue) {
        final ResourceReference resourceReference = propertyValue.asResource();
        try (final BufferedReader reader = new BufferedReader(new 
InputStreamReader(resourceReference.read()))) {
            return reader.lines().collect(Collectors.joining());
        } catch (final IOException e) {
            throw new UncheckedIOException("Read JOLT Transform failed", e);
        }
    }{code}
Per [this article|https://www.baeldung.com/convert-input-stream-to-string] 
'reader.lines()' uses readLine underneath the hood which thereby strips the new 
lines. For single line comments ('//') that seems to prevent the JSON from 
being parsed even if the parser is set to ignore comments.  Multiline comments 
('/**/') are unaffected. The fix for this would be to reinsert the new lines 
with 
{code:java}
return reader.lines().collect(Collectors.joining(System.lineSeparator()));{code}
I just wanted to double check with you first if there was any other reason not 
to have the new lines in the spec. Please advise. Thanks!


was (Author: JIRAUSER294662):
[~mattyb149] I was able to trace this bug to code you had added for NIFI-4957 

lines 488-495 in JoltTransformRecord and lines 396-402 in JoltTransformJSON
{code:java}
private String readTransform(final PropertyValue propertyValue) {
        final ResourceReference resourceReference = propertyValue.asResource();
        try (final BufferedReader reader = new BufferedReader(new 
InputStreamReader(resourceReference.read()))) {
            return reader.lines().collect(Collectors.joining());
        } catch (final IOException e) {
            throw new UncheckedIOException("Read JOLT Transform failed", e);
        }
    }{code}
Per [this article|https://www.baeldung.com/convert-input-stream-to-string] 
'reader.lines()' uses readLine underneath the hood which thereby strips the new 
lines. For single line comments ('//') that seems to prevent the JSON from 
being parsed even if the parser is set to ignore comments.  Multiline comments 
('/**/') are unaffected. The fix for this would to reinsert the new lines with 
{code:java}
return reader.lines().collect(Collectors.joining(System.lineSeparator()));{code}
I just wanted to double check with you first if there was any other reason not 
to have the new lines in the spec. Please advise. Thanks!

> Jolt spec in JoltTransformJson processor no longer supporting text comments
> ---------------------------------------------------------------------------
>
>                 Key: NIFI-11959
>                 URL: https://issues.apache.org/jira/browse/NIFI-11959
>             Project: Apache NiFi
>          Issue Type: Bug
>    Affects Versions: 1.23.0
>            Reporter: Mahieddine Cherif
>            Assignee: Daniel Stieglitz
>            Priority: Major
>         Attachments: Screenshot 2023-08-17 at 09.24.44-1.png, jolt-issue.json
>
>
> Since NiFi 1.23.0, it seems like comments are no longer supported in Jolt 
> Spec (JoltTransformJson/JoltTransformRecord processors)
> This however seems something that was already supported at least the most 
> wide spread jolt engine [https://jolt-demo.appspot.com/#inception] 
> *Reproducer :* 
> We can easily reproduce it by simply putting a jolt with a comment using 
> either JoltTransformRecord or JoltTransformJson processors as both are 
> impacted.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to