How to serialize/deserialize IgniteConfiguration to/from JSON
Is there a way to easily serialize/deserialize an IgniteConfiguration object to/from JSON?
The IgniteConfiguration class makes use of several interfaces for properties as well as for keys which makes it very difficult to serialize/deserialize to/from JSON without having to resort to annotate the source code (which I can only guess the main developers would not want to).
Any advice or samples from someone who has already done it, would be greatly appreciated
PS: Yes, I know that I could use the Spring module for configuration but I am trying to stay away from having to use Spring, which I might not be able to avoid it after all.
Re: How to serialize/deserialize IgniteConfiguration to/from JSON
Thank you for your prompt reply.
After responding to another issue you replied (Help with Integrating Ignite… with JBoss…) I don’t know how easy would be to describe an IgniteConfiguration object as a JSON string. As you mentioned in that reply, there are many factories, SPIs, etc. that are properties themselves.
I think the main reason for having a JSON configuration of Ignite would be to avoid the use of Spring for configuration but seeing how the IgniteConfiguration class (and its dependents) don’t really follow a JavaBean approach, I don’t think it would be a good candidate for JSON deserialization.
One of the issues (and I think in this case you have no control over it) I ran into was that CacheConfiguration extends MutableConfiguration (from JCache) and MutableConfiguration’s expiryPolicyFactory is set at construction time to EternalExpiryPolicy.factoryOf() which itself returns a FactoryBuilder.SingletonFactory that does not have a default constructor.
Another issue was with the DiscoverySpi configuration whose concrete implementation class TcpDiscoverySpi has many getter methods that when called raise an NPE (e.g. getRemoteNodes() ) and the reason for this, is that a TcpDiscoverySpi is not really ready until its spiStart method is called, which a JSON Serializer would not know about that.
Having said all this, I am going to open a ticket to request that Ignite itself provides some utility class/method that returns an IgniteConfiguration from a JSON string and generates a JSON from an IgniteConfiguration. It would be left to the implementors of the feature to determine how to specify the JSON string for deserialization and/or other restrictions/constraints/pre-requisites necessary for it to work correctly.