Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Object.toString alternative. A universal "toString" JavaScript function for any Java Object. Works on nashorn, nudge4j and can be called from Java 8
function toString(oj) {
if (oj == null) return 'null';
if (Java.isJavaObject(oj)==false) return 'Error: not a Java Object';
try {
} catch (e) {
var url = new'');
var ucl = java.lang.Class.forName('');
var addURL = ucl.getDeclaredMethod("addURL", [ url.getClass() ]);
addURL.invoke(java.lang.ClassLoader.getSystemClassLoader(), url );
var MULTI_LINE_STYLE = Java.type('org.apache.commons.lang3.builder.ToStringStyle').MULTI_LINE_STYLE;
var ReflectionToStringBuilder = Java.type('org.apache.commons.lang3.builder.ReflectionToStringBuilder');
return ReflectionToStringBuilder.toString(oj, MULTI_LINE_STYLE, true,true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.