Any chance of sending JSON objects to JavaScript components?

Hello everyone,

I was just wondering if it was possible to store and transfer data in a JavaScriptComponentState as pure JSON? I tried briefly but couldn’t make it work, but maybe I was doing something wrong. If I knew it was possible I would spend more time on it.

This would greatly reduce the amount of boilerplate collections code on the server side, especially when in the end some of these collections are only going to end up as JSON objects.

Thanks for any help!
Chris.

Hi,

The way it should work is that you should be able to add a JSONObject to your state or use it as an RPC parameter. Unfortunately, at the moment we are still using separate JSON libraries on the client and on the server, which makes this a bit tricky. Track
#8942 Create a common wrapper for the two used JSON libraries
and
#9928 Support JSON objects in state and as RPC parameters
to see when this progresses. I also heard that using a JSONObject in the state today already might work “by accident”, at least in some cases. But #9928 will give real support for it.

Aha,
that’s
why it’s not working. Excellent, good to know it’ll be working eventually. Thanks Artur!