GWT 导入 Class 和 net.sf.jsonJSONObject
GWT Import Class and net.sf.jsonJSONObject
我在同一个包中有 2 个 class。最初的编译和构建很好,没有任何问题。不是由于要求,我正在为 class B 在 class A 中创建一个对象。
Class A {
int a;
Sting b;
B b;
.. all getters and setters..
}
import net.sf.json.JSONObject;
Class B {
..do JSON activities..
}
两个 classes 都没有 gwt.xml 并且不在表示层中。客户端 classes 和 gwt xml 在一个单独的包中。它们在同一个包中。
现在,当删除 class A 中的 class B 对象时,构建工作正常。当我们在 class 中有对象时,我得到错误
[ERROR] Errors in 'file:......./domain/ExecutorResponse.java'
[ERROR] Line 73: No source code is available for type net.sf.json.JSONObject; did you forget to inherit a required module?
[ERROR] Unable to find type '....ReleaseReportModule'
[ERROR] Hint: Previous compiler errors may have made this type unavailable
我的 POM 映射了依赖关系。构建工作到现在为止。添加对象后最近才失败。我还尝试在使用这些 class 对象的父 gwt xml 中添加 <inherit... >
,但没有成功。
这可能是什么问题?
我的包结构是
src/main/java
|
|--com.my.pack.helper
|
|--both my classes are here
|
|--com.my.pack.gwt
|
|--contains client side classes with UIObjects and Widgets. Helper objects used here to populate the data.
src/main/resources
|
|--com.my.pack.gwt
|
|--widgets
|
|--contains the ui.xml & gwt.xml
|
|--common.gwt.xml
问题是您正尝试在客户端使用 net.sf.json.JSONObject
class,而 gwt 不知道 如何翻译javascript.
有关客户端支持的 classes,请参阅 this list。
我想建议使用 gwt-jsonwrapper in client side. If you still willing to use net.sf.json,仅在 GWT 项目的服务器端使用,并且 return 值通过 RPC 作为字符串格式。
public final String getSomething() {
JSONObject obj = new JSONObject();
Bean bean = .....;
obj = JSONObject.fromObject(bean);
return StringEscapeUtils.escapeHtml(obj.toString());
}
在您的客户端,将结果字符串解析为
HTML html = new HTML(result.replace(" ", "-"));
JSONValue value = JSONParser.parseLenient(html.getText());
JSONWrapper json = new JSONWrapper(value);
JSONWrapper data = json.get("key");
要使用 gwt-jsonwrapper ,请在 module.xml
中添加以下两行
<inherits name="com.google.gwt.json.JSON"/>
<inherits name='com.pathf.gwt.util.json.jsonwrapper'/>
我在同一个包中有 2 个 class。最初的编译和构建很好,没有任何问题。不是由于要求,我正在为 class B 在 class A 中创建一个对象。
Class A {
int a;
Sting b;
B b;
.. all getters and setters..
}
import net.sf.json.JSONObject;
Class B {
..do JSON activities..
}
两个 classes 都没有 gwt.xml 并且不在表示层中。客户端 classes 和 gwt xml 在一个单独的包中。它们在同一个包中。 现在,当删除 class A 中的 class B 对象时,构建工作正常。当我们在 class 中有对象时,我得到错误
[ERROR] Errors in 'file:......./domain/ExecutorResponse.java'
[ERROR] Line 73: No source code is available for type net.sf.json.JSONObject; did you forget to inherit a required module?
[ERROR] Unable to find type '....ReleaseReportModule'
[ERROR] Hint: Previous compiler errors may have made this type unavailable
我的 POM 映射了依赖关系。构建工作到现在为止。添加对象后最近才失败。我还尝试在使用这些 class 对象的父 gwt xml 中添加 <inherit... >
,但没有成功。
这可能是什么问题?
我的包结构是
src/main/java
|
|--com.my.pack.helper
|
|--both my classes are here
|
|--com.my.pack.gwt
|
|--contains client side classes with UIObjects and Widgets. Helper objects used here to populate the data.
src/main/resources
|
|--com.my.pack.gwt
|
|--widgets
|
|--contains the ui.xml & gwt.xml
|
|--common.gwt.xml
问题是您正尝试在客户端使用 net.sf.json.JSONObject
class,而 gwt 不知道 如何翻译javascript.
有关客户端支持的 classes,请参阅 this list。
我想建议使用 gwt-jsonwrapper in client side. If you still willing to use net.sf.json,仅在 GWT 项目的服务器端使用,并且 return 值通过 RPC 作为字符串格式。
public final String getSomething() {
JSONObject obj = new JSONObject();
Bean bean = .....;
obj = JSONObject.fromObject(bean);
return StringEscapeUtils.escapeHtml(obj.toString());
}
在您的客户端,将结果字符串解析为
HTML html = new HTML(result.replace(" ", "-"));
JSONValue value = JSONParser.parseLenient(html.getText());
JSONWrapper json = new JSONWrapper(value);
JSONWrapper data = json.get("key");
要使用 gwt-jsonwrapper ,请在 module.xml
中添加以下两行<inherits name="com.google.gwt.json.JSON"/>
<inherits name='com.pathf.gwt.util.json.jsonwrapper'/>