diff --git a/native/src/main/java/io/ballerina/lib/data/jsondata/io/BallerinaByteBlockInputStream.java b/native/src/main/java/io/ballerina/lib/data/jsondata/io/BallerinaByteBlockInputStream.java index 705b761..6c4116b 100644 --- a/native/src/main/java/io/ballerina/lib/data/jsondata/io/BallerinaByteBlockInputStream.java +++ b/native/src/main/java/io/ballerina/lib/data/jsondata/io/BallerinaByteBlockInputStream.java @@ -21,7 +21,6 @@ import io.ballerina.lib.data.jsondata.utils.DiagnosticErrorCode; import io.ballerina.lib.data.jsondata.utils.DiagnosticLog; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.concurrent.StrandMetadata; import io.ballerina.runtime.api.types.MethodType; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; @@ -83,7 +82,7 @@ public int read() { public void close() throws IOException { super.close(); if (closeMethod != null) { - env.getRuntime().callMethod(iterator, closeMethod.getName(), new StrandMetadata(false, null)); + env.getRuntime().callMethod(iterator, closeMethod.getName(), null); } } @@ -93,7 +92,7 @@ private boolean hasBytesInCurrentChunk() { private boolean readNextChunk() throws InterruptedException { try { - Object result = env.getRuntime().callMethod(iterator, nextMethodName, new StrandMetadata(false, null)); + Object result = env.getRuntime().callMethod(iterator, nextMethodName, null); if (result == null) { done = true; return true; diff --git a/native/src/main/java/io/ballerina/lib/data/jsondata/json/Native.java b/native/src/main/java/io/ballerina/lib/data/jsondata/json/Native.java index 0161865..894c302 100644 --- a/native/src/main/java/io/ballerina/lib/data/jsondata/json/Native.java +++ b/native/src/main/java/io/ballerina/lib/data/jsondata/json/Native.java @@ -85,13 +85,15 @@ public static Object parseBytes(BArray json, BMap options, BTyp public static Object parseStream(Environment env, BStream json, BMap options, BTypedesc typed) { final BObject iteratorObj = json.getIteratorObj(); - BallerinaByteBlockInputStream byteBlockSteam = new BallerinaByteBlockInputStream(env, - iteratorObj, resolveNextMethod(iteratorObj), resolveCloseMethod(iteratorObj)); - Object result = JsonParser.parse(new InputStreamReader(byteBlockSteam), options, typed); - if (byteBlockSteam.getError() != null) { - return byteBlockSteam.getError(); - } - return result; + return env.yieldAndRun(() -> { + BallerinaByteBlockInputStream byteBlockSteam = new BallerinaByteBlockInputStream(env, iteratorObj, + resolveNextMethod(iteratorObj), resolveCloseMethod(iteratorObj)); + Object result = JsonParser.parse(new InputStreamReader(byteBlockSteam), options, typed); + if (byteBlockSteam.getError() != null) { + return byteBlockSteam.getError(); + } + return result; + }); } public static Object toJson(Object value) {