Issue Details (XML | Word | Printable)

Key: XSTR-461
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Joerg Schaible
Reporter: Cheong, Chung-Onn
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XStream

Processing annotation for MapConverter broken

Created: 01/Jan/08 08:43 PM   Updated: 25/Feb/08 05:02 PM
Component/s: Annotations, Converters
Affects Version/s: Upcoming
Fix Version/s: 1.3

File Attachments: 1. Text File MapConverterPatch.txt (2 kB)


JDK version and platform: Ubuntu Linux 7.10, Java version 1.6.0_03


 Description  « Hide
I get an InitilizationException when i try to process an annotation for a MapConverter subclass. Below is output of my testcast.

com.thoughtworks.xstream.InitializationException: Cannot instantiate converter com.thoughtworks.acceptance.annotations.MapConverterTest$MyMapConverter : Cannot construct com.thoughtworks.acceptance.annotations.MapConverterTest$MyMapConverter, none of the dependencies match any constructor's parameters
at com.thoughtworks.xstream.mapper.AnnotationMapper.cacheConverter(AnnotationMapper.java:431)
at com.thoughtworks.xstream.mapper.AnnotationMapper.processConverterAnnotations(AnnotationMapper.java:264)
at com.thoughtworks.xstream.mapper.AnnotationMapper.processTypes(AnnotationMapper.java:162)
at com.thoughtworks.xstream.mapper.AnnotationMapper.processAnnotations(AnnotationMapper.java:134)
at com.thoughtworks.xstream.XStream.processAnnotations(XStream.java:1440)
at com.thoughtworks.xstream.XStream.processAnnotations(XStream.java:1451)
at com.thoughtworks.acceptance.annotations.MapConverterTest.setUp(MapConverterTest.java:42)

Below is a new testcase for the above reported problem

Index:
/home/chungonn/development/projects/xstream-trunk/xstream/src/test/com/thoughtworks/acceptance/annotations/MapConverterTest.java
===================================================================

/home/chungonn/development/projects/xstream-trunk/xstream/src/test/com/thoughtworks/acceptance/annotations/MapConverterTest.java
(revision 0)
+++
/home/chungonn/development/projects/xstream-trunk/xstream/src/test/com/thoughtworks/acceptance/annotations/MapConverterTest.java
(revision 0)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2006 Joe Walnes.
+ * Copyright (C) 2006, 2007 XStream Committers.
+ * All rights reserved.
+ *
+ * The software in this package is published under the terms of the BSD
+ * style license a copy of which has been included with this distribution in
+ * the LICENSE.txt file.
+ *
+ * Created on 02. March 2006 by Mauro Talevi
+ */
+package com.thoughtworks.acceptance.annotations;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import com.thoughtworks.acceptance.AbstractAcceptanceTest;
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.annotations.XStreamConverter;
+import com.thoughtworks.xstream.annotations.XStreamConverters;
+import com.thoughtworks.xstream.converters.collections.MapConverter;
+import com.thoughtworks.xstream.mapper.Mapper;
+
+
+/**
+ * Tests for using annotations to map converter
+ *
+ * @author Chung-Onn, Cheong
+ */
+public class MapConverterTest extends AbstractAcceptanceTest {
+ + @Override
+ protected XStream createXStream() { + XStream xstream = super.createXStream(); + xstream.autodetectAnnotations(true); + return xstream; + }
+
+ protected void setUp() throws Exception { + super.setUp(); + xstream.alias("my-map", MyMap.class); + xstream.processAnnotations(MyMap.class); + }
+
+ public void testAnnotationForForFieldsOfSameType() { + final MyMap aMap = new MyMap(); + aMap.put("key1", "value1"); + + }
+
+ @XStreamConverters({@XStreamConverter(MyMapConverter.class)})
+ public class MyMap extends HashMap<String, Object> { + + }
+ + public class MyMapConverter extends MapConverter {
+
+ public MyMapConverter(Mapper classMapper) { + super(classMapper); + }
+ + public boolean canConvert(Class type) { + return type.equals(Map.class); + }
+
+ }
+}



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Cheong, Chung-Onn added a comment - 02/Jan/08 08:39 AM
TestCase for MapConverter

Joerg Schaible added a comment - 03/Jan/08 06:34 PM
The old annotation code had special support for converters taking a Mapper as ctor argument. This was no longer available. I missed this functionality, since it was not covered by a unit test. XStream still does not support arbitrary parameters, but a converter may now request a Mapper, ReflectionProvider, ClassLoader or JVM as ctor dependency.

You may give it a try (note, you have to fix your unit test also <g>).

  • Jörg

Joerg Schaible added a comment - 25/Feb/08 05:02 PM
Closing issues before next release.