Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] java.lang.NoSuchMethodError: 'boolean com.alibaba.fastjson2.JSONReader.nextIfArrayStart()' #3322

Open
fakerlove1 opened this issue Jan 26, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@fakerlove1
Copy link

/**
 * 从文件中获取最大的json字段名称
 *
 * @param file 文件
 * @return 对应的json映射sql配置
 */
public static List<JsonMappingSqlDTO> getJsonMappingSqlDTOList(File file) {
    List<JsonMappingSqlDTO> jsonMappingSqlDTOList = new ArrayList<>();
    InputStreamReader inputStreamReader = null;
    JSONReader reader = null;
    Set<String> columnNames = new HashSet<>();
    try {
        inputStreamReader = new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8);
        reader = new JSONReader(inputStreamReader);
        reader.startArray(); // 启动数组解析
        while (reader.hasNext()) {
            // 将其解析成Map<String,Object> 类型
            JSONObject object = (JSONObject) reader.readObject();
            // 获取所有的key
            Set<String> keySet = object.keySet();
            for (String key : keySet) {
                if (!columnNames.contains(key)) {
                    columnNames.add(key);
                    JsonMappingSqlDTO jsonMappingSqlDTO = new JsonMappingSqlDTO();
                    jsonMappingSqlDTO.setFrom(key);
                    jsonMappingSqlDTO.setTo(key);
                    String type = Optional.ofNullable(object.get(key))
                            .map(value -> value.getClass().getSimpleName())
                            .orElse("String");
                    jsonMappingSqlDTO.setType(type);
                    jsonMappingSqlDTOList.add(jsonMappingSqlDTO);
                }
            }
        }
        reader.endArray();

    } catch (Exception e) {
        log.error("获取文件失败", e);
    } finally {

        try {
            if (Objects.nonNull(reader)) {
                reader.close();
            }
            if (Objects.nonNull(inputStreamReader)) {
                inputStreamReader.close();
            }
        } catch (IOException e) {
            log.error("关闭文件失败", e);
        }
    }

    return jsonMappingSqlDTOList;
}

为啥换一个机器就可以。

Image

@fakerlove1 fakerlove1 added the bug Something isn't working label Jan 26, 2025
@wenshao
Copy link
Member

wenshao commented Jan 30, 2025

是多个jar共存加载顺序不一样导致问题了吧?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants