-
Notifications
You must be signed in to change notification settings - Fork 6
scijava-persist : persisting objects with Gson and scijava discovery mechanism #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hey @NicoKiaru! Welcome to the incubator! This new module looks super cool! Let's see if we can't get this merged 💪
I'd be happy to help you out. I cloned your fork, it seems that your issues are due to version differences in
|
This commit makes a few changes which are needed in combination,
resulting in a incubator ready Maven module
1) Adds scijava-persist as a child module of the incubator
2) Denotes the incubator as the parent of scijava-persist
3) Removes the ImageJ dependency in favor of SciJava Common
0afe0db to
61947b3
Compare
|
@NicoKiaru I added two commits to your PR. Feel free to keep either or both of them:
After reading through the code a couple more times, I think I can answer some more of your discussion points:
Hmm, I think that
I might be completely crazy, but it sounds like a nice idea in my head 😁
My first instinct suggests that we should fail/skip both of the relevant serializers, and log an error. I think it is a mistake to do otherwise; if there are multiple serializer implementations, they should be reconciled into one. We do not want any confusion about which is being run. What do you think of this plan?
This is with respect to
Generally speaking, I like the idea of modularity, can you elaborate a bit more about the idea of annotations? How might the user benefit from a particular scenario? Do you think it would be useful for the user to specify a list of |
Thanks, that's perfect. And the context is enough, yes.
I don't know anything about JPMS, but I looked quickly and I kind of understand. In QuPath, I believe the 'internal' not being visible is kind of solved by putting this class in its original package: But I guess this won't solve the JPMS issue ?
Hum, if I understand correctly, this looks like adding another layer on top of Gson. Why not, but is it worth the effort ? While there's no use case and given all what needs to be maintained in scijava, do you think it's beneficial ? Would it be an idea to have 'scijava-gson' module which is rather unsafe (no version), and then make a 'scijava-persist' module, which is using scijava-gson or something else. Also one thing to consider is the compatibility with other software. If we rewrite, (using
👍
Not sure I understand your question, but maybe here's an example: Let's say I want to serialize a Now let's suppose that this sequence contains:
Serializing the sequence object will give something like: Fine. Now when deserializing, you will write something like By using RuntimeTypeAdapter, an extra field (named Serializing the sequence object will give something like: And it can now be deserialized easily as a RealTransform object. FYI, I'm already using this and the adapters are in https://github.com/bigdataviewer/bigdataviewer-playground/tree/master/src/main/java/net/imglib2/realtransform
Not sure yet, but the example of transform above could be such a scenario.
Yes, so if you do that I'd say you can use gson directly, no need for extensibility. The problem arises when you have adapters scattered in different repos. For instance, for the transform objects, some adapters are located in a 'core' repo (bigdataviewer-playground), but I also define other kinds of transforms and their respective adapters in extra repositories (like in this one: https://github.com/BIOP/bigdataviewer-biop-tools/tree/20391be90a54a26529e614dc084e4a2e3effd572/src/main/java/bdv/util). I want the serialization mechanism to be able to serialize any transform, and potentially one which I did not define myself. |
TODO: Scijava common is unable to find the Adapter Service.
03b282b to
e7f2c3b
Compare
Hmm, I think the easiest thing to do here then is to fork the needed classes from
Good point 😁. I still think this is a good idea if we could envision any other serialization protocol being useful within the SciJava world, but I don't want that to hold up the merging of this PR. The nice thing about the incubator is that it leaves us free to make these changes. So let's ignore this for now?
I could see an argument for that if we abstract the
I think I understand this, my question is more about why this method exists. I figured that it had something to do with this question you had:
If we are forking this class, it seems to me like this
Aha. Makes sense to me 😁 |
|
Thanks a lot!!
I think such a decision should not be taken by me, because I don't know enough about good software practice... Here's what I have in mind:
Trying to fix gson will cause complexity, plus we probably won't be able to cover every use case, and we will lose the 'default' serialisation procedure. Regarding the other comments:
To be honest, I didn't look at all at how this RuntimeTypeAdapterFactory class works 😁. This method is not used currently, we can probably remove it. If we want to put the full class name, we could just replace One last point regarding conflicts: there is still the confilct of the name used to specify the type. For instance a class like this: Cannot be serialized with runtime adapters. |
From @NicoKiaru: This PR brings a scijava service DefaultScijavaAdapterService which provides a way to serialize and deserialize java objects. Vocabulary : adapter = serializer (object to text) + deserializer (text to object) The most meaningful demo is in SerializationTests.java. A test is included, which basically makes a loop: object -> serialization -> string1 -> deserialization -> object -> serialization -> string2, and checks that string1.equals(string2) Scijava persist uses Gson serialization ( with RunTime adapters, which provide a way to serialize/deserialize objects extending abstract class or implements interface, see javadoc of RuntimeTypeAdapterFactory), and discovers and registers adapters at runtime. The adapters which are autodiscovered are of two kinds: IClassAdapter IClassRuntimeAdapter for adapters which require runtime adaptation (is this RealTransform object an affine transform ? or a sequence of transform, or a thinplateSplineTransform ? One runtime adapter needs to be registered per class) See #30
From @NicoKiaru: This PR brings a scijava service DefaultScijavaAdapterService which provides a way to serialize and deserialize java objects. Vocabulary : adapter = serializer (object to text) + deserializer (text to object) The most meaningful demo is in SerializationTests.java. A test is included, which basically makes a loop: object -> serialization -> string1 -> deserialization -> object -> serialization -> string2, and checks that string1.equals(string2) Scijava persist uses Gson serialization ( with RunTime adapters, which provide a way to serialize/deserialize objects extending abstract class or implements interface, see javadoc of RuntimeTypeAdapterFactory), and discovers and registers adapters at runtime. The adapters which are autodiscovered are of two kinds: IClassAdapter IClassRuntimeAdapter for adapters which require runtime adaptation (is this RealTransform object an affine transform ? or a sequence of transform, or a thinplateSplineTransform ? One runtime adapter needs to be registered per class) See #30
This draft PR brings a scijava service
DefaultScijavaAdapterServicewhich provides a way to serialize and deserialize java objects.Vocabulary : adapter = serializer (object to text) + deserializer (text to object)
The most meaningful demo is in
SerializationTests.java. A test is included, which basically makes a loop:object -> serialization -> string1 -> deserialization -> object -> serialization -> string2, and checks thatstring1.equals(string2)Scijava persist uses Gson serialization ( with RunTime adapters, which provide a way to serialize/deserialize objects extending abstract class or implements interface, see javadoc of
RuntimeTypeAdapterFactory), and discovers and registers adapters at runtime. The adapters which are autodiscovered are of two kinds:IClassAdapterIClassRuntimeAdapterfor adapters which require runtime adaptation (is thisRealTransformobject an affine transform ? or a sequence of transform, or a thinplateSplineTransform ? One runtime adapter needs to be registered per class)A few points to discuss:
ScijavaGsonHelper)java.awt.Listvsjava.util.List)