vlsi commented on a change in pull request #660:
URL: https://github.com/apache/jmeter/pull/660#discussion_r750057518
##########
File path:
src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/GraphQLRequestParamUtils.java
##########
@@ -79,28 +81,27 @@ 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())));
-
- 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());
+ final JsonFactory jsonFactory = new JsonFactory();
+ final StringWriter writer = new StringWriter(1024);
+
+ try (JsonGenerator gen = jsonFactory.createGenerator(writer)) {
+ gen.writeStartObject();
+
+ gen.writeStringField(OPERATION_NAME_FIELD,
StringUtils.trimToNull(params.getOperationName()));
+
+ if (StringUtils.isNotBlank(params.getVariables())) {
+ gen.writeRaw(",\"" + VARIABLES_FIELD + "\":");
Review comment:
Just wondering: does writeFieldName work here?
##########
File path:
src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/util/GraphQLRequestParamUtils.java
##########
@@ -79,28 +81,27 @@ 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())));
-
- 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());
+ final JsonFactory jsonFactory = new JsonFactory();
+ final StringWriter writer = new StringWriter(1024);
+
+ try (JsonGenerator gen = jsonFactory.createGenerator(writer)) {
+ gen.writeStartObject();
+
+ gen.writeStringField(OPERATION_NAME_FIELD,
StringUtils.trimToNull(params.getOperationName()));
+
+ if (StringUtils.isNotBlank(params.getVariables())) {
+ gen.writeRaw(",\"" + VARIABLES_FIELD + "\":");
Review comment:
Just wondering: does writeFieldName(VARIABLES_FIELD) work here?
--
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]