r/javahelp • • Feb 07 '21

Unsolved Serialisation Java8

Yesterday i took an interview where i was asked "why serialisation is said to b lazy" ?

I certainly could not answer this as i have never ever come across anything where the serialisation is considered lazy. After the interview i did a quick google and yet no ans.

Can anyone please help know the right ans for this with detailed explanation

java8

22 Upvotes

21 comments sorted by

View all comments

22

u/Robyt3 Feb 07 '21

Using Serializable is lazy, because it's a quick and dirty solution with many drawbacks.

https://github.com/HugoMatilla/Effective-JAVA-Summary#74-implement-serializable-judiciously

5

u/Jyotikb25 Feb 07 '21

thanks alot for answering , also the word lazy in the context ,what exactly is its significance? does it mean "not long term solution" or something else

11

u/marvk Feb 07 '21

It has a lot of drawbacks but is quick to implement. Doing it is lazy. Using a different method of serialization like serializing to json requires more effort, but has more advantages.

4

u/HecknChonker Extreme Brewer Feb 07 '21

Serializing to and from JSON is fairly trivial, and really doesn't take that much effort.

String json = objectMapper.writeValueAsString(object);

https://www.baeldung.com/jackson-object-mapper-tutorial

3

u/marvk Feb 07 '21

Sure, when you have POJOs assembled from primitives or simple Objects it's trivial. But often times you end up needing a few adapters.