Skip to content

Commit

Permalink
增加帮助函数
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Jan 23, 2025
1 parent dee2cd5 commit e0765de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions nop-core/src/main/java/io/nop/core/lang/json/JsonTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.yaml.snakeyaml.Yaml;

import java.lang.reflect.Type;
import java.util.Map;
import java.util.function.Function;

import static io.nop.core.CoreConfigs.CFG_JSON_PARSE_IGNORE_UNKNOWN_PROP;
Expand All @@ -40,6 +41,8 @@ public static IJsonTool instance() {
}

public static Object parse(String str) {
if (StringHelper.isBlank(str))
return null;
JsonParseOptions options = new JsonParseOptions();
options.setStrictMode(true);
return instance().parseFromText(null, str, options);
Expand All @@ -51,6 +54,10 @@ public static Object parseNonStrict(String str) {
return instance().parseFromText(null, str, options);
}

public static Map<String, Object> parseMap(String str) {
return (Map<String, Object>) parseNonStrict(str);
}

public static Object parseNonStrict(SourceLocation loc, String str) {
JsonParseOptions options = new JsonParseOptions();
options.setStrictMode(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.nop.api.core.util.SourceLocation;
import io.nop.api.core.util.Symbol;
import io.nop.commons.text.tokenizer.TextScanner;
import io.nop.commons.util.StringHelper;

import java.util.Collections;
import java.util.LinkedHashMap;
Expand All @@ -21,6 +22,12 @@
import static io.nop.core.CoreErrors.ERR_SELECTION_INVALID_ARG_NAME;

public class FieldSelectionBeanParser {
public static FieldSelectionBean fromText(SourceLocation loc, String text) {
if (StringHelper.isEmpty(text))
return null;
return new FieldSelectionBeanParser().parseFromText(loc, text);
}

public FieldSelectionBean parseFromText(SourceLocation loc, String text) {
TextScanner sc = TextScanner.fromString(loc, text);
sc.skipBlank();
Expand Down

0 comments on commit e0765de

Please sign in to comment.