Support canEncode() for JAXBElement in Jaxb2XmlEncoder

Commit d7970e4ab8 introduced support for JAXBElement in
Jaxb2XmlEncoder's encodeValue() method; however, canEncode() still
returned false for a JAXBElement element type.

This commit revises canEncode() so that it returns true for an element
type that is assignable from JAXBElement.

See gh-30552
See gh-32972
Closes gh-32977
This commit is contained in:
Thomas Deblock
2024-06-07 09:25:11 +02:00
committed by Sam Brannen
parent 43a113f067
commit 47a5ebfde6
2 changed files with 5 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -92,7 +92,8 @@ public class Jaxb2XmlEncoder extends AbstractSingleValueEncoder<Object> {
if (super.canEncode(elementType, mimeType)) {
Class<?> outputClass = elementType.toClass();
return (outputClass.isAnnotationPresent(XmlRootElement.class) ||
outputClass.isAnnotationPresent(XmlType.class));
outputClass.isAnnotationPresent(XmlType.class) ||
elementType.isAssignableFrom(JAXBElement.class));
}
else {
return false;