From fc6506cf0889479e04ab2ac0d092338155ad8eb6 Mon Sep 17 00:00:00 2001 From: David M Date: Fri, 17 May 2024 20:51:56 +0200 Subject: [PATCH] Issue #257: Updated PropRefRemoteHandler to deal with Structs properly --- .../propertyref/PropRefRemoteHandler.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/dbus-java-core/src/main/java/org/freedesktop/dbus/propertyref/PropRefRemoteHandler.java b/dbus-java-core/src/main/java/org/freedesktop/dbus/propertyref/PropRefRemoteHandler.java index 8dc169c8..7cc22763 100644 --- a/dbus-java-core/src/main/java/org/freedesktop/dbus/propertyref/PropRefRemoteHandler.java +++ b/dbus-java-core/src/main/java/org/freedesktop/dbus/propertyref/PropRefRemoteHandler.java @@ -1,9 +1,6 @@ package org.freedesktop.dbus.propertyref; -import org.freedesktop.dbus.Marshalling; -import org.freedesktop.dbus.RemoteInvocationHandler; -import org.freedesktop.dbus.RemoteObject; -import org.freedesktop.dbus.TypeRef; +import org.freedesktop.dbus.*; import org.freedesktop.dbus.annotations.DBusBoundProperty; import org.freedesktop.dbus.annotations.DBusProperty.Access; import org.freedesktop.dbus.connections.AbstractConnection; @@ -14,6 +11,7 @@ import org.freedesktop.dbus.utils.DBusNamingUtil; import org.freedesktop.dbus.utils.Util; +import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.Optional; @@ -79,7 +77,18 @@ public static Object handleDBusBoundProperty(AbstractConnection _conn, RemoteObj // requested return type is not Variant but the result is -> unwrap Variant if (_method.getReturnType() != Variant.class && typeClass != Variant.class && result instanceof Variant v) { - return v.getValue(); + result = v.getValue(); + } + + // if this is a Struct, convert it to the proper class + if (Struct.class.isAssignableFrom(typeClass)) { + Constructor cons = typeClass.getConstructors()[0]; + try { + result = cons.newInstance((Object[]) result); + } catch (Exception _ex) { + throw new DBusException(_ex.getMessage()); + } + } return result;