We sometimes handle big lists of documents, in which we make criteria based searches.
In order to optimize these searches, we have started using java HashMaps.
The problem is that java Objects cannot be saved in files using the service pu.flow:savePipelineToFile.
Is there a way to push some kind of serializer/deserializer for java Objects? Usually our HashMaps are pretty simple (key as String, value as IData) and it would help our debug processes a lot!
I wouldn’t recommend using savePipelineToFile for produtive usage.
If you need to persist objects to a file, create a Java service writing the file. A working example can be found in PSUtilities, but this one does not resemble up to date implementation practises. So I would propose using this as an example and writing a new one. This way you can use all Java functionality for serializing you objects.
Hi, indeed the Codable interface seems to be the answer. I’ll try that and report the result here!
This is not intended for production, but for debugging purpose. Being able to use specific java objects in step by step mode will help us gain a lot of time!
Here’s an exemple of a wrapper for the HashMap class. I only tried the IDataCodable interface, but it seems to work perfectly:
The savePipelineToFile/restorePipelineFromFile work as they should
It will save everything that can be saved, meaning: any java Object that is either already recognized (like IData, String, List instances…) or another implementaion of IDataCodable
A bonus I hadn’t expected: in step by step mode, the HashMap is now represented not as its toString() representation, but as the IData you built in the getIData method. Meaning its MUUUUUUUCH more readable in debug mode.
Enjoy!
PS: in my implementation, I chose to represent the HashMap as an IData array. Of course, you can do anything you like instead.