Comments (9)
Why do you want to send your struct wrapped in a variant?
Structs should extend the Struct.class and can therefore be send without wrapping it in a variant.
A struct should be looking like the samples in test sources (e.g. org.freedesktop.dbus.test.helper.structs.SampleStruct).
The position-annotation is important and is zero based!
If you wrap your object in a variant, the result will look like 'v(byyyyyyyyyyyyssssssssuiqyiiiis)'.
So you have to expect a Variant on the other side as well.
You then have to get the value from the variant and so on.
from dbus-java.
from dbus-java.
How does your code for receiving look like?
Usually you have an java interface with some methods in it.
Then you get the remote object from DBus by using somthing like:
MyRemoteInterface foo = (MyRemoteInterface) dbusSession.getRemoteObject("what.ever", "/where/ever");
Variant<MyStructData> variantStruct = foo.getMyStructDataWrappedInVariant();
MyStructData struct = variantStruct.getValue();
// continue to work with struct
The interface would look like:
@DBusInterfaceName("what.ever")
public interface MyRemoteInterface extends DBusInterface {
Variant<MyStructData> getMyStructDataWrappedInVariant();
}
So what are you doing?
from dbus-java.
from dbus-java.
Now I see what's going on.
Due to the fact that the struct is wrapped in a Variant object, the information on which class to use for this struct is getting lost.
When de-serializing the DBus message the resulting Variant will contain a struct of dummy type DBusStructType (you can see that when calling variant.getType() or see your ClassCastException).
When reading variant.getValue() you will receive all fields of the struct in order as Object[] instead of the struct class itself.
There is no way to 'teach' the library to do this automatically as the signature of a struct is not unique. There may be multiple structs with the same signature but resulting in different classes.
So to get a Struct out of a Variant, you have to know which kind of Struct it is and re-construct it manually.
To provide some more help, I added the class StructHelper to dbus-java.
This should be able to convert a Variant to a given Struct subclass, if Variant is compatible.
Please check my sandbox project to see how it works.
from dbus-java.
from dbus-java.
File attachments are not supported on github when answer tickets by mail, so I cannot see whatever you wanted to share.
Did you try my solution I posted before?
from dbus-java.
from dbus-java.
Your quoted part is in deed duplicated code in the sample. I've removed that part.
The conversion is already done in StructHelper.
As this solution is working for you, I'll close the ticket.
from dbus-java.
Related Issues (20)
- Documentation example does not work correctly. HOT 1
- In version 5, `withAutoConnect(false)` appears broken. HOT 2
- Cleanup AbstractConnection
- `default` interface methods. Or not. HOT 7
- problem to execute DBusViewer HOT 3
- How to export/publish Property in interface? HOT 2
- Properties Get method endless waiting HOT 1
- Cannot connect to DBUS HOT 11
- Sending signal with byte[] fails with verbose logging HOT 1
- [Feature request] Any plan in adding a module-info ? HOT 2
- Custom ITransportProvider cannot be found by ServiceLoader HOT 4
- Something a bit wrong with `@DBusBoundProperty` HOT 9
- Incorrect code generation for systemd StartTransientUnit HOT 3
- Add dbus-java-transport-junixsocket to dbus-java-bom
- Help with DBusConnectionBuilder HOT 2
- CodeGenerator does not create @DBusBoundProperty annotated fields properly for types TypeRef ans Struct HOT 2
- GetAll is not callable when using @DBusBoundProperty on a List<DBusPath> property HOT 1
- Memory leak in AbstractConnectionBase#importedObjects HOT 5
- Remove dependency on missing UnixSystem class HOT 1
- Graal Native Image Support HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dbus-java.