From 1302e69373aff9362382bab092bc968517bea964 Mon Sep 17 00:00:00 2001 From: lwang Date: Wed, 21 Jul 2021 20:45:24 +0800 Subject: [PATCH] add config to control close parser on stop or not --- .../main/java/org/jsfr/json/SurfingConfiguration.java | 9 +++++++++ .../src/main/java/org/jsfr/json/FastJsonParser.java | 2 +- jsurfer-gson/src/main/java/org/jsfr/json/GsonParser.java | 2 +- .../src/main/java/org/jsfr/json/JacksonParser.java | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/jsurfer-core/src/main/java/org/jsfr/json/SurfingConfiguration.java b/jsurfer-core/src/main/java/org/jsfr/json/SurfingConfiguration.java index 5f80537..9b0fdf2 100644 --- a/jsurfer-core/src/main/java/org/jsfr/json/SurfingConfiguration.java +++ b/jsurfer-core/src/main/java/org/jsfr/json/SurfingConfiguration.java @@ -314,6 +314,7 @@ public int compare(IndefinitePathBinding o1, IndefinitePathBinding o2) { private int maxDepth = -1; private boolean skipOverlappedPath = false; private boolean hasFilter = false; + private boolean closeParserOnStop = true; private Binding[][] definitePathLookup; @@ -387,4 +388,12 @@ public boolean hasFilter() { return hasFilter; } + public void setCloseParserOnStop(boolean closeParserOnStop) { + this.closeParserOnStop = closeParserOnStop; + } + + public boolean isCloseParserOnStop() { + return closeParserOnStop; + } + } diff --git a/jsurfer-fastjson/src/main/java/org/jsfr/json/FastJsonParser.java b/jsurfer-fastjson/src/main/java/org/jsfr/json/FastJsonParser.java index 3c0ebb7..d1fe6f2 100644 --- a/jsurfer-fastjson/src/main/java/org/jsfr/json/FastJsonParser.java +++ b/jsurfer-fastjson/src/main/java/org/jsfr/json/FastJsonParser.java @@ -145,7 +145,7 @@ private void doParse() { context.primitive(staticPrimitiveHolder.withValue(tempString)); } - if (context.isStopped()) { + if (context.getConfig().isCloseParserOnStop() && context.isStopped()) { lexer.close(); } diff --git a/jsurfer-gson/src/main/java/org/jsfr/json/GsonParser.java b/jsurfer-gson/src/main/java/org/jsfr/json/GsonParser.java index 4425b1d..65e8c9d 100644 --- a/jsurfer-gson/src/main/java/org/jsfr/json/GsonParser.java +++ b/jsurfer-gson/src/main/java/org/jsfr/json/GsonParser.java @@ -124,7 +124,7 @@ private void doParse() { break; } } - if (context.isStopped()) { + if (context.getConfig().isCloseParserOnStop() && context.isStopped()) { jsonReader.close(); } } catch (Exception e) { diff --git a/jsurfer-jackson/src/main/java/org/jsfr/json/JacksonParser.java b/jsurfer-jackson/src/main/java/org/jsfr/json/JacksonParser.java index 40daee9..2052b38 100644 --- a/jsurfer-jackson/src/main/java/org/jsfr/json/JacksonParser.java +++ b/jsurfer-jackson/src/main/java/org/jsfr/json/JacksonParser.java @@ -200,7 +200,7 @@ void doPare() throws IOException { throw new IllegalStateException("Unexpected token"); } } - if (context.isStopped()) { + if (context.getConfig().isCloseParserOnStop() && context.isStopped()) { this.jsonParser.close(); } }