Title: [2126] trunk: Implicit type argument can be omitted when registering converters with @XStreamConverter annotation.
Revision
2126
Author
joehni
Date
2013-09-24 19:21:11 -0500 (Tue, 24 Sep 2013)

Log Message

Implicit type argument can be omitted when registering converters with @XStreamConverter annotation.

Modified Paths

Diff

Modified: trunk/xstream/src/java/com/thoughtworks/xstream/annotations/XStreamConverter.java (2125 => 2126)


--- trunk/xstream/src/java/com/thoughtworks/xstream/annotations/XStreamConverter.java	2013-09-25 00:12:01 UTC (rev 2125)
+++ trunk/xstream/src/java/com/thoughtworks/xstream/annotations/XStreamConverter.java	2013-09-25 00:21:11 UTC (rev 2126)
@@ -38,7 +38,8 @@
  * type.</li>
  * <li>{@link Class}: The type of the element where the annotation is declared. Note, that this
  * argument is not supported when using
- * {@link com.thoughtworks.xstream.annotations.XStreamConverters}.</li>
+ * {@link com.thoughtworks.xstream.annotations.XStreamConverters} or {@link #useImplicitType()}
+ * == false.</li>
  * </ul>
  * <li>{@link com.thoughtworks.xstream.core.JVM}: Utility e.g. to load classes.</li> <li>
  * {@link ClassLoader} (deprecated since upcoming): The class loader used by the XStream
@@ -62,26 +63,47 @@
 @Documented
 public @interface XStreamConverter {
     Class<? extends ConverterMatcher> value();
+
     int priority() default XStream.PRIORITY_NORMAL;
+
     /**
+     * Flag to provide the current type as implicit first Class argument to a converter's
+     * constructor.
+     * 
+     * @return true if the current type is provided
+     * @since upcoming
+     */
+    boolean useImplicitType() default true;
+
+    /**
      * Provide class types as arguments for the converter's constructor arguments.
-     * 
-     * <p>Note, that XStream itself provides the current class type as first Class argument to
-     * a constructor, if the annotation is added directly to a class type (and not as part of a
+     * <p>
+     * Note, that XStream itself provides the current class type as first Class argument to a
+     * constructor, if the annotation is added directly to a class type (and not as part of a
      * parameter declaration of a {@link XStreamConverters} annotation). The current type has
-     * precedence over any type provided with this method.
+     * precedence over any type provided with this method. This behavior can be overridden
+     * setting {@link #useImplicitType()} to false.
      * 
      * @return the types
      * @since 1.4.2
      */
     Class<?>[] types() default {};
+
     String[] strings() default {};
+
     byte[] bytes() default {};
+
     char[] chars() default {};
+
     short[] shorts() default {};
+
     int[] ints() default {};
+
     long[] longs() default {};
+
     float[] floats() default {};
+
     double[] doubles() default {};
+
     boolean[] booleans() default {};
 }

Modified: trunk/xstream/src/java/com/thoughtworks/xstream/mapper/AnnotationMapper.java (2125 => 2126)


--- trunk/xstream/src/java/com/thoughtworks/xstream/mapper/AnnotationMapper.java	2013-09-25 00:12:01 UTC (rev 2125)
+++ trunk/xstream/src/java/com/thoughtworks/xstream/mapper/AnnotationMapper.java	2013-09-25 00:21:11 UTC (rev 2126)
@@ -487,7 +487,7 @@
         Converter result = null;
         final Object[] args;
         final List<Object> parameter = new ArrayList<Object>();
-        if (targetType != null) {
+        if (targetType != null && annotation.useImplicitType()) {
             parameter.add(targetType);
         }
         final List<Object> arrays = new ArrayList<Object>();

Modified: trunk/xstream-distribution/src/content/changes.html (2125 => 2126)


--- trunk/xstream-distribution/src/content/changes.html	2013-09-25 00:12:01 UTC (rev 2125)
+++ trunk/xstream-distribution/src/content/changes.html	2013-09-25 00:21:11 UTC (rev 2126)
@@ -86,6 +86,7 @@
     	<li>JIRA:XSTR-742: Register CompositeClassLoader in Java 7 as parallel capable.</li>
     	<li>JIRA:XSTR-743: Support proxy collections of Hibernate Envers.</li>
     	<li>Fix NPE in AttributeMapper.shouldLookForSingleValueConverter if parameters fieldName and definedIn are null.</li>
+    	<li>Implicit type argument can be omitted when registering converters with @XStreamConverter annotation.</li>
     </ul>
 
     <h2>API changes</h2>
@@ -114,6 +115,7 @@
     	<li>Added static methods newReflectionProvider, isAWTAvailable, isSQLAvailable and isSwingAvailable to
     	c.t.x.core.JVM as replacement for the deprecated non-static methods.</li>
     	<li>Deprecated c.t.x.core.JVM() and all non-static methods.</li>
+    	<li>Added method useImplicitType to c.t.x.annotations.XStreamConverter.</li>
     	<li>JIRA:XSTR-722: Added 
     	c.t.x.converters.reflection.ReflectionProvider.getFieldOrNull(Class, String).</li>
     	<li>Deprecated 

To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email

Reply via email to