3

My question may sound very basic one but I am a bit confused on jackson s writeValueAsString(String) is also called as serialization and conversion of java object to byte stream is also called as Serialization.

Can anyone help me understand; how both of them are different?

The reason I am asking this question is, I got into a scenario where I call a REST service. The REST responds in 10 seconds with JSON. However if I log the time of writeValueAsString(String) on server side, it hardly takes a second.

UPDATE 1: This is what I am observing

  1. Last log on invoked REST service(returning a collection) prints at -->9:10:10 UTC. And, data simultaneously starts streaming on my machines Git bash as I am using curl to call service.

  2. After 10 seconds last log on my Servlet filter( as intercepts the request to REST api uri) prints out at --> 9:10:20 UTC and at the very same time data streaming stops at Git bash(nearly 35Mb downloaded). So, what could be the reason for this behavior?

If Jackson simultaneously started sending bytes over the network while serialization is still on?

Is that Jackson serialization is slow or network bandwidth is low?

Note that, I tried running my serialization and deserialization only using writeValueAsString(..)/readValue(..) operations without any network call through junit with the same set of data and they executes within a second of time.

Thanks

Jaraws
  • 581
  • 1
  • 7
  • 24
  • 1
    From [wikipedia](https://en.wikipedia.org/wiki/Serialization): *In computing, serialization (or serialisation) is the process of translating data structures or object state into a format that can be stored (for example, in a file or memory buffer) or transmitted (for example, across a network connection link) and reconstructed later (possibly in a different computer environment).* – Lino Jun 23 '20 at 08:09
  • 3
    Java serialization takes an object and converts it into a byte stream. The same happens with Jackson when converting to JSON it's just the byte stream is in a different format. It's possible there's some confusion since JSON is a text format, but remember that everything is 1's and 0's to a computer, even text. The important part is that both ends understand the format. – Slaw Jun 23 '20 at 08:17
  • Slaw, what will be taking time then? If from writeValueAsString(..) to response received at client end is nearly 9 seconds and of which writeValueAsString(..) just consuming a second of time. – Jaraws Jun 23 '20 at 08:44
  • Can you provide a link to the Javadoc of `writeValueAsString`? Or otherwise provide a [mre] in your question? – Slaw Jun 23 '20 at 09:43
  • I just updated my question with update 1. – Jaraws Jun 24 '20 at 03:35

1 Answers1

3

Server response time of 10 seconds is not just the serialization time, it includes the:

  • total time of request reaching the REST service server over the network
  • internal processing in the REST service app
  • response reaching your application over the network
  • (Additionaly the time taken at various other layers, but not including them for the sake of simplicity).

And for serialization - adding the comment from @Lino here:

In computing, serialization (or serialisation) is the process of translating data structures or object state into a format that can be stored (for example, in a file or memory buffer) or transmitted (for example, across a network connection link) and reconstructed later (possibly in a different computer environment)

Source : Wikipedia

Lino
  • 19,604
  • 6
  • 47
  • 65
Smile
  • 3,832
  • 3
  • 25
  • 39
  • Smile, I have calculated the time over the network, the time consumed for processing request on server side but even after considering all the times, the time I assume is spent for serializing the response is far more than time consumed by jsons writeValueAsString(..) operation. Is writeValueAsString() is not something we call serialization? Why? – Jaraws Jun 23 '20 at 08:30
  • Check @Slaw's comment about whether writeValueAsString is serialization. I would advise hitting the REST service by some other client like Postman and then compare the response time with that of doing it with java. Also, what is the size of response? – Smile Jun 23 '20 at 09:27
  • Do you also own the REST service you are calling? If yes, you can further do analysis in that service about which component takes most time. – Smile Jun 23 '20 at 09:29