diff --git a/docs/en/connector-v2/source/Http.md b/docs/en/connector-v2/source/Http.md
index 8b922edc230..992542b50c8 100644
--- a/docs/en/connector-v2/source/Http.md
+++ b/docs/en/connector-v2/source/Http.md
@@ -44,37 +44,38 @@ They can be downloaded via install-plugin.sh or from the Maven central repositor
## Source Options
-| Name | Type | Required | Default | Description |
-|-------------------------------|---------|----------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| url | String | Yes | - | Http request url. |
-| schema | Config | No | - | Http and seatunnel data structure mapping |
-| schema.fields | Config | No | - | The schema fields of upstream data |
-| json_field | Config | No | - | This parameter helps you configure the schema,so this parameter must be used with schema. |
-| pageing | Config | No | - | This parameter is used for paging queries |
-| pageing.page_field | String | No | - | This parameter is used to specify the page field name in the request. It can be used in headers, params, or body with placeholders like ${page_field}. |
-| pageing.use_placeholder_replacement | Boolean | No | false | If true, use placeholder replacement (${field}) for headers, parameters and body values, otherwise use key-based replacement. |
-| pageing.total_page_size | Int | No | - | This parameter is used to control the total number of pages |
-| pageing.batch_size | Int | No | - | The batch size returned per request is used to determine whether to continue when the total number of pages is unknown |
-| pageing.start_page_number | Int | No | 1 | Specify the page number from which synchronization starts |
+| Name | Type | Required | Default | Description |
+|-------------------------------|---------|----------|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| url | String | Yes | - | Http request url. |
+| schema | Config | No | - | Http and seatunnel data structure mapping |
+| schema.fields | Config | No | - | The schema fields of upstream data |
+| json_field | Config | No | - | This parameter helps you configure the schema,so this parameter must be used with schema. |
+| pageing | Config | No | - | This parameter is used for paging queries |
+| pageing.page_field | String | No | - | This parameter is used to specify the page field name in the request. It can be used in headers, params, or body with placeholders like ${page_field}. |
+| pageing.use_placeholder_replacement | Boolean | No | false | If true, use placeholder replacement (${field}) for headers, parameters and body values, otherwise use key-based replacement. |
+| pageing.total_page_size | Int | No | - | This parameter is used to control the total number of pages |
+| pageing.batch_size | Int | No | - | The batch size returned per request is used to determine whether to continue when the total number of pages is unknown |
+| pageing.start_page_number | Int | No | 1 | Specify the page number from which synchronization starts |
| pageing.page_type | String | No | PageNumber | this parameter is used to specify the page type ,or PageNumber if not set, only support `PageNumber` and `Cursor`. |
| pageing.cursor_field | String | No | - | this parameter is used to specify the Cursor field name in the request parameter. |
-| pageing.cursor_response_field | String | No | - | This parameter specifies the field in the response from which the cursor is retrieved. |
-| content_json | String | No | - | This parameter can get some json data.If you only need the data in the 'book' section, configure `content_field = "$.store.book.*"`. |
-| format | String | No | text | The format of upstream data, now only support `json` `text`, default `text`. |
-| method | String | No | get | Http request method, only supports GET, POST method. |
-| headers | Map | No | - | Http headers. |
-| params | Map | No | - | Http params. |
-| body | String | No | - | Http body,the program will automatically add http header application/json,body is jsonbody. |
-| poll_interval_millis | Int | No | - | Request http api interval(millis) in stream mode. |
-| retry | Int | No | - | The max retry times if request http return to `IOException`. |
-| retry_backoff_multiplier_ms | Int | No | 100 | The retry-backoff times(millis) multiplier if request http failed. |
-| retry_backoff_max_ms | Int | No | 10000 | The maximum retry-backoff times(millis) if request http failed |
-| enable_multi_lines | Boolean | No | false | |
-| connect_timeout_ms | Int | No | 12000 | Connection timeout setting, default 12s. |
-| socket_timeout_ms | Int | No | 60000 | Socket timeout setting, default 60s. |
-| common-options | | No | - | Source plugin common parameters, please refer to [Source Common Options](../source-common-options.md) for details |
+| pageing.cursor_response_field | String | No | - | This parameter specifies the field in the response from which the cursor is retrieved. |
+| content_json | String | No | - | This parameter can get some json data.If you only need the data in the 'book' section, configure `content_field = "$.store.book.*"`. |
+| format | String | No | text | The format of upstream data, now only support `json` `text`, default `text`. |
+| method | String | No | get | Http request method, only supports GET, POST method. |
+| headers | Map | No | - | Http headers. |
+| params | Map | No | - | Http params. |
+| body | String | No | - | Http body,the program will automatically add http header application/json,body is jsonbody. |
+| poll_interval_millis | Int | No | - | Request http api interval(millis) in stream mode. |
+| retry | Int | No | - | The max retry times if request http return to `IOException`. |
+| retry_backoff_multiplier_ms | Int | No | 100 | The retry-backoff times(millis) multiplier if request http failed. |
+| retry_backoff_max_ms | Int | No | 10000 | The maximum retry-backoff times(millis) if request http failed |
+| enable_multi_lines | Boolean | No | false | |
+| connect_timeout_ms | Int | No | 12000 | Connection timeout setting, default 12s. |
+| socket_timeout_ms | Int | No | 60000 | Socket timeout setting, default 60s. |
+| common-options | | No | - | Source plugin common parameters, please refer to [Source Common Options](../source-common-options.md) for details |
| keep_params_as_form | Boolean | No | false | Whether the params are submitted according to the form, used for compatibility with legacy behaviors. When true, the value of the params parameter is submitted through the form. |
-| keep_page_param_as_http_param | Boolean | No | false | Whether to set the paging parameters to params. For compatibility with legacy behaviors. |
+| keep_page_param_as_http_param | Boolean | No | false | Whether to set the paging parameters to params. For compatibility with legacy behaviors.|
+| json_filed_missed_return_null | Boolean | No | false | When the json field is missing, set true return null else error.|
## How to Create a Http Data Synchronization Jobs
@@ -216,7 +217,7 @@ By default, the parameters will be added to the url path.
If you need to keep the old version behavior, please check keep_params_as_form.
### body
-The HTTP body is used to carry the actual data in requests or responses, including JSON, form submissions.
+The HTTP body is used to carry the actual data in requests or responses, including JSON, form submissions.
The reference format is as follows:
```hocon
diff --git a/seatunnel-connectors-v2/connector-http/connector-http-base/pom.xml b/seatunnel-connectors-v2/connector-http/connector-http-base/pom.xml
index f18d6f9fef1..e19e9ab9848 100644
--- a/seatunnel-connectors-v2/connector-http/connector-http-base/pom.xml
+++ b/seatunnel-connectors-v2/connector-http/connector-http-base/pom.xml
@@ -33,6 +33,7 @@
4.5.13
4.4.4
2.0.0
+ 3.12.4
@@ -69,5 +70,29 @@
json-path
${json-path.version}
+
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ test
+
+
+ org.mockito
+ mockito-core
+ ${mockito.version}
+ test
+
+
+ org.mockito
+ mockito-junit-jupiter
+ ${mockito.version}
+ test
+
diff --git a/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/config/HttpParameter.java b/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/config/HttpParameter.java
index 272f2023298..94493a6c600 100644
--- a/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/config/HttpParameter.java
+++ b/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/config/HttpParameter.java
@@ -45,6 +45,7 @@ public class HttpParameter implements Serializable {
protected boolean arrayMode = false;
protected int batchSize = 1;
protected int requestIntervalMs = 0;
+ protected boolean jsonFiledMissedReturnNull;
public void buildWithConfig(ReadonlyConfig pluginConfig) {
// set url
@@ -83,5 +84,7 @@ public void buildWithConfig(ReadonlyConfig pluginConfig) {
this.setEnableMultilines(pluginConfig.get(HttpSourceOptions.ENABLE_MULTI_LINES));
this.setConnectTimeoutMs(pluginConfig.get(HttpSourceOptions.CONNECT_TIMEOUT_MS));
this.setSocketTimeoutMs(pluginConfig.get(HttpSourceOptions.SOCKET_TIMEOUT_MS));
+ this.setJsonFiledMissedReturnNull(
+ pluginConfig.get(HttpSourceOptions.JSON_FILED_MISSED_RETURN_NULL));
}
}
diff --git a/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/config/HttpSourceOptions.java b/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/config/HttpSourceOptions.java
index cc179ea027f..5014a01c4a2 100644
--- a/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/config/HttpSourceOptions.java
+++ b/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/config/HttpSourceOptions.java
@@ -147,4 +147,10 @@ public class HttpSourceOptions extends HttpCommonOptions {
.intType()
.defaultValue(DEFAULT_SOCKET_TIMEOUT_MS)
.withDescription("Socket timeout setting, default 60s.");
+
+ public static final Option JSON_FILED_MISSED_RETURN_NULL =
+ Options.key("json_filed_missed_return_null")
+ .booleanType()
+ .defaultValue(false)
+ .withDescription("When the json field is missing, return null");
}
diff --git a/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/source/HttpSourceReader.java b/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/source/HttpSourceReader.java
index b82fe3fe0c3..fdb2b50adc5 100644
--- a/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/source/HttpSourceReader.java
+++ b/seatunnel-connectors-v2/connector-http/connector-http-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/http/source/HttpSourceReader.java
@@ -36,6 +36,9 @@
import org.apache.seatunnel.connectors.seatunnel.http.config.PageInfo;
import org.apache.seatunnel.connectors.seatunnel.http.exception.HttpConnectorErrorCode;
import org.apache.seatunnel.connectors.seatunnel.http.exception.HttpConnectorException;
+import org.apache.seatunnel.connectors.seatunnel.http.util.JsonPathProcessor;
+import org.apache.seatunnel.connectors.seatunnel.http.util.JsonPathProcessorFactory;
+import org.apache.seatunnel.connectors.seatunnel.http.util.JsonPathUtils;
import org.apache.commons.collections4.MapUtils;
@@ -418,47 +421,24 @@ private void collect(Collector output, String data) throws IOExcep
deserializationCollector.collect(contentData.getBytes(), output);
}
- private List