我一直试图将xml(作为字符串)解组到一个对象,但它返回了一个NullPointerException错误。我花了一周时间寻找解决方案,但似乎什么都没用。我已经多次修改了“unmarshallpacs008”方法和“Spienvelessage”类,尝试了我在论坛上找到的其他东西。
在调试代码时,我看到错误发生在“unmarshaller.unmarshal”点,在该点上,“SpinevelMessage”类中存在的所有2个元素都返回null。它们的返回方式如下图所示,但我已经更改了@XmlElement的名称和属性,没有任何效果。
appHdr=null文档=null
抛出错误的点在“message.getDocument()......”bc没有文档,因为它返回null(PSPEmissorService的第94行)
java.lang.NullPointerException: null
at com.praxis.spi_simulator.psp_emissor.application.services.PSPEmissorService.sendPaymentsToSpi(PSPEmissorService.java:94) ~[classes/:na]
at com.praxis.spi_simulator.psp_emissor.application.controller.PSPEmissorController.sendPaymentsToSpiIssuer(PSPEmissorController.java:70) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197) ~[spring-web-5.3.5.jar:5.3.5]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141) ~[spring-web-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1060) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:962) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.5.jar:5.3.5]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.5.jar:5.3.5]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:652) ~[tomcat-embed-core-9.0.44.jar:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.5.jar:5.3.5]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.44.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.44.jar:9.0.44]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.5.jar:5.3.5]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.5.jar:5.3.5]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.5.jar:5.3.5]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.5.jar:5.3.5]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.5.jar:5.3.5]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.5.jar:5.3.5]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1707) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.44.jar:9.0.44]
at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]
SPIEnvelopeMessage message = XMLUtil.unmarshallpacs008(xml);
idLongStr = ("" + idLong).length() < SimulatorConstants.TAMANIO_COMPLEMENTO ? "0" + idLong : "" + idLong;
message.getDocument().getFIToFICstmrCdtTrf().getGrpHdr().setMsgId(idSufijo + idLongStr);
message.getAppHdr().setBizMsgIdr(idSufijo + idLongStr);
@XmlRootElement(name = "Envelope")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SPIEnvelopeMessage", propOrder = {
"appHdr",
"document"
})
public class SPIEnvelopeMessage {
@XmlElement(name = "AppHdr", required = true)
protected SPIHead00100101 appHdr;
@XmlElement(name = "Document", required = true)
protected SPIPacs00800109 document;
/**
* Obtiene el valor de la propiedad appHdr.
*
* @return
* possible object is
* {@link SPIHead00100101 }
*
*/
public SPIHead00100101 getAppHdr() {
return appHdr;
}
/**
* Define el valor de la propiedad appHdr.
*
* @param value
* allowed object is
* {@link SPIHead00100101 }
*
*/
public void setAppHdr(SPIHead00100101 value) {
this.appHdr = value;
}
/**
* Obtiene el valor de la propiedad document.
*
* @return
* possible object is
* {@link SPIPacs00800109 }
*
*/
public SPIPacs00800109 getDocument() {
return document;
}
/**
* Define el valor de la propiedad document.
*
* @param value
* allowed object is
* {@link SPIPacs00800109 }
*
*/
public void setDocument(SPIPacs00800109 value) {
this.document = value;
}
}
@SuppressWarnings("unchecked")
public static SPIEnvelopeMessage unmarshallpacs008(String xml)
throws JAXBException {
StringReader sr = new StringReader(xml);
JAXBContext jc = JAXBContext.newInstance(SPIEnvelopeMessage.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
return (SPIEnvelopeMessage) ((JAXBElement) unmarshaller.unmarshal(sr)).getValue();
}
要列表一个对象,您必须确保该对象以及该对象的内容是可序列化的。
尝试在您的类中实现Serializable接口:
public SPIEnvelopeMessage implements Serializable {}
XML响应 我为电影和图像创建了pojo类。 Film.java 形象JAVA 请帮助我是新来的,我应该使用JAXB。 解决方案: 我已经加了 在Image的getter方法中,我添加了@xmlement(name=“Image”)。 在Image类中,我添加了一个注释@XmlRootElement(name=“Image”),它提供了我想要的东西。
我使用JAXB解组XML文件Java对象。 这个XML包含一个列表。例如 Java类为items提供@xmlementwrapper 当我试图解组时,会出现空指针异常。
问题内容: 如标题所示,我试图将XML直接解组到地图中,而不必先解组为结构,然后将结构转换为地图。我正在处理相当大的数据集,并且双重转换所花费的时间比预期的要多。 如果有人能对此提供任何指导,将不胜感激。 XML:重复classAccesses,还有其他一些元素。 我当前的结构:我首先解析出每个标头元素,然后使用子元素创建一个新结构 所需的地图:我想保留diffs结构,但我希望子结构“ Class
问题内容: 我正在使用Internet上将对象编组为XML文件的API。鉴于XSD文件也可用,所以我希望一旦下载文件就可以将它们解编回到Java对象中。 环顾四周后,看起来JAXB是用Java进行此操作的默认库,但是当我开发移动应用程序时,额外的8.6MB依赖性是不可接受的。我还找到了XStream,但它仍然重达7.9MB。 看看Android SDK,看起来唯一可用的真正XML解析器是SAX。
我有一个类,它有一个包含的列表。在我的应用程序中,我在中设置细节,然后添加到的中,然后使用将转换为。 下面代码行的1个illegalAnnotationExc一定类有两个相同名称的属性trainingList