Skip to content

Commit

Permalink
Remove Json parser APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
HindujaB committed Mar 6, 2024
1 parent e2dddd4 commit fa1fa69
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ public class JsonParser {
private JsonParser() {
}

private static final ThreadLocal<StateMachine> tlStateMachine = ThreadLocal.withInitial(JsonStateMachine::new);

/**
* Parses the contents in the given {@link InputStream} and returns a json.
*
Expand Down Expand Up @@ -107,15 +105,19 @@ public static Object parse(String jsonStr, JsonUtils.NonStringValueProcessingMod
* @throws BError for any parsing error
*/
public static Object parse(Reader reader, JsonUtils.NonStringValueProcessingMode mode) throws BError {
JsonStateMachine sm = (JsonStateMachine) tlStateMachine.get();
try {
sm.setMode(mode);
return sm.execute(reader);
} finally {
// Need to reset the state machine before leaving. Otherwise, references to the created
// JSON values will be maintained and the java GC will not happen properly.
sm.reset();
return StreamParser.parse(reader, getTargetType(mode));
}

private static Type getTargetType(JsonUtils.NonStringValueProcessingMode mode) {
Type targetType;
if (mode == FROM_JSON_DECIMAL_STRING) {
targetType = PredefinedTypes.TYPE_JSON_DECIMAL;
} else if (mode == FROM_JSON_FLOAT_STRING) {
targetType = PredefinedTypes.TYPE_JSON_FLOAT;
} else {
targetType = PredefinedTypes.TYPE_JSON;
}
return targetType;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static Object parse(String str, Type targetType) throws BError {
* @return value of the given target type
* @throws BError for any parsing error
*/
private static Object parse(Reader reader, Type targetType) throws BError {
public static Object parse(Reader reader, Type targetType) throws BError {
StreamStateMachine sm = tlStateMachine.get();
try {
sm.addTargetType(targetType);
Expand Down

0 comments on commit fa1fa69

Please sign in to comment.