graphhopper / directions-api-clients

API clients for various languages for the GraphHopper Directions API
https://docs.graphhopper.com/
Apache License 2.0
30 stars 39 forks source link

Feature: Make Java models implement serializable #32

Closed Dexyon closed 4 years ago

Dexyon commented 5 years ago

Added the option to the swagger CLI to make all models implement the ISerializable interface

karussell commented 5 years ago

Is Serializable really used these days? May I ask which framework requires you to do this?

And with such an addition wouldn't we suggest that we fully support java Serialization? Please see here: https://softwareengineering.stackexchange.com/q/191269 what I mean:

As any good Java developer knows, if you plan to serialize an object, even in a session, you need a real serialization ID (serialVersionUID), not just a 1L, and you need to implement the Serializable interface. However, most developers do not know the real rules behind the Java deserialization process. If your object has changed, more than just adding simple fields to the object, it is possible that Java cannot deserialize the object correctly even if the serialization ID has not changed. Suddenly, you cannot retrieve your data any longer, which is inherently bad.

Dexyon commented 5 years ago

Hi Peter,

I came upon this issue when I was trying to serialize the object to store it in a Redis store. By default it tries to serialize objects. For now I worked around the issue, since I'm not sure if that is the way I want to store the object.

I had this code locally, so decided just push it and create some discussion :)

karussell commented 5 years ago

I came upon this issue when I was trying to serialize the object to store it in a Redis store.

Which Java client are you using where it is required to use Serializable interface? These days typically (de)serialization libraries can live without it (like e.g. jackson). And if you want to use e.g. jedis with serialized java you can serialize into a JSON:

https://stackoverflow.com/questions/12279117/can-jedis-get-set-an-java-pojo/12355876#12355876

Note the comment of the redis dev: "although I won't recommend to store your java objects serialized"

Another possibility is to use redisson