diff --git a/jaxb-ri/core/src/main/java/com/sun/xml/bind/v2/ClassFactory.java b/jaxb-ri/core/src/main/java/com/sun/xml/bind/v2/ClassFactory.java index 36641d7..b2b7c61 100644 --- a/jaxb-ri/core/src/main/java/com/sun/xml/bind/v2/ClassFactory.java +++ b/jaxb-ri/core/src/main/java/com/sun/xml/bind/v2/ClassFactory.java @@ -169,9 +169,21 @@ * Call a method in the factory class to get the object. */ public static Object create(Method method) { - Throwable errorMsg; - try { - return method.invoke(null, emptyObject); + return create(method, Object.class); + } + + /** + * Call a method in the factory class to get the object. + */ + @SuppressWarnings("unchecked") + public static T create(Method method, Class jaxbType) { + Throwable errorMsg; + try { + if (method.getParameterTypes().length == 1) { + return (T) method.invoke(null, jaxbType); + } else { + return (T) method.invoke(null, emptyObject); + } } catch (InvocationTargetException ive) { Throwable target = ive.getTargetException(); diff --git a/jaxb-ri/runtime/impl/src/main/java/com/sun/xml/bind/v2/model/impl/ClassInfoImpl.java b/jaxb-ri/runtime/impl/src/main/java/com/sun/xml/bind/v2/model/impl/ClassInfoImpl.java index 7b092a5..be98fd9 100644 --- a/jaxb-ri/runtime/impl/src/main/java/com/sun/xml/bind/v2/model/impl/ClassInfoImpl.java +++ b/jaxb-ri/runtime/impl/src/main/java/com/sun/xml/bind/v2/model/impl/ClassInfoImpl.java @@ -42,6 +42,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import java.lang.reflect.ParameterizedType; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -1302,14 +1303,22 @@ fClass = nav().use(clazz); } for(M m: nav().getDeclaredMethods(nav().asDecl(fClass))){ - //- Find the zero-arg public static method with the required return type - if (nav().getMethodName(m).equals(method) && - nav().isSameType(nav().getReturnType(m), nav().use(clazz)) && - nav().getMethodParameters(m).length == 0 && - nav().isStaticMethod(m)){ - factoryMethod = m; - break; + //- Find the zero-arg public static method with the required (or Object) return type + // or one-arg (Class) public static method with the required (or Object) return type + if (nav().getMethodName(m).equals(method) && + (nav().isSameType(nav().getReturnType(m), nav().use(clazz)) || + nav().asDecl(nav().getReturnType(m)).equals(Object.class)) && + nav().isStaticMethod(m)) { + + T[] mParams = nav().getMethodParameters(m); + if (mParams.length == 0 || + (mParams.length == 1 && + nav().isParameterizedType(mParams[0]) && + ((ParameterizedType) mParams[0]).getRawType().equals(Class.class))) { + factoryMethod = m; + break; } + } } if (factoryMethod == null){ builder.reportError(new IllegalAnnotationException( diff --git a/jaxb-ri/runtime/impl/src/main/java/com/sun/xml/bind/v2/runtime/ClassBeanInfoImpl.java b/jaxb-ri/runtime/impl/src/main/java/com/sun/xml/bind/v2/runtime/ClassBeanInfoImpl.java index 50c3d60..4fe7753 100644 --- a/jaxb-ri/runtime/impl/src/main/java/com/sun/xml/bind/v2/runtime/ClassBeanInfoImpl.java +++ b/jaxb-ri/runtime/impl/src/main/java/com/sun/xml/bind/v2/runtime/ClassBeanInfoImpl.java @@ -285,7 +285,7 @@ if (factoryMethod == null){ bean = ClassFactory.create0(jaxbType); }else { - Object o = ClassFactory.create(factoryMethod); + Object o = ClassFactory.create(factoryMethod, jaxbType); if( jaxbType.isInstance(o) ){ bean = (BeanT)o; } else {