Discussion:
JSObject without Java-based conversion to JSON
(too old to reply)
Victor Polischuk
2018-04-11 04:48:02 UTC
Permalink
Dear all,

I apologize if the question was already raised in the mail list, however, I find it quite strange that JSObject lacks convenient methods to convert it at least to JSON-string, if not directly to Java-POJOs?

The Internet is full of suggestions which involve JavaScript JSON.stringify(..) as a utility. While it might work too, but I guess a lot of others are just traversing the JSObject by their own "converters".

Therefore, if there is no design limitations/reasons why the conversion should/could not be applied within the Java representation, I am ready to volunteer on the patch.

My reason for it are:
* It looks quite ugly to execute JavaScript to make something with "almost" Java object.
* Java has enormous number of JSON libraries already. I guess it is nice to allow people connect their favorite with minimal efforts. Potentially, if it will be required "string" phase might be excluded (not JSObject->String->POJO, but JSObject->POJO).
* It may simplify logging/debugging of interaction between Java and JS.

/
Best Regards,
Victor
Sundararajan Athijegannathan
2018-04-13 02:50:38 UTC
Permalink
Please note that a general Java object graph may involve circular
references. Without modifying JSON somehow, it is not possible to handle
such cases. That said, please do file a rfe with your ideas and we can
discuss.

-Sundar
Post by Victor Polischuk
Dear all,
I apologize if the question was already raised in the mail list, however, I find it quite strange that JSObject lacks convenient methods to convert it at least to JSON-string, if not directly to Java-POJOs?
The Internet is full of suggestions which involve JavaScript JSON.stringify(..) as a utility. While it might work too, but I guess a lot of others are just traversing the JSObject by their own "converters".
Therefore, if there is no design limitations/reasons why the conversion should/could not be applied within the Java representation, I am ready to volunteer on the patch.
* It looks quite ugly to execute JavaScript to make something with "almost" Java object.
* Java has enormous number of JSON libraries already. I guess it is nice to allow people connect their favorite with minimal efforts. Potentially, if it will be required "string" phase might be excluded (not JSObject->String->POJO, but JSObject->POJO).
* It may simplify logging/debugging of interaction between Java and JS.
/
Best Regards,
Victor
Victor Polischuk
2018-04-14 09:52:36 UTC
Permalink
Hi Sundar,

Thank you for the answer. I have filed a RFE #9053373, with the minimal intrusion in the API which already should allow people to work with Nashorn more comfortably.

/Victor

--- Original message ---
From: "Sundararajan Athijegannathan" <***@oracle.com>
Date: 13 April 2018, 05:47:38
Post by Sundararajan Athijegannathan
Please note that a general Java object graph may involve circular
references. Without modifying JSON somehow, it is not possible to handle
such cases. That said, please do file a rfe with your ideas and we can
discuss.
-Sundar
Post by Victor Polischuk
Dear all,
I apologize if the question was already raised in the mail list, however, I find it quite strange that JSObject lacks convenient methods to convert it at least to JSON-string, if not directly to Java-POJOs?
The Internet is full of suggestions which involve JavaScript JSON.stringify(..) as a utility. While it might work too, but I guess a lot of others are just traversing the JSObject by their own "converters".
Therefore, if there is no design limitations/reasons why the conversion should/could not be applied within the Java representation, I am ready to volunteer on the patch.
* It looks quite ugly to execute JavaScript to make something with "almost" Java object.
* Java has enormous number of JSON libraries already. I guess it is nice to allow people connect their favorite with minimal efforts. Potentially, if it will be required "string" phase might be excluded (not JSObject->String->POJO, but JSObject->POJO).
* It may simplify logging/debugging of interaction between Java and JS.
/
Best Regards,
Victor
Tony Zakula
2018-04-14 12:43:25 UTC
Permalink
Where is it filed? Curious. We use Jackson and annotations to avoid
circular references.
Post by Victor Polischuk
Hi Sundar,
Thank you for the answer. I have filed a RFE #9053373, with the minimal
intrusion in the API which already should allow people to work with Nashorn
more comfortably.
/Victor
--- Original message ---
oracle.com>
Date: 13 April 2018, 05:47:38
Post by Sundararajan Athijegannathan
Please note that a general Java object graph may involve circular
references. Without modifying JSON somehow, it is not possible to handle
such cases. That said, please do file a rfe with your ideas and we can
discuss.
-Sundar
Post by Victor Polischuk
Dear all,
I apologize if the question was already raised in the mail list,
however, I find it quite strange that JSObject lacks convenient methods to
convert it at least to JSON-string, if not directly to Java-POJOs?
Post by Sundararajan Athijegannathan
Post by Victor Polischuk
The Internet is full of suggestions which involve JavaScript
JSON.stringify(..) as a utility. While it might work too, but I guess a lot
of others are just traversing the JSObject by their own "converters".
Post by Sundararajan Athijegannathan
Post by Victor Polischuk
Therefore, if there is no design limitations/reasons why the
conversion should/could not be applied within the Java representation, I am
ready to volunteer on the patch.
Post by Sundararajan Athijegannathan
Post by Victor Polischuk
* It looks quite ugly to execute JavaScript to make something with
"almost" Java object.
Post by Sundararajan Athijegannathan
Post by Victor Polischuk
* Java has enormous number of JSON libraries already. I guess it is
nice to allow people connect their favorite with minimal efforts.
Potentially, if it will be required "string" phase might be excluded (not
JSObject->String->POJO, but JSObject->POJO).
Post by Sundararajan Athijegannathan
Post by Victor Polischuk
* It may simplify logging/debugging of interaction between Java and JS.
/
Best Regards,
Victor
Loading...