gpt4 book ai didi

JavaSerializer - 序列化对象时出错 -> wicket

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:18:11 26 4
gpt4 key购买 nike

我有一个带有选项卡的主页 (BasePage),一切正常,我的代码功能没有任何问题。但是这个异常让我很烦,我想摆脱它。我看了这个

Error serializing object class - when running Wicket and GAE

还有这个

Wicket: how to get rid of WicketNotSerializableException?

但我没能解决我的问题。谁能帮帮我?

public class BasePage extends WebPage {
public static final String PATH = "base";

public BasePage() {
final List tabs = new ArrayList<>();

//add Search Item Tab
tabs.add(new AbstractTab(new Model<>("Search Item")) {
@Override
public WebMarkupContainer getPanel(String s) {
return new SearchItem(s);
}
});

//add Search Domain Tab
tabs.add(new AbstractTab(new Model<>("Search Domain")) {
@Override
public WebMarkupContainer getPanel(String s) {
return new SearchDomain(s);
}
});

AjaxTabbedPanel ajaxTabbedPanel = new AjaxTabbedPanel("tabs", tabs);

add(new AjaxTabbedPanel("tabs", tabs));
}
}

堆栈跟踪:

2015-08-28 11:39:48,456 [http-bio-8080-exec-12] ERROR org.apache.wicket.serialize.java.JavaSerializer - Error serializing object class com.ui.homepage.BasePage [object=[Page class = com.ui.homepage.BasePage, id = 0, render count = 1]]
org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream$ObjectCheckException: The object type is not Serializable!
A problem occurred while checking object with type: com.persistence.RequestEntityDAOExtra
Field hierarchy is:
0 [class=com.ui.homepage.BasePage, path=0]
private java.lang.Object org.apache.wicket.MarkupContainer.children [class=org.apache.wicket.extensions.ajax.markup.html.tabs.AjaxTabbedPanel, path=0:tabs]
private java.lang.Object org.apache.wicket.MarkupContainer.children [class=[Ljava.lang.Object;]
private org.apache.wicket.markup.html.link.PopupSettings org.apache.wicket.markup.html.link.Link.popupSettings[1] [class=com.searchpages.SearchItem, path=0:tabs:panel]
private java.lang.Object org.apache.wicket.MarkupContainer.children [class=[Ljava.lang.Object;]
private java.lang.Object org.apache.wicket.MarkupContainer.children[1] [class=org.apache.wicket.markup.html.form.Form, path=0:tabs:panel:searchForm]
private java.lang.Object org.apache.wicket.MarkupContainer.children [class=[Ljava.lang.Object;]
private java.lang.Object org.apache.wicket.MarkupContainer.children[0] [class=org.apache.wicket.markup.html.WebMarkupContainer, path=0:tabs:panel:searchForm:searchInput]
private java.lang.Object org.apache.wicket.MarkupContainer.children [class=[Ljava.lang.Object;]
private java.lang.Object org.apache.wicket.MarkupContainer.children[0] [class=org.apache.wicket.extensions.ajax.markup.html.autocomplete.AutoCompleteTextField, path=0:tabs:panel:searchForm:searchInput:callerId]
final com.persistence.RequestEntityDAOExtra com.ui.searchpages.SearchItem$1.val$requestEntityDAOExtra [class=com.persistence.RequestEntityDAOExtra] <----- field that is causing the problem

更新:我发现了问题,但我不明白为什么会这样

之前:

final RequestEntityDAOExtra requestEntityDAOExtra =
((MyApp) getApplication()).getRequestEntityDAOExtra();

//callerId input
final AutoCompleteTextField<String> callerInput = new AutoCompleteTextField<String>("callerId", new Model<String>(),
autoCompleteSettings) {
@Override
protected Iterator getChoices(String callerId) {
return requestEntityDAOExtra.getEntitiesByCallerId(callerId).iterator();
}
};

之后:

final AutoCompleteTextField<String> callerInput = new AutoCompleteTextField<String>("callerId", new Model<String>(),
autoCompleteSettings) {
@Override
protected Iterator getChoices(String callerId) {
final RequestEntityDAOExtra requestEntityDAOExtra =
((MyApp) getApplication()).getRequestEntityDAOExtra();
return requestEntityDAOExtra.getEntitiesByCallerId(callerId).iterator();
}
};

如果我在方法中声明我的 dao 对象,异常将不再存在。但是为什么?

最佳答案

看起来 RequestEntityDAOExtra 不是 Serializable。我真的不能说为什么不或者它是否应该 Serializable 因为它在很大程度上取决于您的应用程序。

在您的第一种情况下,您声明:

final RequestEntityDAOExtra requestEntityDAOExtra =
((MyApp) getApplication()).getRequestEntityDAOExtra();

在序列化期间,这将被视为与任何成员变量相同,因为每当执行匿名内部类时都需要恢复它。我的建议是在 Wicket 上下文中将变量声明为 final 时要非常小心。对于我的项目,我只允许将 IModel 的实现声明为最终的(显然加上任何 Wicket 组件)。

您的第二种方法有效,因为 RequestEntityDAOExtra 不会使用 Panel 进行序列化,而是每次从您的 Application 重新请求。

关于JavaSerializer - 序列化对象时出错 -> wicket,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32267082/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com