alibaba / alibaba/fastjson2

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

Open
#3,322 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

/**
* 从文件中获取最大的json字段名称
*
* @param file 文件
* @return 对应的json映射sql配置
*/
public static List getJsonMappingSqlDTOList(File file) {
List jsonMappingSqlDTOList = new ArrayList<>();
InputStreamReader inputStreamReader = null;
JSONReader reader = null;
Set columnNames = new HashSet<>();
try {
inputStreamReader = new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8);
reader = new JSONReader(inputStreamReader);
reader.startArray(); // 启动数组解析
while (reader.hasNext()) {
// 将其解析成Map 类型
JSONObject object = (JSONObject) reader.readObject();
// 获取所有的key
Set 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](https://github.com/user-attachments/assets/c1c63581-5a89-4537-ab7b-83dc1d5040ad)

Contributor guide

Open the contributing guide

Research direction

Start with the NoSuchMethodError in the supplied getJsonMappingSqlDTOList method and inspect the JSONReader startArray call shown there. Compare the fastjson2 versions and runtime dependencies on the two machines, then reproduce the file parsing case; done means the same compatible JSONReader API works on both environments.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.