jakartaee / jakartaee/jaxb-api

JAXBResult cannot be initialized with target type

Open
#252 5 comments 0 reactions 1 assignee Claimed by @glassfishrobot View on GitHub
enhancement Major
Dominant language
Java
Stars
79
Forks
48
Avg merge
7h 12m
Merged PRs (30d)
2

Description

If I want to unmarshal an XML document on to a class that doesn't have the
@XmlRootElement annotation, then I can use unmarshaller.unmarshal(source, Class)
to tell it which type to bind to, and it'll return me a JAXBElement for that type.

However, if I want to use JAXBResult to pipe a transform on to the same type, I
have no such option. JAXBResult gets a UnmarshallerHandler from the
Unmarshaller, but there's no mechanism for passing in the target type. And so,
JAXBResult can only target @XmlRootElement-annotated clases, which severely
limits its usefulness.

WOuld it be possible to have JAXBResult modified so that I can construct it with
a JAXBContext, plus a target type?

JAXBResult result = new JAXBResult(context, MyClass.class);
// perform transform on to result
JAXBElement output = result.getResult();
#### Environment
Operating System: All
Platform: All
#### Affected Versions
[2.1.12]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.