Hi Cristiano,

Yes, you have identified a bug - please open an issue for it. I'll work on
a fix.

Best regards,

David

On Thu, 20 Dec 2018 at 12:55, Cristiano <[email protected]> wrote:

> Hi David, many thanks for the insight. It is a very interesting
> approach, ideed.
>
> I just tried with errorHandler() now. I've took the tests from Felix
> Converter and use my own converter instance and it worked for DTO,
> javabeans and other common cases.
>
> But unfortunately, the current implementation of Felix Converter is not
> calling this method when dealing with the Interface's created Proxy.
>
> The code bellow was taken from the invoke(Object proxy, Method method,
> Object[] args) method:
>
> >                 // If no value is available take the default if specified
> >                 if (val == null) {
> >                     if (cls.isAnnotation()) {
> >                         val = method.getDefaultValue();
> >                     }
> >
> >                     if (val == null) {
> >                         if (args != null && args.length == 1) {
> >                             val = args[0];
> >                         } else {
> >                             throw new ConversionException(
> >                                     "No value for property: " +
> propName);
> >                         }
> >                     }
> >                 }
>
> As you can see, the ConversionException is being thrown and it is not
> captured by the CustomConverterImpl class as it does in other situations.
>
>
> Should I open an issue for that ?
>
> best regards
>
>
> On 20/12/2018 08:35, David Bosschaert wrote:
> > Hi Cristiano,
> >
> > You should be able to do this with a custom errorHandler() [1].
> > For that you'd create a custom converter and supply it with an
> errorHandler
> > function. See also [2] and [3].
> >
> > Hope this helps,
> >
> > David
> >
> > [1]
> >
> https://osgi.org/javadoc/osgi.cmpn/7.0.0/org/osgi/util/converter/ConverterBuilder.html#errorHandler-org.osgi.util.converter.ConverterFunction-
> > [2]
> >
> https://osgi.org/specification/osgi.cmpn/7.0.0/util.converter.html#util.converter-customizing.converters
> > [3]
> >
> https://osgi.org/specification/osgi.cmpn/7.0.0/util.converter.html#d0e147674
> >
> > On Wed, 19 Dec 2018 at 20:51, Cristiano <[email protected]> wrote:
> >
> >> Hello all,
> >>
> >> I'm using Converter to convert a JsonObject (a Map) to an Interface.
> >>
> >> I've created this test for a scenario where any bundle is informed:
> >>
> >>>          IProvisioningConfiguration config = CONVERTER.convert(json)
> >>>                  .to(IProvisioningConfiguration.class);
> >>>
> >>>          assertThat(config).isNotNull();
> >>>          assertThat(config.delay()).isEqualTo(5);
> >>>          assertThat(config.bundles()).isEmpty();
> >> My problem is that I'm receiving a ConversionException when trying to
> >> access a method from the interface which value was not supplied by the
> >> source object map.
> >>
> >>> org.osgi.util.converter.ConversionException: No value for property:
> >>> bundles
> >>>      at
> >>>
> org.osgi.util.converter.ConvertingImpl$4.invoke(ConvertingImpl.java:802)
> >>>      at com.sun.proxy.$Proxy8.bundles(Unknown Source)
> >>>      at
> >>>
> >>
> br.com.c8tech.vxosgi.config.JsonConvertionUnitTest.testProvisioningConfigurationJsonConvertionToInterface(JsonConvertionUnitTest.java:102)
> >>
> >> Is there any way to work with optional values in the target interface
> >> without get this exception ?
> >>
> >>
> >> many thanks,
> >>
> >> Cristiano
> >>
> >>
>

Reply via email to