[BUG]
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
配置:
// for scala, 使用需要转换为java的String
```
val route: String =
"""
|[
| {
| "childrenMenus": [],
| "menuVO": {
| "code": "home",
| "description": "",
| "elementVOS": [],
| "href": "org.poem.client.gui.uicomponents.carinfollist.StayDistributionProveListController",
| "icon": "jiaoyixulie",
| "id": 44,
| "orderNum": 0,
| "parentId": 13,
| "path": "org.poem.client.gui.uicomponents.carinfollist.StayDistributionProveListController",
| "sel": false,
| "title": "待获取回收证明车辆列表"
| }
| },
| {
| "childrenMenus": [],
| "menuVO": {
| "code": "home",
| "description": "",
| "elementVOS": [],
| "href": "org.poem.client.gui.uicomponents.carinfollist.DistributionProveListController",
| "icon": "jichupeizhi",
| "id": 44,
| "orderNum": 0,
| "parentId": 13,
| "path": "org.poem.client.gui.uicomponents.carinfollist.DistributionProveListController",
| "sel": false,
| "title": "已获取回收证明车辆"
| }
| }
|]
|""".stripMargin
转换对象:
public class MenuVoCell implements Serializable {
private ObjectProperty menuVO;
private ObservableList childrenMenus;
public MenuVoCell() {
}
public MenuVoCell(MenuVO menuVO, List childrenMenus) {
this.menuVO = new SimpleObjectProperty<>(menuVO);
if (childrenMenus != null) {
getChildrenMenus().addAll(childrenMenus);
}
}
public MenuVO getMenuVO() {
return menuVO.get();
}
public ObjectProperty menuVOProperty() {
return menuVO;
}
public ObservableList getChildrenMenus() {
if (childrenMenus == null) {
ObservableList innerList = FXCollections.observableArrayList();
childrenMenus = new SimpleListProperty<>(innerList);
}
return childrenMenus;
}
}
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class MenuVO implements Serializable {
private SimpleIntegerProperty id = new SimpleIntegerProperty();
private SimpleStringProperty code = new SimpleStringProperty();
private SimpleStringProperty title = new SimpleStringProperty();
private SimpleIntegerProperty parentId = new SimpleIntegerProperty();
private SimpleStringProperty href = new SimpleStringProperty();
private SimpleStringProperty icon = new SimpleStringProperty();
private SimpleStringProperty type = new SimpleStringProperty();
private SimpleIntegerProperty orderNum = new SimpleIntegerProperty();
private SimpleStringProperty description = new SimpleStringProperty();
private SimpleStringProperty path = new SimpleStringProperty();
private SimpleStringProperty enabled = new SimpleStringProperty();
private SimpleStringProperty node = new SimpleStringProperty();
private SimpleBooleanProperty sel = new SimpleBooleanProperty(false);
private List elementVOS;
public MenuVO() {
}
public int getId() {
return id.get();
}
public SimpleIntegerProperty idProperty() {
return id;
}
public void setId(int id) {
this.id.set(id);
}
public String getCode() {
return code.get();
}
public SimpleStringProperty codeProperty() {
return code;
}
public void setCode(String code) {
this.code.set(code);
}
public String getTitle() {
return title.get();
}
public SimpleStringProperty titleProperty() {
return title;
}
public void setTitle(String title) {
this.title.set(title);
}
public int getParentId() {
return parentId.get();
}
public SimpleIntegerProperty parentIdProperty() {
return parentId;
}
public void setParentId(int parentId) {
this.parentId.set(parentId);
}
public String getHref() {
return href.get();
}
public SimpleStringProperty hrefProperty() {
return href;
}
public void setHref(String href) {
this.href.set(href);
}
public String getIcon() {
return icon.get();
}
public SimpleStringProperty iconProperty() {
return icon;
}
public void setIcon(String icon) {
this.icon.set(icon);
}
public String getType() {
return type.get();
}
public SimpleStringProperty typeProperty() {
return type;
}
public void setType(String type) {
this.type.set(type);
}
public Integer getOrderNum() {
return orderNum.get();
}
public SimpleIntegerProperty orderNumProperty() {
return orderNum;
}
public void setOrderNum(int orderNum) {
this.orderNum.set(orderNum);
}
public String getDescription() {
return description.get();
}
public SimpleStringProperty descriptionProperty() {
return description;
}
public void setDescription(String description) {
this.description.set(description);
}
public String getPath() {
return path.get();
}
public SimpleStringProperty pathProperty() {
return path;
}
public void setPath(String path) {
this.path.set(path);
}
public String getEnabled() {
return enabled.get();
}
public SimpleStringProperty enabledProperty() {
return enabled;
}
public void setEnabled(String enabled) {
this.enabled.set(enabled);
}
public String getNode() {
return node.get();
}
public SimpleStringProperty nodeProperty() {
return node;
}
public void setNode(String node) {
this.node.set(node);
}
public boolean isSel() {
return sel.get();
}
public SimpleBooleanProperty selProperty() {
return sel;
}
public void setSel(boolean sel) {
this.sel.set(sel);
}
public List getElementVOS() {
if (elementVOS == null) {
elementVOS = new ArrayList<>();
}
return elementVOS;
}
@Override
public String toString() {
return getTitle();
}
}
在调用 静态方法把json转化为对象列表的时候报错:
操作:
public class Routes {
/**
* 获取所有的memu
*
* @return
*/
public static List getAllMenus(){
JSONArray jsonArray = JSONArray.parseArray(Route.route());
return jsonArray.toJavaList(MenuVoCell.class);
}
}
```
报告的异常是:
```
java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at com.alibaba.fastjson2.reader.ObjectReaderImplList.createInstance(ObjectReaderImplList.java:275)
at com.alibaba.fastjson2.reader.ObjectReaderImplList.createInstance(ObjectReaderImplList.java:194)
at com.alibaba.fastjson2.util.TypeUtils.cast(TypeUtils.java:1279)
at com.alibaba.fastjson2.reader.ObjectReader.createInstance(ObjectReader.java:136)
at com.alibaba.fastjson.JSONArray.toJavaList(JSONArray.java:828)
at org.poem.client.store.Routes.getAllMenus(Routes.java:26)
at org.poem.client.gui.uicomponents.login.LoginController.lambda$loadApplicatonStore$21(LoginController.java:461)
at io.datafx.core.concurrent.ProcessChain.lambda$addSupplier$2(ProcessChain.java:152)
at io.datafx.core.concurrent.ProcessChain.execute(ProcessChain.java:208)
at io.datafx.core.concurrent.ProcessChain.access$100(ProcessChain.java:64)
at io.datafx.core.concurrent.ProcessChain$1.call(ProcessChain.java:245)
at javafx.concurrent.Task$TaskCallable.call(Task.java:1423)
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
at java.util.concurrent.FutureTask.run(FutureTask.java)
at io.datafx.core.concurrent.RunnableBasedDataFxTask.call(RunnableBasedDataFxTask.java:58)
at io.datafx.core.concurrent.RunnableBasedDataFxTask.call(RunnableBasedDataFxTask.java:46)
at javafx.concurrent.Task$TaskCallable.call(Task.java:1423)
at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
at java.util.concurrent.FutureTask.run(FutureTask.java)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
```
在使用 fastjson1 的时候,转换没有异常
Contributor guide
Research direction
Start with Routes.getAllMenus(), JSONArray.toJavaList(MenuVoCell.class), and the ObjectReaderImplList.createInstance stack frames. Reproduce the conversion using the supplied JSON and Java classes, then compare the behavior with fastjson1. Done means the fastjson2 conversion no longer throws the reported NullPointerException and returns the expected MenuVoCell list.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100