Forum Stats

  • 3,839,736 Users
  • 2,262,532 Discussions
  • 7,901,052 Comments

Discussions

XMLMarshalException

managed BEAN
managed BEAN Member Posts: 948 Silver Badge
edited Feb 3, 2018 5:08PM in Java Programming

Hello everyone,

I have a xml format text in a String type variable.

I am trying to unmarshal it into a java class i created.

For some reason i do not know it is throwing following stack error:

[Exception [EclipseLink-25004] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.XMLMarshalExceptionException Description: An error occurred unmarshalling the documentInternal Exception: java.lang.NullPointerException]javax.xml.bind.UnmarshalException - with linked exception:[Exception [EclipseLink-25004] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.XMLMarshalExceptionException Description: An error occurred unmarshalling the documentInternal Exception: java.lang.NullPointerException]at org.eclipse.persistence.jaxb.JAXBUnmarshaller.handleXMLMarshalException(JAXBUnmarshaller.java:1110)at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:638)at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:163)at restwebservice.PeopleWS.getSearchedPeople(PeopleWS.java:124)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.eclipse.persistence.jaxb.JAXBUnmarshaller.handleXMLMarshalException(JAXBUnmarshaller.java:1110)at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:638)at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:163)at restwebservice.PeopleWS.getSearchedPeople(PeopleWS.java:124)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205)at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)at org.glassfish.jersey.internal.Errors.process(Errors.java:315)at org.glassfish.jersey.internal.Errors.process(Errors.java:297)at org.glassfish.jersey.internal.Errors.process(Errors.java:267)at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471)at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425)at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383)at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336)at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223)at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286)at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260)at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137)at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350)at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:141)at java.security.AccessController.doPrivileged(Native Method)at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:650)at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:124)at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:232)at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:94)at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:248)at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3683)at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3649)at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326)at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2433)at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2281)at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2259)at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1691)at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1651)at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:270)at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348)at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333)at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54)at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:640)at weblogic.work.ExecuteThread.execute(ExecuteThread.java:406)at weblogic.work.ExecuteThread.run(ExecuteThread.java:346)Caused by: Exception [EclipseLink-25004] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.XMLMarshalExceptionException Description: An error occurred unmarshalling the documentInternal Exception: java.lang.NullPointerExceptionat org.eclipse.persistence.exceptions.XMLMarshalException.unmarshalException(XMLMarshalException.java:120)at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.convertSAXException(SAXUnmarshaller.java:1040)at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:946)at org.eclipse.persistence.internal.oxm.XMLUnmarshaller.unmarshal(XMLUnmarshaller.java:653)at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:635)... 63 moreCaused by: java.lang.NullPointerExceptionat org.eclipse.persistence.internal.jaxb.XMLJavaTypeConverter.convertDataValueToObjectValue(XMLJavaTypeConverter.java:151)at org.eclipse.persistence.oxm.mappings.converters.XMLConverterAdapter.convertDataValueToObjectValue(XMLConverterAdapter.java:28)at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.getObjectValue(AbstractDirectMapping.java:616)at org.eclipse.persistence.oxm.mappings.XMLDirectMapping.getObjectValue(XMLDirectMapping.java:1)at org.eclipse.persistence.internal.oxm.XMLDirectMappingNodeValue.setNullValue(XMLDirectMappingNodeValue.java:209)at org.eclipse.persistence.internal.oxm.record.UnmarshalRecordImpl.endDocument(UnmarshalRecordImpl.java:645)at org.eclipse.persistence.internal.oxm.record.UnmarshalRecordImpl.endElement(UnmarshalRecordImpl.java:1123)at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parseEvent(XMLStreamReaderReader.java:154)at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parse(XMLStreamReaderReader.java:99)at org.eclipse.persistence.internal.oxm.record.XMLStreamReaderReader.parse(XMLStreamReaderReader.java:86)at org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller.unmarshal(SAXUnmarshaller.java:938)... 65 more

The xml is attached (the one ok and the one not ok).

The major difference is the size.

With one xml data it works with other it does not,so so it´s not the code itself, right?

xml = xml.replaceFirst("ROWSET xmlns:xsi = \"http://www.w3.org/2001/XMLSchema-instance\"","peopleRowList");String string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";xml = string.concat(xml);xml = xml.replaceAll("ROWSET", "peopleRowList");xml = xml.replaceAll("ROW", "peopleList");xml = xml.replaceAll(" xsi:nil = \"true\"", "");InputStream instr = new ByteArrayInputStream(xml.getBytes());JAXBContext jaxbContext = JAXBContext.newInstance(PeopleRowList.class);Unmarshaller  jaxbUnmarshaller = jaxbContext.createUnmarshaller();PeopleRowList test = (PeopleRowList) jaxbUnmarshaller.unmarshal(instr);peopleRowList = test;

What is happening?

Thanks for help.

Carlos

Best Answer

Answers

  • 836548
    836548 Member Posts: 286
    edited Feb 2, 2018 12:53AM

    i had similar issue earlier, try to use Java parse's rather than using eclipse plugin.

    The issue which i face was , the xml parser reading the file in chunk say 5316 character each time, and due to partial read it was giving error.

    as we have to use the plugin , hence to overcome, we entered blank line and made sure every tag will be closed with in 5316 line, and aligned our xml accordingly.

    Hope by doing so or adding comment line will help you too. But easy way i suggest to go for Java sax parser, rather than any external plugin

  • ateixeira
    ateixeira Member Posts: 19
    edited Feb 2, 2018 3:50AM Answer ✓

    Hello,

    And what about your java attribute types are the same as coming from the xml text?

    Regards,

    AT

  • managed BEAN
    managed BEAN Member Posts: 948 Silver Badge
    edited Feb 3, 2018 5:08PM

    Hi,

    Thanks, there was a problem with with one attribute type which was timestamp and i was converting to date.

    But the problem raised when i was having more than 20.000 results, do not know why it worked when i had less?!?!?

    Problem fixed.

    Thanks

    Carlos

This discussion has been closed.