Help coderanch get a
new server
by contributing to the fundraiser
  • 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

When to use Serializable

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gurus,
I have some doubts regarding when to use the interface serializable. I have a very simple application. There is a servlet that invokes some bean. The bean does the jdbc connections and gets a ResultSet. The value object class is initialized from the ResultSet. Now my question is do i need to serialize the value object. If not when would i need serialization in such web applications?

Thanks,
Martin
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Martin,

Firstly, I'm no guru, so what you read below should be taken as opinion only.

So, your question is should you implement java.io.Serializable on your value object. It's certainly a reasonable thing to do, but whether you actually do it or not might depend on the answer to your second question.

Do you need to serialize the value object? Well, only you can answer that. You could serialize your object if you wanted to transmit its state, say over a network. You could also use serialization if you wanted to persist your object's state, say to a file or database. The benefit of serialization is that you can easily deserialize the object at the other end, or at a later date.

Typically in my experience of using web applications with relational databases there's no need to use object serialization but I expect it depends on your architecture and requirements.

Hope that helps.

Jules
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Broadly, two major cases.
  • When your web application is distributable, the application server needs to be able to replicate sessions between servers by serializing the objects in the session.
  • When your web application needs to marshal domain objects over the network, for example to communicate with a remote EJB tier.
  • - Peter
     
    Ranch Hand
    Posts: 61
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I think its a good idea to serialize the value object if you are not sure if you need it. Its not going to harm your application.
     
    Peter den Haan
    author
    Posts: 3252
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    KISS, YAGNI.

    - Peter
     
    Martin Lira
    Ranch Hand
    Posts: 97
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Gotit gurus!!
     
    You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
    We need your help - Coderanch server fundraiser
    https://coderanch.com/t/782867/Coderanch-server-fundraiser
    reply
      Bookmark Topic Watch Topic
    • New Topic