1

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>
Michi-2142
  • 1,170
  • 3
  • 18
  • 39
  • What features do you have enabled? And what version of Open Liberty are you running? Not sure it matters, but how are you getting to your code (E.g. is it a JAX-WS type of invocation? JAX-RS , etc.)? – Scott Kurz Jun 15 '21 at 13:32
  • @ScottKurz I've updated my question regarding OpenLiberty specs – Michi-2142 Jun 21 '21 at 12:44
  • jaxws-2.2 uses jaxb-2.2 as a dependency so you might try switching your maven dependency to 2.2.12. Not sure if that will have an effect, but its worth keeping them aligned I think. – Thomas Johnson Jun 21 '21 at 18:22

0 Answers0