Skip to content

Commit

Permalink
Add support for Double values when formatting GraphQL variables for J…
Browse files Browse the repository at this point in the history
…SON.
  • Loading branch information
aoutzen-snap authored and jmartisk committed May 9, 2024
1 parent de1107b commit c7b5f6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ private JsonObject _formatJsonVariables() {
varBuilder.add(k, (Boolean) v);
} else if (v instanceof Long) {
varBuilder.add(k, (Long) v);
} else if (v instanceof Double) {
varBuilder.add(k, (Double) v);
} else if (v == null) {
varBuilder.addNull(k);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public void testPrimitiveTypesToJson() {

request.setVariable("key", "foo");
assertEquals("{\"query\":\"example\",\"variables\":{\"key\":\"foo\"}}", request.toJson());

request.setVariable("key", 5L);
assertEquals("{\"query\":\"example\",\"variables\":{\"key\":5}}", request.toJson());

request.setVariable("key", 5.5);
assertEquals("{\"query\":\"example\",\"variables\":{\"key\":5.5}}", request.toJson());
}

@Test
Expand Down

0 comments on commit c7b5f6a

Please sign in to comment.