ferenc-csaky commented on code in PR #17:
URL: 
https://github.com/apache/flink-connector-http/pull/17#discussion_r2781303283


##########
flink-connector-http/src/main/java/org/apache/flink/connector/http/table/lookup/querycreators/GenericJsonAndUrlQueryCreatorFactory.java:
##########
@@ -92,6 +92,18 @@ public class GenericJsonAndUrlQueryCreatorFactory implements 
LookupQueryCreatorF
                                     + "The expected format of the map is:"
                                     + "<br>"
                                     + " key1:value1,key2:value2");
+    public static final ConfigOption<String> ADDITIONAL_REQUEST_JSON =

Review Comment:
   nit: I'd name this constant `REQUEST_ADDITONAL_BODY_JSON` to match the 
already existing naming pattern.



##########
flink-connector-http/src/main/java/org/apache/flink/connector/http/table/lookup/querycreators/GenericJsonAndUrlQueryCreator.java:
##########
@@ -145,9 +149,36 @@ public LookupQueryInfo createLookupQuery(final RowData 
lookupDataRow) {
             // Body-based queries
             // serialize to a string for the body.
             try {
-                lookupQuery =
-                        ObjectMapperAdapter.instance()
-                                
.writeValueAsString(jsonObject.retain(requestBodyFields));
+                ObjectNode bodyJsonObject = 
jsonObject.retain(requestBodyFields);
+
+                // Merge additional JSON if provided
+                if (additionalRequestJson != null && 
!additionalRequestJson.trim().isEmpty()) {
+                    try {
+                        JsonNode additionalNode =
+                                
ObjectMapperAdapter.instance().readTree(additionalRequestJson);
+                        if (additionalNode.isObject()) {
+                            ObjectNode additionalObjectNode = (ObjectNode) 
additionalNode;
+                            // Merge all fields from additional JSON into the 
body
+                            // This preserves nested objects and arrays as-is
+                            additionalObjectNode
+                                    .fields()
+                                    .forEachRemaining(
+                                            entry ->
+                                                    bodyJsonObject.set(
+                                                            entry.getKey(), 
entry.getValue()));

Review Comment:
   I am wondering what would be the desired behavior here? If i have a key in 
`additionalObjectNode` that `bodyJsonObject` also has, the current logic will 
overwrite the original value. Do we wanna do that? By default I as a user may 
not want that. Maybe I want to add some default values to my data, but I 
definitely do not want to overwrite the field if it exists already.
   
   I am thinking that we may also make this configurable and introduce a flag 
to control this behavior. So to make them as a group we could have something 
like:
   - `http.request.additional-body-json.content`
   - `http.request.additional-body-json.overwrite-original`
   
   WDYT?



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