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/19 16:57:52 UTC

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 � 
</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 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/
>