我序列化下面的類,所以我可以送過來一個REST接口:序列化java.lang.Error的
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
/**
* Object that holds information on result of executed method on remote agent.
*/
public class ResultMessage implements Message {
private static final long serialVersionUID = -8740453631197286688L;
private Exception exception;
private Error error;
private String exceptionType;
private String errorType;
public String getCmdResponse() {
return cmdResponse;
}
public Exception getException() {
return exception;
}
public void setException(Exception e) {
this.exception = e;
if (e != null) {
this.exceptionType = e.getClass().getName();
}
}
public String getExceptionType() {
return exceptionType;
}
public Error getError() {
return error;
}
public void setError(Error error) {
this.error = error;
if (error != null) {
this.errorType = error.getClass().getName();
}
}
public String getErrorType() {
return errorType;
}
}
我可以編碼沒有任何問題異常,但我似乎無法編碼錯誤。以下錯誤:
java.lang.NoClassDefFoundError: com/cfg/ObjectRepositoryFactory
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: com.cfg.ObjectRepositoryFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 7 more
當我嘗試序列化此我得到:
org.jboss.resteasy.spi.ReaderException:
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized
field "exception" (Class java.lang.Throwable), not marked as ignorable
at [Source: [email protected];
line: 1, column: 2080] (through reference chain:
com.rest.message.ResultMessage["error"]->java.lang.Throwable["exception"])
這就是場被置:
try {
verb.runCommand(result);
} catch (Exception e) {
LOGGER.fatal("Failed to execute command [" + msg.getCommand() + "] due to exception");
System.err.println("Exception: ");
e.printStackTrace();
LOGGER.trace(e.getMessage(), e);
result.setException(e);
} catch (Error ee) {
result.setError(ee);
System.err.println("Error: ");
ee.printStackTrace();
LOGGER.trace(ee.getMessage(), ee);
LOGGER.fatal("Failed to execute command [" + msg.getCommand() + "] due to error");
} finally {
sendResult(result);
}
當我趕上的java.lang。它的異常工作正常,但沒有這個特殊的java.lang.Error。
你真的需要跟蹤和序列化完整的Throwables與他們的stacktrace和所有?你能不能在發生錯誤時記錄錯誤,並記錄錯誤代碼或-message? –