woonsan commented on a change in pull request #660:
URL: https://github.com/apache/jmeter/pull/660#discussion_r749852853



##########
File path: 
src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/GraphQLRequestParamUtils.java
##########
@@ -79,28 +80,24 @@ public static boolean isGraphQLContentType(final String 
contentType) {
      * @throws RuntimeException if JSON serialization fails for some reason 
due to any runtime environment issues
      */
     public static String toPostBodyString(final GraphQLRequestParams params) {
-        final ObjectMapper mapper = new ObjectMapper();
-        final ObjectNode postBodyJson = mapper.createObjectNode();
-        postBodyJson.set(OPERATION_NAME_FIELD,
-                
JsonNodeFactory.instance.textNode(StringUtils.trimToNull(params.getOperationName())));
+        final StringBuilder sb = new StringBuilder(1024);
+
+        sb.append("{");
+
+        appendJsonStringField(sb, OPERATION_NAME_FIELD, 
StringUtils.trimToNull(params.getOperationName()));
+        sb.append(",");
 
         if (StringUtils.isNotBlank(params.getVariables())) {
-            try {
-                final ObjectNode variablesJson = 
mapper.readValue(params.getVariables(), ObjectNode.class);
-                postBodyJson.set(VARIABLES_FIELD, variablesJson);
-            } catch (JsonProcessingException e) {
-                log.error("Ignoring the GraphQL query variables content due to 
the syntax error: {}",
-                        e.getLocalizedMessage());
-            }
+            sb.append("\"").append(VARIABLES_FIELD).append("\":");
+            sb.append(StringUtils.trim(params.getVariables()));
+            sb.append(",");
         }
 
-        postBodyJson.set(QUERY_FIELD, 
JsonNodeFactory.instance.textNode(StringUtils.trim(params.getQuery())));
+        appendJsonStringField(sb, QUERY_FIELD, 
escapeNewLinesForJson(StringUtils.trim(params.getQuery())));

Review comment:
       Fixed using `JsonGenerator` for safety: 
5c9fb4f92b20bb3feb5770023d7ed4ed021a29d6 Thanks!




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