POJO Stuck
Feb. 9th, 2023 09:18 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
When I originally ported our code to Java, it was some years ago. One of the things that I wrote was a fairly robust class to support XML serialization which handled the various types that I wanted to handle as simple calls, burying the translation to and from Strings. It also knows how to detect and avoid duplicating multiple instances of the same object that are in the serialization stream. And it has a SAX-like callback method to allow the classes that it works with to read attributes and contained elements in any order that they are presented.
Overall, it's a nice class.
But Java moves forward and the Jackson libraries now support XML serialization using their own scheme. In this case, you add some simple annotations to the class and now you can read and write an object (Plain Old Java Object, or POJO) belonging to the class in XML as well as JSON.
I spent the last two days adding support for Jackson-enabled objects to my XML serialization library. This was relatively simple, because both my XML serialization library and Jackson's are built on top of StAX, which is a very nice XML streaming system. I had to make a few changes, because I had used the XMLEventReader and Jackson wanted the XMLStreamReader, but that mostly just required me to remove all of the peek() references from my code.
Today, the modified code passed all of the unit tests (and some new tests that I added for the occasion), so you can now read and write Jackson-enabled objects as part of my XML serialization scheme.
It's nice to have a quick win.
Overall, it's a nice class.
But Java moves forward and the Jackson libraries now support XML serialization using their own scheme. In this case, you add some simple annotations to the class and now you can read and write an object (Plain Old Java Object, or POJO) belonging to the class in XML as well as JSON.
I spent the last two days adding support for Jackson-enabled objects to my XML serialization library. This was relatively simple, because both my XML serialization library and Jackson's are built on top of StAX, which is a very nice XML streaming system. I had to make a few changes, because I had used the XMLEventReader and Jackson wanted the XMLStreamReader, but that mostly just required me to remove all of the peek() references from my code.
Today, the modified code passed all of the unit tests (and some new tests that I added for the occasion), so you can now read and write Jackson-enabled objects as part of my XML serialization scheme.
It's nice to have a quick win.