I would like to deserialize a simple xml string to an object using the javax.xml.bind.Unmarshaller in an java EE application running in open-liberty. I have following method to deserialize:
Deserialize
package com.my.deserializer;
public class XmlDeserializer {
private static Name deserialize() {
try {
JAXBContext jaxbContext = JAXBContext.newInstance(Name.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StringReader reader = new StringReader("<Name xml:lang=\"en\">Acme, Inc.</Name>");
Name cXml = (Name) unmarshaller.unmarshal(reader);
return cXml;
} catch (JAXBException e) {
e1.printStackTrace();
}
return null;
}
}
Class
package com.my.model;
@XmlRootElement(name = "Name")
public class Name implements Serializable {
private static final long serialVersionUID = -4018453444627994825L;
@XmlAttribute(name = "lang", namespace = "xml")
public String lang;
@XmlValue
public String text;
}
When I call XmlDeserializer.deserialize()
, I get following exception:
java.lang.IllegalAccessError: tried to access class com.my.model.Name from class com.my.deserializer.XmlDeserializer
I only can get this code working if I change class name from Name
to any other name e.x. Name_Entity
. Is there anything wrong with my code?
System specs
- Windows 10 x64
- Eclipse 2020-06
- Java SE-1.8
- Maven Dependency:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
OpenLiberty (v. 20.0.0.9)
Feautures:
<feature>webProfile-8.0</feature>
<feature>mpJwt-1.1</feature>
<feature>localConnector-1.0</feature>
<feature>mpHealth-2.2</feature>
<feature>jaxws-2.2</feature>