MCPcopy Create free account
hub / github.com/jwtk/jjwt / toObjectArray

Method toObjectArray

api/src/main/java/io/jsonwebtoken/lang/Objects.java:255–275  ·  view source on GitHub ↗

Convert the given array (which may be a primitive array) to an object array (if necessary of primitive wrapper objects). A null source value will be converted to an empty Object array. @param source the (potentially primitive) array @return the corresponding object array (never <cod

(Object source)

Source from the content-addressed store, hash-verified

253 * @throws IllegalArgumentException if the parameter is not an array
254 */
255 public static Object[] toObjectArray(Object source) {
256 if (source instanceof Object[]) {
257 return (Object[]) source;
258 }
259 if (source == null) {
260 return new Object[0];
261 }
262 if (!source.getClass().isArray()) {
263 throw new IllegalArgumentException("Source is not an array: " + source);
264 }
265 int length = Array.getLength(source);
266 if (length == 0) {
267 return new Object[0];
268 }
269 Class wrapperType = Array.get(source, 0).getClass();
270 Object[] newArray = (Object[]) Array.newInstance(wrapperType, length);
271 for (int i = 0; i < length; i++) {
272 newArray[i] = Array.get(source, i);
273 }
274 return newArray;
275 }
276
277
278 //---------------------------------------------------------------------

Callers 2

arrayToListMethod · 0.95

Calls 3

isArrayMethod · 0.80
newInstanceMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected