Polymorphism

2 posts / 0 new
Last post
Offline
Last seen: 5 years 9 months ago
Joined: 07/12/2018
Posts: 1
Polymorphism

Subscriber is not receiving all fields from polymorphic types.  And based on what I have read on this Forum, I think this might be the expected behavior.

I am using Java and my IDL looks like this: 

struct Container {   sequence<Parent> items; };

struct Parent { string lastName;  }:

struct Child : Parent { string firstName; };

PROBLEM:

If I create Child instances and add them to Container.items, the Publisher seems to publish firstName and lastName, but the Subscriber only receives lastName.  That is, it doesn't see the
fields implemented in the subclass.

Is there some way to get the polymorphism to work such that the Subscriber receives all of the fields associated with the runtime type that was published?

Thanks in advance!

Joe

 

 

Organization:
Offline
Last seen: 3 months 2 weeks ago
Joined: 02/11/2016
Posts: 144

Hey,

1. How do you know that the publishers publishes the first name? did you use wireshark and a dissector?

2. When you are not using the dynamic data api, rti will use statically compiled libraries to deserialize incoming data. since the type of Container is statically defined to work with a sequence of parents, i guess it is statically bound to work with parents, not children.

3. Other approaches that support do "polymorphism" are using UNIONS and using optional fields. (for example, making the sequence a sequence of "people", using a field to determine type of person, parent or child, and using an optional field firstName that has some default value that can be ignored)

 

Good luck,

Roy.