How’s it going there?
After I posted my blog about Autonomous JSON Database ADJ and Json libs, some people got to me asking and informing me that we can map directly to and from OSON (JSON type) without having to parser or serialize JSON text, and for that, we can use the “createDocumentFrom” method. So I decide to explore this as well.
This is a kind of a continuation from my previous blog where I explored the “createDocumentFromString” method, and in this one, I’ll explore the “createDocumentFrom” method.
You can check the Java Doc.
Note: my intention here is not to show that one way is better than the other or to indicate one lib as better than the other. but to show the possible options. And as I already demonstrated the result will be the same.
Oracle provides some examples, but the idea here is to see how we can use ADJ with Java Records and see all Libs possibilities, and about the topic, I found this blog series with a lot of explanations that I suggest you read before checking my examples.
Again I did the test with the most popular JSON libs; JSON-B, Jackson, and Gson.
Picture1: most popular JSON libs
You can check and get the code in my GitHub.
From the previous example, I just add a new Class Autonomous2 using the new method.
First I updated the yasson version from 1.0.6 to 1.0.8 and with that, I got rid of some WARNING
For JSON-B I changed the attribute’s names to add get in front.
For Jackson, I ended up with an ugly switch/case method that I didn’t find a better way to populate the “gen” object.
throw new IllegalStateException(token.toString());
I checked out the new Quarkus 1.13.2.Final released – Oracle JDBC driver extension, bug fixes, and there’s no SODA support.
You can see everything about JDBC here and an example with Oracle here.
Picture2: Java Duke serialization and deserialization
- As I demonstrated, all options end up creating the same result.
- Use what is best for your case or whatever you feel more comfortable with.
- Java Records will likely need some JSON-B specification integration but that there is no technical blocker to make it work.
- I had fun and learned a lot about the differences between the JSON libs and how to combine them with Java Records
Don’t forget that now the always Free Oracle Autonomous JSON Database is available, so now is the Action time. Go ahead and try to play around with AJD and check out the Java Records examples.