hypfvieh / dbus-java

Improved version of java DBus library provided by freedesktop.org (https://dbus.freedesktop.org/doc/dbus-java/)
https://hypfvieh.github.io/dbus-java/
MIT License
185 stars 73 forks source link

Marshalling a Map with a generic type does not work #269

Closed vicr123 closed 10 hours ago

vicr123 commented 6 days ago

Example: In the following interface (in Kotlin)

@DBusInterfaceName("org.freedesktop.portal.FileChooser")
public interface DBusFileChooserInterface : DBusInterface {
    fun OpenFile(parentWindow: String, title: String, options: Map<String, Variant<*>>): ObjectPath;
}

The library marshals the options parameter as an a{s}, not an a{sv} as expected.

The root cause seems to be that the marshalling code does not handle a WildcardType: image

hypfvieh commented 6 days ago

Could you please provide sample Java code to demonstrate this issue?

[edit] This issues sounds a lot like #233, which is a pure kotlin problem and no library/Java issue.

vicr123 commented 6 days ago

Yeah that seems to fix the issue. I'm wondering if maybe we can add support in for whatever Kotlin does so we don't run into this in future. I'd be willing to open a PR but for some reason I can't seem to compile the code on my setup 😅

It would probably just involve the marshaller being able to handle a WildcardType and decoding the upperBounds of that type instead.

hypfvieh commented 5 days ago

Yeah that seems to fix the issue. I'm wondering if maybe we can add support in for whatever Kotlin does so we don't run into this in future. I'd be willing to open a PR but for some reason I can't seem to compile the code on my setup

No special setup required for this project. I just use Eclipse to open/edit and Maven to build the project. Works just fine without any additional configuration.

It would probably just involve the marshaller being able to handle a WildcardType and decoding the upperBounds of that type instead.

Maybe, maybe not. Map is a parametrized type, so when improving this, it also has to work with other types used as key or value in Map. As I'm not a Kotlin user, I can only check if there is anything I can do from the Java point of view. But I'm not sure that there is much I can do. Parametrized types like Map and Collection is always painful to handle. Most of the time important information is missing due to type erasure. I'll may have a look at this later, if you can provide a PR or other findings it will be much apprechiated.