Git Product home page Git Product logo

Comments (9)

clausnagel avatar clausnagel commented on May 27, 2024 1

merged serializable branch into master (7c32e28)

from citygml4j.

clausnagel avatar clausnagel commented on May 27, 2024

No considerations so far because I am using CityGML or CityJSON for de-/serialization. I like your idea and it shouldn't be too hard to implement it. Btw, your are talking about the classes in org.citygml4j.model, right?

from citygml4j.

kainoa21 avatar kainoa21 commented on May 27, 2024

Correct! I think it is just a matter of adding the interface and potentially adding serialVersionUID. Agreed that CityGML or CityJSON also works for serialization but a bit bloated for inter-process communication. If you are open to it I can submit a PR.

from citygml4j.

clausnagel avatar clausnagel commented on May 27, 2024

Yes, a PR would be great. I think, the root interface of all model classes is org.citygml4j.model.common.base.ModelObject. So it should be sufficient to let this interface extend Serializable.

I am not sure about the serialVersionUID field. Is it required for every non-abstract class? Or is it sufficient to be present for the (abstract) root class of an inheritance chain to be considered for all classes in that inheritance chain? If the latter is possible, this would substantially reduce the effort.

from citygml4j.

kainoa21 avatar kainoa21 commented on May 27, 2024

I am not an expert in this space, but my sense is that any class which contains fields that you intend to be restored after deserialization need to be marked as Serializable otherwise the default empty constructor will be called. So I think this means that most of the classes in the org.citygml4j.model will need to explicitly implement Serializable (and therefore should probably maintain their own serialVersionUID).

from citygml4j.

clausnagel avatar clausnagel commented on May 27, 2024

I did a quick test. It seems to be sufficient to let the interface org.citygml4j.model.common.base.ModelObject and the abstract class org.citygml4j.model.module.AbstractModule extend resp. implement the Serializable interface. After that I was able to serialize and deserialize a citygml4j object. Well, I have not worked with Java serialization before so I was surprised to learn that it is quite slow.

Afterwards, I added a serialVersionUID to org.citygml4j.model.gml.base.AbstractGML which is a base class for many citygml4j classes. With that change, I was not able to deserialize the object from my previous test anymore. So it seems to be sufficient to use serialVersionUID on root classes of an inheritance chain.

from citygml4j.

mprins avatar mprins commented on May 27, 2024

You should read https://stackoverflow.com/questions/285793/what-is-a-serialversionuid-and-why-should-i-use-it

Afterwards, I added a serialVersionUID to org.citygml4j.model.gml.base.AbstractGML which is a base class for many citygml4j classes. With that change, I was not able to deserialize the object from my previous test anymore. So it seems to be sufficient to use serialVersionUID on root classes of an inheritance chain.

this conforms to the spec; because you now have a different version of the object so it is assumed incompatible.
if you always want to create compatible java serializations each generated class should have a serialVersionUID, it can be 1L, otherwise data may not be deserialized in a different JVM

from citygml4j.

clausnagel avatar clausnagel commented on May 27, 2024

@kainoa21 Sorry for not being very active on this lately. I pushed the implementation of the Serializable interface to the serializable branch for testing. It required just a small change to the model classes as written above. And when using buffered input and output streams, serialization performance is just fine. So feel free to test the branch and provide feedback or edits.

@mprins Thanks for your input.

from citygml4j.

kainoa21 avatar kainoa21 commented on May 27, 2024

This is great @clausnagel and I have verified that is working for my use case. Thank you for enabling this!

from citygml4j.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.