You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.
JAXBContext.newInstance(Class<?>) throws "JAXBException: Package java.lang with JAXB class xxx defined in a module java.base must be open to at least java.xml.bind module" if the class is in java.lang package
#1184
Open
LanceAndersen opened this issue
Apr 20, 2018
· 1 comment
public static void main(String[] args) throws Exception {
// marshal
int[] x = new int[]{1,5,2,3,4};
JAXBElement<int[]> xe = new JAXBElement<int[]>(new QName("", "root"), int[].class, JAXBElement.GlobalScope.class, x);
Marshaller m = JAXBContext.newInstance(int[].class).createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
m.marshal(xe,System.out);
// unmarshal
Unmarshaller u = JAXBContext.newInstance(int[].class).createUnmarshaller();
JAXBElement e = u.unmarshal(new StreamSource(new StringReader(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" +
"<root>\n" +
" <item>1</item>\n" +
" <item>5</item>\n" +
" <item>2</item>\n" +
" <item>3</item>\n" +
" <item>4</item>\n" +
"</root>\n")), int[].class);
}
}
Exception in thread "main" javax.xml.bind.JAXBException: Package java.lang with JAXB class [I defined in a module java.base must be open to at least java.xml.bind module.
at java.xml.bind@9/javax.xml.bind.ModuleUtil.delegateAddOpensToImplModule(ModuleUtil.java:148)
at java.xml.bind@9/javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:285)
at java.xml.bind@9/javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:270)
at java.xml.bind@9/javax.xml.bind.ContextFinder.find(ContextFinder.java:407)
at java.xml.bind@9/javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:706)
at java.xml.bind@9/javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:647)
at TestJAXB.main(TestJAXB.java:16)
Please note, the exception is thrown in JAXBContext.newInstance(int[].class), other code is just to show a whole example.
The text was updated successfully, but these errors were encountered:
Previously tracked via: https://bugs.openjdk.java.net/browse/JDK-8184726
Run the following java program:
import java.io.StringReader;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;
import javax.xml.transform.stream.StreamSource;
public class TestJAXB {
}
Exception in thread "main" javax.xml.bind.JAXBException: Package java.lang with JAXB class [I defined in a module java.base must be open to at least java.xml.bind module.
at java.xml.bind@9/javax.xml.bind.ModuleUtil.delegateAddOpensToImplModule(ModuleUtil.java:148)
at java.xml.bind@9/javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:285)
at java.xml.bind@9/javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:270)
at java.xml.bind@9/javax.xml.bind.ContextFinder.find(ContextFinder.java:407)
at java.xml.bind@9/javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:706)
at java.xml.bind@9/javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:647)
at TestJAXB.main(TestJAXB.java:16)
Please note, the exception is thrown in JAXBContext.newInstance(int[].class), other code is just to show a whole example.
The text was updated successfully, but these errors were encountered: