Stefan Bischof created FELIX-6020:
-------------------------------------
Summary: Converter could not convert to Interfaces, which only has
methods from inherited Interfaces
Key: FELIX-6020
URL: https://issues.apache.org/jira/browse/FELIX-6020
Project: Felix
Issue Type: Bug
Components: Converter
Affects Versions: converter-1.0.2
Reporter: Stefan Bischof
Hi,
the Converter could not convert to an Interfaces, when the Interface only has
methods from inherited other Interfaces.
Here is a TestCase:
{code:java}
import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.osgi.util.converter.Converter;
import org.osgi.util.converter.Converters;
public class ConvTest {
interface InterfaceFoo {
String foo();
}
interface InterfaceFooBar extends InterfaceFoo {
String bar();
}
interface InterfaceFooNon extends InterfaceFoo {
// Empty
}
private static final String fooValue = "foofoo";
private static final String barValue = "barbar";
final Converter converter = Converters.standardConverter();
@Test
public void testFooPure() throws Exception {
final Map<String, Object> map = new HashMap<String, Object>();
map.put("foo", fooValue);
final InterfaceFoo iFoo = converter.convert(map).to(InterfaceFoo.class);
assertEquals(fooValue, iFoo.foo());
}
@Test
public void testFooBar() throws Exception {
final Map<String, Object> map = new HashMap<String, Object>();
map.put("foo", fooValue);
map.put("bar", barValue);
final InterfaceFooBar iFooBar =
converter.convert(map).to(InterfaceFooBar.class);
assertEquals(fooValue, iFooBar.foo());
assertEquals(barValue, iFooBar.bar());
}
@Test
public void testFooNon() throws Exception {
final Map<String, Object> map = new HashMap<String, Object>();
map.put("foo", fooValue);
final InterfaceFooNon iFooNon =
converter.convert(map).to(InterfaceFooNon.class);
assertEquals(fooValue, iFooNon.foo());
}
}{code}
Stacktrace
{code:java}
org.osgi.util.converter.ConversionException: Cannot convert foo to interface
de.jena.servicehub.doc.latex.itest.ConvTest$InterfaceFooNon
at org.osgi.util.converter.ConvertingImpl.to(ConvertingImpl.java:212)
at
org.osgi.util.converter.CustomConverterImpl$ConvertingWrapper.to(CustomConverterImpl.java:176)
at
org.osgi.util.converter.CustomConverterImpl$ConvertingWrapper.to(CustomConverterImpl.java:139)
at
org.osgi.util.converter.ConvertingImpl.convertMapEntryToSingleValue(ConvertingImpl.java:260)
at org.osgi.util.converter.ConvertingImpl.to(ConvertingImpl.java:197)
at
org.osgi.util.converter.CustomConverterImpl$ConvertingWrapper.to(CustomConverterImpl.java:176)
at
org.osgi.util.converter.CustomConverterImpl$ConvertingWrapper.to(CustomConverterImpl.java:139)
at
org.osgi.util.converter.ConvertingImpl.convertMapToSingleValue(ConvertingImpl.java:236)
at org.osgi.util.converter.ConvertingImpl.to(ConvertingImpl.java:195)
at
org.osgi.util.converter.CustomConverterImpl$ConvertingWrapper.to(CustomConverterImpl.java:176)
at
org.osgi.util.converter.CustomConverterImpl$ConvertingWrapper.to(CustomConverterImpl.java:139)
{code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)