Example usage for jdk.nashorn.internal.scripts JO put

List of usage examples for jdk.nashorn.internal.scripts JO put

Introduction

In this page you can find the example usage for jdk.nashorn.internal.scripts JO put.

Prototype

public Object put(final Object key, final Object value, final boolean strict) 

Source Link

Document

Put a property in the ScriptObject (java.util.Map-like method to help ScriptObjectMirror implementation)

Usage

From source file:com.pivotal.cf.mobile.ats.json.JsonFunctions.java

License:Open Source License

public static Object convert(Object o) {
    if (o instanceof Collection<?>) {
        List<?> original = (List<?>) o;
        Object[] array = original.toArray();
        for (int i = 0; i < array.length; i++) {
            array[i] = convert(array[i]);
        }//  w  w w.  j av  a  2 s  . c  o  m
        return jdk.nashorn.internal.objects.Global.allocate(array);
    } else if (o instanceof Map<?, ?>) {
        jdk.nashorn.internal.scripts.JO jo = new jdk.nashorn.internal.scripts.JO(
                jdk.nashorn.internal.runtime.PropertyMap.newMap());
        ((Map<?, ?>) o).forEach((k, v) -> jo.put(k, convert(v), false));
        return jo;
    } else {
        return o;
    }
}