Failed to set MinumEscapeHandler to jaxb marshaller

55 views Asked by At

Please do not block the post due to the fact that a similar solution already exists on this site. Using the following java code, which is a REST service that returns xml, when I request the service itself, I get an error, although the code still fully working. The solutions say that you need to add a property javax.xml.bind.context.factory=com.sun.xml.bind.v2.ContextFactory, but the problem is that I can't find a dependency anywhere that contains com.sun.xml.bind.v2.ContextFactory, so the problem still remains unresolved. Maybe it's just a bug and I shouldn't pay attention? I use Tomee plume 9.1.0.

code, that throwing exception:

@Path("/rs")
public class HelloWorld {
    @GET
    @Path("/sayHello")
    @Produces(MediaType.APPLICATION_XML)
    public Student sayHello() {
        return new Student("Peter");
    }
}

@XmlRootElement
class Student {
    int id;
    String name;
    public Student() {}
    public Student(String name) {
        this.name = name;
    }
    public int getId() {
        return id;
    }
    @XmlAttribute
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    @XmlElement
    public void setName(String name) {
        this.name = name;
    }
}

error code:

06-Jan-2024 22:25:19.420 INFO [http-nio-8080-exec-8] org.apache.cxf.common.jaxb.JAXBUtils.setEscapeHandler Failed to set MinumEscapeHandler to jaxb marshaller
    jakarta.xml.bind.PropertyException: name: com.sun.xml.bind.characterEscapeHandler value: null
        at jakarta.xml.bind.helpers.AbstractMarshallerImpl.setProperty(AbstractMarshallerImpl.java:343)
        at org.glassfish.jaxb.runtime.v2.runtime.MarshallerImpl.setProperty(MarshallerImpl.java:499)
        at org.apache.cxf.common.jaxb.JAXBUtils.setEscapeHandler(JAXBUtils.java:1135)
        at org.apache.cxf.common.jaxb.JAXBUtils.lambda$setMinimumEscapeHandler$0(JAXBUtils.java:1121)
        at java.base/java.util.Optional.ifPresent(Optional.java:178)
        at org.apache.cxf.common.jaxb.JAXBUtils.setMinimumEscapeHandler(JAXBUtils.java:1121)
        at org.apache.cxf.jaxrs.provider.JAXBElementProvider.marshalToOutputStream(JAXBElementProvider.java:610)
        at org.apache.cxf.jaxrs.provider.JAXBElementProvider.marshal(JAXBElementProvider.java:576)
        at org.apache.cxf.jaxrs.provider.JAXBElementProvider.marshal(JAXBElementProvider.java:441)
        at org.apache.cxf.jaxrs.provider.JAXBElementProvider.writeTo(JAXBElementProvider.java:317)
        at org.apache.cxf.jaxrs.utils.JAXRSUtils.writeMessageBody(JAXRSUtils.java:1651)
        at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:249)
        at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.processResponse(JAXRSOutInterceptor.java:122)
        at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRSOutInterceptor.java:84)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
        at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:90)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
        at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:265)
0

There are 0 answers