vlsi commented on a change in pull request #651:
URL: https://github.com/apache/jmeter/pull/651#discussion_r593794397



##########
File path: 
src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/GraphQLRequestParamUtils.java
##########
@@ -79,27 +76,32 @@ 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 result = new StringBuilder();

Review comment:
       Just for the reference, here's how you generate raw JSON with 
JsonGenerator:
   
   ```java
       private static final JsonFactory factory = JsonFactory.builder().build();
   
       public static String toPostBodyString(final GraphQLRequestParams params) 
{
           StringWriter sw = new StringWriter();
           try (JsonGenerator gen = factory.createGenerator(sw)) {
               gen.writeStartObject();
               gen.writeStringField(OPERATION_NAME_FIELD, 
nullIfBlank(params.getOperationName()));
               String variables = params.getVariables();
               gen.writeFieldName(VARIABLES_FIELD);
               gen.writeRawValue(variables.trim());
               gen.writeStringField(QUERY_FIELD, 
nullIfBlank(params.getQuery()));
               gen.writeEndObject();
           } catch (IOException e) {
               throw new IllegalStateException("Can't write params to JSON", e);
           }
           return sw.toString();
       }
   
       private static String nullIfBlank(String value) {
           if (value == null) {
               return null;
           }
           value = value.trim();
           return value.isEmpty() ? null : value;
       }
   ```
   
   However, I still believe that is the wrong direction. It fixes one issue and 
creates another :((




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

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


Reply via email to