Closed mattdibi closed 1 year ago
I cannot check what's happening due to lack of proper setup. But I know that Variants may be unwrapped in some cases.
A Variant
is nothing else than a container which holds the value the and type of the value. Dbus-java will convert that to the desired type. Therefore a Map<String, Object>
should probably work.
In any case you will have some expectation of what type you will get and have to check if the value matches that expectation.
When using Variant
it would be checking which type, creating the proper instance etc. When getting the unwrapped value as Object
you have to some instanceof
checking.
For me your setup looks similar to NetworkManagerExample (line 60-70).
But I know that Variants may be unwrapped in some cases.
That's what caught me off guard.
As you pointed out I'm in a similar situation to the NetworkManager example, but there you found yourself with a Map<String, Variant<?>>
... in the ModemManager case I expected to find a Map<String, Variant<?>>
but I find myself with the already unwrapped variants in the map.
Is this due to ModemManager providing additional metadata in its DBus messages that allows for this unwrapping to take place (not actually sure this is technically possible, I'm not a dbus expert)? Is there a way to avoid this unwrapping to take place to have consistent behaviour between services (I'm using both NetoworkManager and ModemManager in my codebase and this inconsistency is somewhat weird)?
Therefore a Map<String, Object> should probably work.
This is what I ended up doing, even though I'm not liking since the behaviour is not consistent with other services.
The conversion is caused due to the different return types.
NetworkManager will return a List of Map (aa{sv}
) when e.g. asking for "AddressData".
Dbus-java will only check the first level of returned value to unwrap Variant
.
The returned object in for "AddressData" is a List, the List contains a Map, so there is nothing to unwrap.
In your case the return value is just a Map. I assume that the code in Marshalling line 610 will be called. This will than call the deSerializeParameter
method on key and value of the map which then will unwrap the Variant
.
There is no way to change this behavior.
Hello there,
I have a weird issue with a ModemManager property that is being unexpectedly unwrapped when retrieved.
I'm trying to get the data from the
Bearer
object Properties on my Raspberry Pi.Using
busctl
I get the expected output and signature:I've generated the following code for the
Bearer
object using the ModemManager introspection data.Then I created the following simple example to trigger the behaviour:
When I run the above code I get:
I expected to find a
Variant
not aString
inside theMap
!All the
Properties
content get casted to the final Java type instead of being aVariant
. Is this supposed to happen? How should I access the data without using aObject
type?Versions used for testing: