Lehel44 commented on code in PR #6018:
URL: https://github.com/apache/nifi/pull/6018#discussion_r883696217


##########
nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/json/JsonTreeRowRecordReader.java:
##########
@@ -44,30 +44,51 @@
 import java.util.function.Supplier;
 
 public class JsonTreeRowRecordReader extends AbstractJsonRowRecordReader {
-    private final RecordSchema schema;
 
+    private final RecordSchema schema;
 
     public JsonTreeRowRecordReader(final InputStream in, final ComponentLog 
logger, final RecordSchema schema,
-        final String dateFormat, final String timeFormat, final String 
timestampFormat) throws IOException, MalformedRecordException {
-        super(in, logger, dateFormat, timeFormat, timestampFormat);
-        this.schema = schema;
+                                   final String dateFormat, final String 
timeFormat, final String timestampFormat) throws IOException, 
MalformedRecordException {
+        this(in, logger, schema, dateFormat, timeFormat, timestampFormat, 
null, null, null);
     }
 
     public JsonTreeRowRecordReader(final InputStream in, final ComponentLog 
logger, final RecordSchema schema,
                                    final String dateFormat, final String 
timeFormat, final String timestampFormat,
-                                   final StartingFieldStrategy strategy, final 
String startingFieldName) throws IOException, MalformedRecordException {
-        super(in, logger, dateFormat, timeFormat, timestampFormat, strategy, 
startingFieldName);
-        this.schema = schema;
+                                   final StartingFieldStrategy 
startingFieldStrategy, final String startingFieldName,
+                                   final SchemaApplicationStrategy 
schemaApplicationStrategy)
+            throws IOException, MalformedRecordException {
+
+        super(in, logger, dateFormat, timeFormat, timestampFormat, 
startingFieldStrategy, startingFieldName);
+        if (startingFieldStrategy == StartingFieldStrategy.NESTED_FIELD && 
schemaApplicationStrategy == SchemaApplicationStrategy.WHOLE_JSON) {
+            this.schema = getSelectedSchema(schema, startingFieldName);
+        } else {
+            this.schema = schema;
+        }
+    }
+
+    private RecordSchema getSelectedSchema(final RecordSchema schema, final 
String startingFieldName) {

Review Comment:
   Indeed, I will change it to work with deeper nested fields as well. Thanks 
for the test case too!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to