public static Object wrap ( Object o ) { if ( o == null ) { return NULL ; } if ( o instanceof JSONArray || o instanceof JSONObject ) { return o ; } if ( o . equals ( NULL ) ) { return o ; } try { if ( o instanceof Collection ) { return new JSONArray ( ( Collection ) o ) ; } else if ( o . getClass ( ) . isArray ( ) ) { return new JSONArray ( o ) ; } if ( o instanceof Map ) { return new JSONObject ( ( Map ) o ) ; } if ( o instanceof Boolean || o instanceof Byte || o instanceof Character || o instanceof Double || o instanceof Float || o instanceof Integer || o instanceof Long || o instanceof Short || o instanceof String ) { return o ; } } catch ( Exception ignored ) { } return null ; }
Wraps the given object if necessary .