Calling all Java dudes

Veroland

Executive Member
Joined
Aug 24, 2005
Messages
6,304
Lo

This is probably a dumb question with a easy answer and I suspect the answer is no.

I have a POJO o1 with some properties and two more POJO's o2 and o3 that both extend o1 and declare some of their own custom properties.

I have a session bean (EJB 3) with a method on that returns a list of o1 that is made up of instances of o2 and o3.

I am exposing the method as a Web Service (Jax-WS) by generating the wsdl as a bottom up java bean service.

Now my problem, the xsd that get generated only defines the properties of o1. Is there a way I can make it generate/define the properties of o2 and o3 as well?

Thanks in advance.
 

FarligOpptreden

Executive Member
Joined
Mar 5, 2007
Messages
5,396
UPFRONT DISCLAIMER: I'm not a Java dude either, but I'm speaking from .NET Web Services experience.

Wouldn't the web service include the properties of o2s and o3s (as well as the inherited o1 properties) if you return a generic type of object (thinking of "object" in C# terms) from the method in the EJB 3 session bean?
 

Veroland

Executive Member
Joined
Aug 24, 2005
Messages
6,304
More or less, I want to have xml output not display the properties if they are not there or otherwise have them blank.

I can't find anything to make the wsdl generator acually inspect the sub classes to define the xsd data structures. I guess I'm going to have to do it top down, i.e. define the wsdl and xsd myself.
 

Veroland

Executive Member
Joined
Aug 24, 2005
Messages
6,304
UPFRONT DISCLAIMER: I'm not a Java dude either, but I'm speaking from .NET Web Services experience.

Wouldn't the web service include the properties of o2s and o3s (as well as the inherited o1 properties) if you return a generic type of object (thinking of "object" in C# terms) from the method in the EJB 3 session bean?

I would think so but for some reason JAXB (what we use to marshall and unmarshall the xml and to generate the wsdl) is not picking up the properties of o2 and o3. Only the properties defined in the generic object o1.
 

Nerfherder

Honorary Master
Joined
Apr 21, 2008
Messages
29,703
I have seen stuff like this before in C++

Do a search on the T1 libraries. Too hard for me :p
 

Veroland

Executive Member
Joined
Aug 24, 2005
Messages
6,304
let me try to elaborate:

Code:
class o1;

class o2 extends o1;
class o3 extends 01;

public List<o1> getList() {
     List<o1> list = new List<o1>();
     list.add(new o2('someValue'));
     list.add(new o3('value1', 'value2'));

     return list;
}

Replacing List<o1> with List<Object> will have pretty much the same effect.
 

FarligOpptreden

Executive Member
Joined
Mar 5, 2007
Messages
5,396
Just a shot in the dark, but shouldn't you declare in Java somewhere which properties of the extended classes should be serialized to XML? Again, from a .NET background you can only serialize (and thus expose) a property if it complies with the following:
- The property is declared as "public"
- The property isn't read-only (i.e. has getter and setter accessors)
- In some cases, the property is declared as [XmlAttribute]

Doesn't Java follow the same type of logic regarding serialization for web services?
 

Veroland

Executive Member
Joined
Aug 24, 2005
Messages
6,304
Just a shot in the dark, but shouldn't you declare in Java somewhere which properties of the extended classes should be serialized to XML? Again, from a .NET background you can only serialize (and thus expose) a property if it complies with the following:
- The property is declared as "public"
- The property isn't read-only (i.e. has getter and setter accessors)
- In some cases, the property is declared as [XmlAttribute]

Doesn't Java follow the same type of logic regarding serialization for web services?

There is a annotation on JAXB that you set wich is supposed to be @WebElements in which you declare your sub classes to use but the JAXB we are using does not like the annotation when creating a web service.

But if you serialise a List<o1>, doesn't it just serialise the whole list based on the rules for o1. And NOT iterate through the entire list checking the types before each element is serialised?

To be honest I don't know how this situation is handled in any language?

That is precisely what is happening. *Scratches head* I don't like this xml stuff. Keep me buried deeply in the back end objects and I'm happy :(

EDIT: BTW, thanks for the help guys, there are either no Java people here or they are not very helpful
 

Veroland

Executive Member
Joined
Aug 24, 2005
Messages
6,304
Thanks, I'll check it out, I just need to take my wife out for her birthday dinner now.

AOP won't resolve this particular problem though, but I'm thinking I'm getting somewhere, will let you guys know.

Ps. If you declare the Dentist class correctly the compiler will pick it up. The abstract on Person and Doctor say that they can not be instantiated but must be overridden.

It needs to be Dentist d = (Dentist)doctors[0]; ---> if doctors[0] is an instanceof Dentist, otherwise you would get a ClassCastException

:)
 

Veroland

Executive Member
Joined
Aug 24, 2005
Messages
6,304
Ok, looks like I got it to work.

I needed to add a @XmlSeeAlso annotation to the base class.

Code:
@XmlSeeAlso(Doctor.class)
public abstract class Person { }

public abstract class Doctor extends Person { }

This will make JAXB inspect the Doctor class as well and generate the property structure into the xsd.
 

FarligOpptreden

Executive Member
Joined
Mar 5, 2007
Messages
5,396
Java also has a Serializable, and it will atomatically serialize the class to the lowest instantiated sub class

Oh, right then. I haven't touched Java in AGES. The last time I did anything in it was back in my first year at varsity. The courses were pretty Java-focused, but somehow we went over to C++ and then on to VB.NET. For my projects I opted to teach myself C# after that. That's pretty much where I ended up now - a C#-aholic. :p
 

Veroland

Executive Member
Joined
Aug 24, 2005
Messages
6,304
Oh, right then. I haven't touched Java in AGES. The last time I did anything in it was back in my first year at varsity. The courses were pretty Java-focused, but somehow we went over to C++ and then on to VB.NET. For my projects I opted to teach myself C# after that. That's pretty much where I ended up now - a C#-aholic. :p

I've done lots of Pascal, Delphi, C, C++ and VB but I still like Java the most. I haven't really played with C# though, but all my projects deploy to *nix environments.
 

FarligOpptreden

Executive Member
Joined
Mar 5, 2007
Messages
5,396
I've done lots of Pascal, Delphi, C, C++ and VB but I still like Java the most. I haven't really played with C# though, but all my projects deploy to *nix environments.

Mono?

Ok, ok... that seems to be the response every time someone talks about .NET and *nix in the same context. Mono's just not quite there yet. It has potential, but lots of .NET stuff still breaks in it.

Java is pretty cool, AFAICR (new acronym?! :p). I'd love to set aside some time again and do a proper project in Java, specifically JEE. My line of work just doesn't allow it right now and I try to separate my work and personal lives to some degree. After hours there's very little time to experiment... :(
 

Veroland

Executive Member
Joined
Aug 24, 2005
Messages
6,304
Mono?

Ok, ok... that seems to be the response every time someone talks about .NET and *nix in the same context. Mono's just not quite there yet. It has potential, but lots of .NET stuff still breaks in it.

Java is pretty cool, AFAICR (new acronym?! :p). I'd love to set aside some time again and do a proper project in Java, specifically JEE. My line of work just doesn't allow it right now and I try to separate my work and personal lives to some degree. After hours there's very little time to experiment... :(

It should be a new acronym, I like it.

What is mono?

All my work I've done the last 8 or years have been J2EE / JEE. That is the space I like and play in.
 

Veroland

Executive Member
Joined
Aug 24, 2005
Messages
6,304
ok, mono looks cool.

Pity it doesn't support the AIX's and Solarises class of unix servers
 

FarligOpptreden

Executive Member
Joined
Mar 5, 2007
Messages
5,396
I think the problem is many non-MS developers' apprehension to get involved in Mono, purely because it then enables MS technologies to be operated on non-MS operating systems. I might be wrong, but this is the general feeling and trend that I can see happening around me.
 
Top