You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by Beaumier Eric <eb...@yahoo.com> on 2001/04/18 23:02:08 UTC

"java.lang.Object" Serializer/Deserializer

When I try to pass my java class (bean) using one
Object inside, I can't retrieve it from the response
of my SOAP call.

It's sounds like no serializer for "java.lang.Object"
!
I have tried using the BeanSerializer:
 
smr.mapTypes(Constants.NS_URI_SOAP_ENC,
  new QName("urn:xml-soap-object", "object"),
  Object.class, beanSer, beanSer);


But unable to cast my object in other type than Object
(ex; ResultSet) when the call came back?

Anybody have an idea?

Thanks.  


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Re: "java.lang.Object" Serializer/Deserializer

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Scott Nichol wrote:

> > to make it work properly when instance class is different from declared
> > property type you should include xsi:type so it will get deserialize
> > properly (i think even with the current bean deserializer).
>
> The issue in this case is that the instance is always serialized as an Object because it is from a
> bean property of type Object, regardless of the actual type being returned by the accessor for the
> property.  The xsi:type that gets written corresponds to java.lang.Object.

i was just pointing that xsi:type can be omitted safely when declared type == actual type but it is
required when you want to serialize subtype (actual instance type) and trying to serialize instance of
Object class should be probably runtime error (and should never happen)...

alek
--
Aleksander Slominski, LH 316, IU, http://www.extreme.indiana.edu/~aslom
As I look afar I see neither cherry Nor tinted leaves Just a modest hut
on the coast In the dusk of Autumn nightfall - Fujiwara no Teika(1162-1241)



Re: "java.lang.Object" Serializer/Deserializer

Posted by Scott Nichol <sn...@computer.org>.
> Scott Nichol wrote:
> > If I were trying to accomplish what you are, I would do one of two things.  Either I would
create a
> > serializer just like BeanSerializer, except that it serializes properties according to the type
of
> > the instance of the property, not the property from getPropertyType.  I would then use that to
> > serialize the class that has the Object property.  I would map each class that could be stored
in
> > that property to either BeanSerializer, the new serializer, or another custom serializer.
> >
>
> to make it work properly when instance class is different from declared
> property type you should include xsi:type so it will get deserialize
> properly (i think even with the current bean deserializer).

The issue in this case is that the instance is always serialized as an Object because it is from a
bean property of type Object, regardless of the actual type being returned by the accessor for the
property.  The xsi:type that gets written corresponds to java.lang.Object.

Scott



Re: "java.lang.Object" Serializer/Deserializer

Posted by Aleksander Slominski <as...@cs.indiana.edu>.
Scott Nichol wrote:
> If I were trying to accomplish what you are, I would do one of two things.  Either I would create a
> serializer just like BeanSerializer, except that it serializes properties according to the type of
> the instance of the property, not the property from getPropertyType.  I would then use that to
> serialize the class that has the Object property.  I would map each class that could be stored in
> that property to either BeanSerializer, the new serializer, or another custom serializer.
> 

to make it work properly when instance class is different from declared
property type you should include xsi:type so it will get deserialize
properly (i think even with the current bean deserializer).

thanks,

alek
--
Aleksander Slominski, IU, http://www.extreme.indiana.edu/~aslom
As I look afar I see neither cherry Nor tinted leaves Just a modest hut
on the coast In the dusk of Autumn nightfall-Fujiwara no Teika(1162-1241)

Re: "java.lang.Object" Serializer/Deserializer (Scott)

Posted by Scott Nichol <sn...@computer.org>.
This is quite true.  In fact, I can imagine someone writing a [de]serializer that uses
Java serialization from and to a "blob".  Of course, there is little chance that someone
could create a client to run against your server using VB, Perl, C++, etc.

Scott

----- Original Message -----
From: "Beaumier Eric" <eb...@yahoo.com>
To: <so...@xml.apache.org>
Sent: Thursday, April 19, 2001 10:57 AM
Subject: Re: "java.lang.Object" Serializer/Deserializer (Scott)


>
> Thanks,
>
> But I will ask you another question.  To avoid all
> this
> steps, could we serialize an Object in String or
> ByteArray (binary representation and recreate it like
> a Blob on the listener).
>
> <SOAP-ENV:Body>
> <ns1:getObjectInfo xmlns:ns1="MyListener"
> SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
> <Object xsi:type="xsd:objectblob">Êþº¾  - s t u v
>  x  y ^ z {  z | }  ~  ?  y ,  z f
> </Object>
> </ns1:getObjectInfo>
> </SOAP-ENV>
>
>
> Thanks again.
>
>
> --- Scott Nichol <sn...@computer.org> wrote:
> > > > If that is the case, you cannot cast it to any
> > other
> > > > class, as it will be deserialized
> > > > from the SOAP message as an Object.
> > >
> > > Why?  It's still an Object (java.lang.Object) ...
> > > It's not supposed to be recreated as the original?
> >
> > Here's my reading of the code; take it as such, not
> > as fact...
> >
> > BeanSerializer is responsible for [de]serializing a
> > bean.  The marshal method, which handles
> > serialization, serializes each property of the bean.
> >  For the data type of each property, it uses
> > the type declared for the property, not the actual
> > type of the instance.  In particular, it does
> >
> >        Class propType =
> > properties[i].getPropertyType();
> >
> > rather than
> >
> >        propValue = propReadMethod.invoke(src, new
> > Object[]{});
> >        Class propType = propValue.getClass();
> >
> > then uses propType as the type to serialize.  In
> > your case, this means the instance is serialized as
> > an Object, not as the actual type that it is.  I
> > believe you discovered that and provided a mapping
> > to serialize/deserialize an Object using the
> > BeanSerializer.  So, any properties on that instance
> > should be serialized in the request message, but the
> > type of the instance will be labeled as
> > something that maps to Object, not to the actual
> > type.
> >
> > The BeanSerializer#unmarshal method deserializes
> > this instance on the server.  The Bean is created
> > by
> >
> >     Class javaType = xjmr.queryJavaType(elementType,
> > inScopeEncStyle);
> >     Object bean = instantiateBean(javaType);
> >
> > The instantiateBean method is basically
> > javaType.newInstance().  Since javaType is Object,
> > the bean
> > you deserialize is truly an Object, not some
> > subclass thereof.
> >
> > If I were trying to accomplish what you are, I would
> > do one of two things.  Either I would create a
> > serializer just like BeanSerializer, except that it
> > serializes properties according to the type of
> > the instance of the property, not the property from
> > getPropertyType.  I would then use that to
> > serialize the class that has the Object property.  I
> > would map each class that could be stored in
> > that property to either BeanSerializer, the new
> > serializer, or another custom serializer.
> >
> > A second possibility is to start with a custom
> > serializer specific to your class that has the
> > Object
> > property.
> >
> > > If the bean
> > > > property has type X, of course, you
> > > > should map type X to the BeanSerializer or some
> > > > custom [de]serializer you write for X.
> > > >
> > >
> > > Do you have some documentation (or URL) of how I
> > can
> > > create my own Serializer/Deserializer (could be
> > > usefull if not already some obejcts aren't
> > supported)?
> >
> > I don't know of such a document off hand.  I think
> > the source code for the existing serializers,
> > both those that get packaged into soap.jar and those
> > from the samples (the address book sample has
> > two serializers) can probably get you through what
> > you need to do.  I found it pretty easy to
> > produce the ones I needed.
> >
> > Scott
> >
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
>


Re: "java.lang.Object" Serializer/Deserializer (Scott)

Posted by Beaumier Eric <eb...@yahoo.com>.
Thanks, 

But I will ask you another question.  To avoid all
this
steps, could we serialize an Object in String or
ByteArray (binary representation and recreate it like
a Blob on the listener).

<SOAP-ENV:Body>
<ns1:getObjectInfo xmlns:ns1="MyListener"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<Object xsi:type="xsd:objectblob">����  - s t u v
 x  y ^ z {  z	 | }  ~  � �  y �  z � 
</Object>
</ns1:getObjectInfo>
</SOAP-ENV>


Thanks again.


--- Scott Nichol <sn...@computer.org> wrote:
> > > If that is the case, you cannot cast it to any
> other
> > > class, as it will be deserialized
> > > from the SOAP message as an Object.
> >
> > Why?  It's still an Object (java.lang.Object) ...
> > It's not supposed to be recreated as the original?
> 
> Here's my reading of the code; take it as such, not
> as fact...
> 
> BeanSerializer is responsible for [de]serializing a
> bean.  The marshal method, which handles
> serialization, serializes each property of the bean.
>  For the data type of each property, it uses
> the type declared for the property, not the actual
> type of the instance.  In particular, it does
> 
>        Class propType =
> properties[i].getPropertyType();
> 
> rather than
> 
>        propValue = propReadMethod.invoke(src, new
> Object[]{});
>        Class propType = propValue.getClass();
> 
> then uses propType as the type to serialize.  In
> your case, this means the instance is serialized as
> an Object, not as the actual type that it is.  I
> believe you discovered that and provided a mapping
> to serialize/deserialize an Object using the
> BeanSerializer.  So, any properties on that instance
> should be serialized in the request message, but the
> type of the instance will be labeled as
> something that maps to Object, not to the actual
> type.
> 
> The BeanSerializer#unmarshal method deserializes
> this instance on the server.  The Bean is created
> by
> 
>     Class javaType = xjmr.queryJavaType(elementType,
> inScopeEncStyle);
>     Object bean = instantiateBean(javaType);
> 
> The instantiateBean method is basically
> javaType.newInstance().  Since javaType is Object,
> the bean
> you deserialize is truly an Object, not some
> subclass thereof.
> 
> If I were trying to accomplish what you are, I would
> do one of two things.  Either I would create a
> serializer just like BeanSerializer, except that it
> serializes properties according to the type of
> the instance of the property, not the property from
> getPropertyType.  I would then use that to
> serialize the class that has the Object property.  I
> would map each class that could be stored in
> that property to either BeanSerializer, the new
> serializer, or another custom serializer.
> 
> A second possibility is to start with a custom
> serializer specific to your class that has the
> Object
> property.
> 
> > If the bean
> > > property has type X, of course, you
> > > should map type X to the BeanSerializer or some
> > > custom [de]serializer you write for X.
> > >
> >
> > Do you have some documentation (or URL) of how I
> can
> > create my own Serializer/Deserializer (could be
> > usefull if not already some obejcts aren't
> supported)?
> 
> I don't know of such a document off hand.  I think
> the source code for the existing serializers,
> both those that get packaged into soap.jar and those
> from the samples (the address book sample has
> two serializers) can probably get you through what
> you need to do.  I found it pretty easy to
> produce the ones I needed.
> 
> Scott
> 
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Re: "java.lang.Object" Serializer/Deserializer

Posted by Scott Nichol <sn...@computer.org>.
> > If that is the case, you cannot cast it to any other
> > class, as it will be deserialized
> > from the SOAP message as an Object.
>
> Why?  It's still an Object (java.lang.Object) ...
> It's not supposed to be recreated as the original?

Here's my reading of the code; take it as such, not as fact...

BeanSerializer is responsible for [de]serializing a bean.  The marshal method, which handles
serialization, serializes each property of the bean.  For the data type of each property, it uses
the type declared for the property, not the actual type of the instance.  In particular, it does

       Class propType = properties[i].getPropertyType();

rather than

       propValue = propReadMethod.invoke(src, new Object[]{});
       Class propType = propValue.getClass();

then uses propType as the type to serialize.  In your case, this means the instance is serialized as
an Object, not as the actual type that it is.  I believe you discovered that and provided a mapping
to serialize/deserialize an Object using the BeanSerializer.  So, any properties on that instance
should be serialized in the request message, but the type of the instance will be labeled as
something that maps to Object, not to the actual type.

The BeanSerializer#unmarshal method deserializes this instance on the server.  The Bean is created
by

    Class javaType = xjmr.queryJavaType(elementType, inScopeEncStyle);
    Object bean = instantiateBean(javaType);

The instantiateBean method is basically javaType.newInstance().  Since javaType is Object, the bean
you deserialize is truly an Object, not some subclass thereof.

If I were trying to accomplish what you are, I would do one of two things.  Either I would create a
serializer just like BeanSerializer, except that it serializes properties according to the type of
the instance of the property, not the property from getPropertyType.  I would then use that to
serialize the class that has the Object property.  I would map each class that could be stored in
that property to either BeanSerializer, the new serializer, or another custom serializer.

A second possibility is to start with a custom serializer specific to your class that has the Object
property.

> If the bean
> > property has type X, of course, you
> > should map type X to the BeanSerializer or some
> > custom [de]serializer you write for X.
> >
>
> Do you have some documentation (or URL) of how I can
> create my own Serializer/Deserializer (could be
> usefull if not already some obejcts aren't supported)?

I don't know of such a document off hand.  I think the source code for the existing serializers,
both those that get packaged into soap.jar and those from the samples (the address book sample has
two serializers) can probably get you through what you need to do.  I found it pretty easy to
produce the ones I needed.

Scott



Re: "java.lang.Object" Serializer/Deserializer

Posted by Beaumier Eric <eb...@yahoo.com>.

> By "one Object inside", do you mean that there is a
> bean property that has type Object?
 
 Yes

> If that is the case, you cannot cast it to any other
> class, as it will be deserialized
> from the SOAP message as an Object.  

Why?  It's still an Object (java.lang.Object) ...
It's not supposed to be recreated as the original?


If the bean
> property has type X, of course, you
> should map type X to the BeanSerializer or some
> custom [de]serializer you write for X.
> 

Do you have some documentation (or URL) of how I can
create my own Serializer/Deserializer (could be
usefull if not already some obejcts aren't supported)?



__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Re: "java.lang.Object" Serializer/Deserializer

Posted by Scott Nichol <sn...@computer.org>.
By "one Object inside", do you mean that there is a bean property that has type Object?
If that is the case, you cannot cast it to any other class, as it will be deserialized
from the SOAP message as an Object.  If the bean property has type X, of course, you
should map type X to the BeanSerializer or some custom [de]serializer you write for X.

Scott

----- Original Message -----
From: "Beaumier Eric" <eb...@yahoo.com>
To: <so...@xml.apache.org>
Sent: Wednesday, April 18, 2001 5:02 PM
Subject: "java.lang.Object" Serializer/Deserializer


>
> When I try to pass my java class (bean) using one
> Object inside, I can't retrieve it from the response
> of my SOAP call.
>
> It's sounds like no serializer for "java.lang.Object"
> !
> I have tried using the BeanSerializer:
>
> smr.mapTypes(Constants.NS_URI_SOAP_ENC,
>   new QName("urn:xml-soap-object", "object"),
>   Object.class, beanSer, beanSer);
>
>
> But unable to cast my object in other type than Object
> (ex; ResultSet) when the call came back?
>
> Anybody have an idea?
>
> Thanks.
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/