Jaxb2Marshaller's "marshallerProperties" Map accepts any value type (SPR-7292)
This commit is contained in:
parent
91560774a0
commit
5e5a8a09cf
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.oxm.jaxb;
|
package org.springframework.oxm.jaxb;
|
||||||
|
|
||||||
import java.awt.Image;
|
import java.awt.*;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
@ -132,9 +132,9 @@ public class Jaxb2Marshaller
|
||||||
|
|
||||||
private Map<String, ?> jaxbContextProperties;
|
private Map<String, ?> jaxbContextProperties;
|
||||||
|
|
||||||
private Map<String, Object> marshallerProperties;
|
private Map<String, ?> marshallerProperties;
|
||||||
|
|
||||||
private Map<String, Object> unmarshallerProperties;
|
private Map<String, ?> unmarshallerProperties;
|
||||||
|
|
||||||
private Marshaller.Listener marshallerListener;
|
private Marshaller.Listener marshallerListener;
|
||||||
|
|
||||||
|
|
@ -158,20 +158,6 @@ public class Jaxb2Marshaller
|
||||||
|
|
||||||
private boolean lazyInit = false;
|
private boolean lazyInit = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the JAXB context path.
|
|
||||||
*/
|
|
||||||
public String getContextPath() {
|
|
||||||
return contextPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a JAXB context path.
|
|
||||||
*/
|
|
||||||
public void setContextPath(String contextPath) {
|
|
||||||
Assert.hasText(contextPath, "'contextPath' must not be null");
|
|
||||||
this.contextPath = contextPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set multiple JAXB context paths. The given array of context paths is converted to a
|
* Set multiple JAXB context paths. The given array of context paths is converted to a
|
||||||
|
|
@ -183,10 +169,18 @@ public class Jaxb2Marshaller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of Java classes to be recognized by a newly created JAXBContext.
|
* Set a JAXB context path.
|
||||||
*/
|
*/
|
||||||
public Class<?>[] getClassesToBeBound() {
|
public void setContextPath(String contextPath) {
|
||||||
return classesToBeBound;
|
Assert.hasText(contextPath, "'contextPath' must not be null");
|
||||||
|
this.contextPath = contextPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the JAXB context path.
|
||||||
|
*/
|
||||||
|
public String getContextPath() {
|
||||||
|
return this.contextPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -198,6 +192,13 @@ public class Jaxb2Marshaller
|
||||||
this.classesToBeBound = classesToBeBound;
|
this.classesToBeBound = classesToBeBound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the list of Java classes to be recognized by a newly created JAXBContext.
|
||||||
|
*/
|
||||||
|
public Class<?>[] getClassesToBeBound() {
|
||||||
|
return this.classesToBeBound;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the <code>JAXBContext</code> properties. These implementation-specific
|
* Set the <code>JAXBContext</code> properties. These implementation-specific
|
||||||
* properties will be set on the underlying <code>JAXBContext</code>.
|
* properties will be set on the underlying <code>JAXBContext</code>.
|
||||||
|
|
@ -216,7 +217,7 @@ public class Jaxb2Marshaller
|
||||||
* @see javax.xml.bind.Marshaller#JAXB_NO_NAMESPACE_SCHEMA_LOCATION
|
* @see javax.xml.bind.Marshaller#JAXB_NO_NAMESPACE_SCHEMA_LOCATION
|
||||||
* @see javax.xml.bind.Marshaller#JAXB_SCHEMA_LOCATION
|
* @see javax.xml.bind.Marshaller#JAXB_SCHEMA_LOCATION
|
||||||
*/
|
*/
|
||||||
public void setMarshallerProperties(Map<String, Object> properties) {
|
public void setMarshallerProperties(Map<String, ?> properties) {
|
||||||
this.marshallerProperties = properties;
|
this.marshallerProperties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -226,7 +227,7 @@ public class Jaxb2Marshaller
|
||||||
* @param properties the properties
|
* @param properties the properties
|
||||||
* @see javax.xml.bind.Unmarshaller#setProperty(String,Object)
|
* @see javax.xml.bind.Unmarshaller#setProperty(String,Object)
|
||||||
*/
|
*/
|
||||||
public void setUnmarshallerProperties(Map<String, Object> properties) {
|
public void setUnmarshallerProperties(Map<String, ?> properties) {
|
||||||
this.unmarshallerProperties = properties;
|
this.unmarshallerProperties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -293,16 +294,13 @@ public class Jaxb2Marshaller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether to lazily initialize the {@link JAXBContext} for this marshaller.
|
* Set whether to lazily initialize the {@link JAXBContext} for this marshaller.
|
||||||
* Default is {@code false} to initialize on startup; can be switched to
|
* Default is {@code false} to initialize on startup; can be switched to {@code true}.
|
||||||
* {@code true}.
|
* <p>Early initialization just applies if {@link #afterPropertiesSet()} is called.
|
||||||
* <p>Early initialization just applies if <code>afterPropertiesSet()</code> is called.
|
|
||||||
* @see #afterPropertiesSet()
|
|
||||||
*/
|
*/
|
||||||
public void setLazyInit(boolean lazyInit) {
|
public void setLazyInit(boolean lazyInit) {
|
||||||
this.lazyInit = lazyInit;
|
this.lazyInit = lazyInit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||||
this.beanClassLoader = classLoader;
|
this.beanClassLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
|
@ -315,7 +313,7 @@ public class Jaxb2Marshaller
|
||||||
else if (!StringUtils.hasLength(getContextPath()) && ObjectUtils.isEmpty(getClassesToBeBound())) {
|
else if (!StringUtils.hasLength(getContextPath()) && ObjectUtils.isEmpty(getClassesToBeBound())) {
|
||||||
throw new IllegalArgumentException("Setting either 'contextPath' or 'classesToBeBound' is required");
|
throw new IllegalArgumentException("Setting either 'contextPath' or 'classesToBeBound' is required");
|
||||||
}
|
}
|
||||||
if (!lazyInit) {
|
if (!this.lazyInit) {
|
||||||
getJaxbContext();
|
getJaxbContext();
|
||||||
}
|
}
|
||||||
if (!ObjectUtils.isEmpty(this.schemaResources)) {
|
if (!ObjectUtils.isEmpty(this.schemaResources)) {
|
||||||
|
|
@ -407,16 +405,16 @@ public class Jaxb2Marshaller
|
||||||
Type typeArgument = parameterizedType.getActualTypeArguments()[0];
|
Type typeArgument = parameterizedType.getActualTypeArguments()[0];
|
||||||
if (typeArgument instanceof Class) {
|
if (typeArgument instanceof Class) {
|
||||||
Class<?> classArgument = (Class<?>) typeArgument;
|
Class<?> classArgument = (Class<?>) typeArgument;
|
||||||
if (isPrimitiveWrapper(classArgument) || isStandardClass(classArgument)) {
|
return (isPrimitiveWrapper(classArgument) || isStandardClass(classArgument) ||
|
||||||
return true;
|
supportsInternal(classArgument, false));
|
||||||
}
|
}
|
||||||
return supportsInternal(classArgument, false);
|
else if (typeArgument instanceof GenericArrayType) {
|
||||||
} else if (typeArgument instanceof GenericArrayType) {
|
|
||||||
GenericArrayType arrayType = (GenericArrayType) typeArgument;
|
GenericArrayType arrayType = (GenericArrayType) typeArgument;
|
||||||
return arrayType.getGenericComponentType().equals(Byte.TYPE);
|
return arrayType.getGenericComponentType().equals(Byte.TYPE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (genericType instanceof Class) {
|
}
|
||||||
|
else if (genericType instanceof Class) {
|
||||||
Class<?> clazz = (Class<?>) genericType;
|
Class<?> clazz = (Class<?>) genericType;
|
||||||
return supportsInternal(clazz, true);
|
return supportsInternal(clazz, true);
|
||||||
}
|
}
|
||||||
|
|
@ -445,8 +443,7 @@ public class Jaxb2Marshaller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the given type is a primitive wrapper type.
|
* Checks whether the given type is a primitive wrapper type.
|
||||||
*
|
* Compare section 8.5.1 of the JAXB2 spec.
|
||||||
* @see section 8.5.1 of the JAXB2 spec
|
|
||||||
*/
|
*/
|
||||||
private boolean isPrimitiveWrapper(Class<?> clazz) {
|
private boolean isPrimitiveWrapper(Class<?> clazz) {
|
||||||
return Boolean.class.equals(clazz) ||
|
return Boolean.class.equals(clazz) ||
|
||||||
|
|
@ -460,8 +457,7 @@ public class Jaxb2Marshaller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the given type is a standard class.
|
* Checks whether the given type is a standard class.
|
||||||
|
* Compare section 8.5.2 of the JAXB2 spec.
|
||||||
* @see section 8.5.2 of the JAXB2 spec
|
|
||||||
*/
|
*/
|
||||||
private boolean isStandardClass(Class<?> clazz) {
|
private boolean isStandardClass(Class<?> clazz) {
|
||||||
return String.class.equals(clazz) ||
|
return String.class.equals(clazz) ||
|
||||||
|
|
@ -673,6 +669,7 @@ public class Jaxb2Marshaller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class Jaxb2AttachmentMarshaller extends AttachmentMarshaller {
|
private static class Jaxb2AttachmentMarshaller extends AttachmentMarshaller {
|
||||||
|
|
||||||
private final MimeContainer mimeContainer;
|
private final MimeContainer mimeContainer;
|
||||||
|
|
@ -806,4 +803,3 @@ public class Jaxb2Marshaller
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue