[BUG] java.lang.NoSuchMethodError: 'boolean com.alibaba.fastjson2.JSONReader.nextIfArrayStart()'
- 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;
}
为啥换一个机器就可以。

Contributor 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