我用以下信息解决了这个问题:http
:
//forums.java.net/jive/thread.jspa?messageID=256122
您需要使用以下配置初始化JAXBContext(其中jaxbObj是要序列化的对象):
Map<String, Object> jaxbConfig = new HashMap<String, Object>(); // initialize our custom readerTransientAnnotationReader reader = new TransientAnnotationReader();try { reader.addTransientField(Throwable.class.getDeclaredField("stackTrace")); reader.addTransientMethod(Throwable.class.getDeclaredMethod("getStackTrace"));} catch (SecurityException e) { throw new RuntimeException(e);} catch (NoSuchMethodException e) { throw new RuntimeException(e);} catch (NoSuchFieldException e) { throw new RuntimeException(e);}jaxbConfig.put(JAXBRIContext.ANNOTATION_READER, reader);JAXBContext jc = JAXBContext.newInstance(new Class[] {jaxbObj.getClass()},jaxbConfig);


