From ba05cb92a9aee2f5b31304d91b81aa2367e97743 Mon Sep 17 00:00:00 2001 From: Kyri Petrou Date: Wed, 22 Nov 2023 20:45:29 +1100 Subject: [PATCH] Fix InputValue.ListValue jsoniter encoder --- .../scala/caliban/interop/jsoniter/jsoniter.scala | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/core/src/main/scala/caliban/interop/jsoniter/jsoniter.scala b/core/src/main/scala/caliban/interop/jsoniter/jsoniter.scala index b13e9e787a..4bfaa7ebf9 100644 --- a/core/src/main/scala/caliban/interop/jsoniter/jsoniter.scala +++ b/core/src/main/scala/caliban/interop/jsoniter/jsoniter.scala @@ -5,7 +5,6 @@ import caliban._ import caliban.parsing.adt.LocationInfo import com.github.plokhotnyuk.jsoniter_scala.core._ -import scala.annotation.switch import scala.collection.immutable.TreeMap /** @@ -52,18 +51,17 @@ private[caliban] object ValueJsoniter { val depthM1 = depth - 1 if (depthM1 < 0) out.encodeError("depth limit exceeded") out.writeArrayStart() - l.foreach(v => encodeInputValue(v, out, depthM1)) + l.foreach(encodeInputValue(_, out, depthM1)) out.writeArrayEnd() case InputValue.ObjectValue(o) => - val depthM1 = depth - 1 + val depthM1 = depth - 1 if (depthM1 < 0) out.encodeError("depth limit exceeded") out.writeObjectStart() - var remaining = o - while (!remaining.isEmpty) { - val (k, v) = remaining.head + val iterator = o.iterator + while (iterator.hasNext) { + val (k, v) = iterator.next() out.writeKey(k) encodeInputValue(v, out, depthM1) - remaining = remaining.tail } out.writeObjectEnd() case InputValue.VariableValue(v) => out.writeVal(v) @@ -84,7 +82,7 @@ private[caliban] object ValueJsoniter { val depthM1 = depth - 1 if (depthM1 < 0) out.encodeError("depth limit exceeded") out.writeArrayStart() - l.foreach(v => encodeResponseValue(v, out, depthM1)) + l.foreach(encodeResponseValue(_, out, depthM1)) out.writeArrayEnd() case ResponseValue.ObjectValue(o) => val depthM1 = depth - 1