• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Which is better?

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Geeks,

We have the following requirement

CLient Machine needs Objects of type A to do some work. These object data needs to come from Server. Now we have two options.

1. Server generates Objects of Type A and convert them to XML and pass it through the Network. Client receives it and parses this XML back into Object of type A .

2. Server generates Objects of Type A and Serialize it and pass it through Network. CLient deserializes it to the Object of Type A.

So some guys says that Serialization process is not standard and is costly and complicated . I want to take suggestions of you guys on it.

Thanks and Regards
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java's serialization is standard, within Java. If both app are Java apps, and are expected to remain Java apps for a long time, then you'll have no problem there. If one of them is non-Java, then Java's built-in serialization probably won't work (unless there's a library to parse it for whatever language you're using, but I wouldn't want to go down that route).

As for complicated, whatever complexity is has is hidden inside. There are only a couple of classes and methods you need to use for most cases.

It should also be less costly in CPU requirements, memory requirements, and bandwidth requirements than XML, since it doesn't have to transform objects very far out of their natural internal representation, and because String representations of binary data are almost always bigger than the original, and XML in particular tends to be hugely bloated.

The main 3 reasons to use XML are:

1) If you need different platforms or languages to interact. In your case, this means if one end is not Java.

2) If you need humans to be able to examine the data in its serialized sate. XML serialized objects are not easy to read for humans, but natively serialized objects are pretty much impossible.

3) Java's native serialization is pretty sensitive to changes in the class. Adding or removing fields can screw it up if the versions on both ends don't match. Depending on which particular XML serialization tool you're using, it may be able to gracefully recover from or ignore those differences.
 
Sahil Reddy
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do i need to have the Same Class in Same package in client side during the process of deserialization.

For example class Student is in Package A on Server , i am serializing it and sending it through network to client.

Now on Client side i am receiving the serialized stream and trying to deserialize it but the Student class resides in different package. It shows ClassNotFoundException. Is it mandatory to have the same
class in same package ?//?

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sahil Reddy wrote:Do i need to have the Same Class in Same package in client side during the process of deserialization.



Yes, the class definition has to be present on the client side. (In theory you could serialize the Class object first, and then use ClassLoader to load that class after deserializaing it, but I've never tried that.)

Now on Client side i am receiving the serialized stream and trying to deserialize it but the Student class resides in different package.



The package is part of the class's definition. If it's in a different package, it's a completely different class, even if everything else is the same.

However it may be that some serialization tools--either a thirdparty one like XStream, or one that you might write yourself--could allow you to effectively say, "Take this serialized object, ignore its class, and deserialize its attributes into an object of this other class." You'll have to research to see if any of the existing tools offer that capability.

It shows ClassNotFoundException. Is it mandatory to have the same
class in same package ?//?



If it's not in the same package, then it's a completely different class.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeff Verdegan wrote:However it may be that some serialization tools--either a thirdparty one like XStream, or one that you might write yourself--could allow you to effectively say, "Take this serialized object, ignore its class, and deserialize its attributes into an object of this other class." You'll have to research to see if any of the existing tools offer that capability.


XStream effectively allows this, as it lets you register an alias for a class name or package name, or even a mapper that would do that on the fly. It seems that XStream even supports some binary format, though I don't have any experience with that (only XML).
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic