serialization - Spring MVC - should my domain classes implement Serializable for over-the-wire transfer? -


i'm trying learn spring boot implementing simple rest api.

my understanding if need transfer object on wire, object should implement serializable.

in many examples on net though, including official ones, domain classes need transferred server client (or vice-versa) not implement serializable.

for instance: https://spring.io/guides/gs/rest-service/

but in cases, do:

for instance: https://github.com/szerhusenbc/jwt-spring-security-demo/blob/master/src/main/java/org/zerhusen/security/jwtauthenticationrequest.java

is there general rule of thumb on when implement serializable?

using java serialization api means need in java on other side of wire deserialize objects, have control code deserializes code serializes.

this typically isn't relevant rest applications, consuming application response business of else's code, outside organization. when building rest application it's normal try avoid imposing limitations on consuming it, picking format more technology-agnostic , broadly available.

some reasons making object serializable be:

  • so can put in httpsession

  • so can pass between tiers in distributed application

  • so can save file system , restore later (for instance, make contents of queue serializable , have queue contents saved when application shuts down, reading save location when application starts restore queue state on shutdown).


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -