Hisoka-X commented on code in PR #9103: URL: https://github.com/apache/seatunnel/pull/9103#discussion_r2107261486
########## seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/util/BracketJsonPathProcessor.java: ########## @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.seatunnel.connectors.seatunnel.http.util; + +import com.jayway.jsonpath.JsonPath; +import com.jayway.jsonpath.ReadContext; + +import java.util.ArrayList; +import java.util.List; + +/** Processor for handling JsonPath with bracket notation (e.g., $['result']['value']). */ +public class BracketJsonPathProcessor extends AbstractJsonPathProcessor { + /** {@inheritDoc} */ + @Override + public List<List<String>> processJsonData(ReadContext jsonReadContext, JsonPath[] paths) { Review Comment: Recheck the logic of `BracketJsonPathProcessor` and `ObjectJsonPathProcessor`. They are totally same. ########## seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/source/HttpSourceReader.java: ########## @@ -418,47 +421,24 @@ private void collect(Collector<SeaTunnelRow> output, String data) throws IOExcep deserializationCollector.collect(contentData.getBytes(), output); } - private List<Map<String, String>> parseToMap(List<List<String>> datas, JsonField jsonField) { - List<Map<String, String>> decodeDatas = new ArrayList<>(datas.size()); - String[] keys = jsonField.getFields().keySet().toArray(new String[] {}); - - for (List<String> data : datas) { - Map<String, String> decodeData = new HashMap<>(jsonField.getFields().size()); - final int[] index = {0}; - data.forEach( - field -> { - decodeData.put(keys[index[0]], field); - index[0]++; - }); - decodeDatas.add(decodeData); - } - - return decodeDatas; - } - private List<List<String>> decodeJSON(String data) { ReadContext jsonReadContext = JsonPath.using(jsonConfiguration).parse(data); - List<List<String>> results = new ArrayList<>(jsonPaths.length); - for (JsonPath path : jsonPaths) { - List<String> result = jsonReadContext.read(path); - results.add(result); - } - for (int i = 1; i < results.size(); i++) { - List<?> result0 = results.get(0); - List<?> result = results.get(i); - if (result0.size() != result.size()) { - throw new HttpConnectorException( - HttpConnectorErrorCode.FIELD_DATA_IS_INCONSISTENT, - String.format( - "[%s](%d) and [%s](%d) the number of parsing records is inconsistent.", - jsonPaths[0].getPath(), - result0.size(), - jsonPaths[i].getPath(), - result.size())); - } + boolean jsonFiledMissedReturnNull = httpParameter.isJsonFiledMissedReturnNull(); + if (jsonFiledMissedReturnNull) { + // Get the appropriate processor for the JsonPaths, passing the + // jsonFiledMissedReturnNull flag + JsonPathProcessor processor = + JsonPathProcessorFactory.getProcessor(this.jsonPaths, true); + return processor.processJsonData(jsonReadContext, this.jsonPaths); + } else { + // Standard processing for strict fields + return JsonPathProcessorFactory.getProcessor(this.jsonPaths) + .processJsonData(jsonReadContext, this.jsonPaths); } Review Comment: ```suggestion return JsonPathProcessorFactory.getProcessor(this.jsonPaths, httpParameter.isJsonFiledMissedReturnNull()) .processJsonData(jsonReadContext, this.jsonPaths); ``` -- 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]
