@@ -409,9 +409,9 @@ Object createInstance(JsonObject jsonObj) {
409
409
}
410
410
411
411
// Arrays
412
- Object [] items = jsonObj .getJsonArray ();
412
+ Object items = jsonObj .getJsonArray ();
413
413
if (c .isArray () || (items != null && c == Object .class && !jsonObj .containsKey (KEYS ))) { // Handle []
414
- int size = (items == null ) ? 0 : items . length ;
414
+ int size = (items == null ) ? 0 : Array . getLength ( items ) ;
415
415
mate = Array .newInstance (c .isArray () ? c .getComponentType () : Object .class , size );
416
416
jsonObj .setTarget (mate );
417
417
return mate ;
@@ -498,8 +498,8 @@ private EnumSet<?> extractEnumSet(JsonObject jsonObj) {
498
498
? evaluateEnumSetTypeFromItems (jsonObj )
499
499
: ClassUtilities .forName (enumClassName , readOptions .getClassLoader ());
500
500
501
- Object [] items = jsonObj .getJsonArray ();
502
- if (items == null || items . length == 0 ) {
501
+ Object items = jsonObj .getJsonArray ();
502
+ if (items == null || Array . getLength ( items ) == 0 ) {
503
503
if (enumClass != null ) {
504
504
return EnumSet .noneOf (enumClass );
505
505
} else {
@@ -510,7 +510,9 @@ private EnumSet<?> extractEnumSet(JsonObject jsonObj) {
510
510
}
511
511
512
512
EnumSet enumSet = null ;
513
- for (Object item : items ) {
513
+ int len = Array .getLength (items );
514
+ for (int i =0 ; i < len ; i ++) {
515
+ Object item = Array .get (items , i );
514
516
Enum enumItem ;
515
517
if (item instanceof String ) {
516
518
enumItem = Enum .valueOf (enumClass , (String ) item );
@@ -541,10 +543,11 @@ private EnumSet<?> extractEnumSet(JsonObject jsonObj) {
541
543
*}</pre>
542
544
*/
543
545
private Class <?> evaluateEnumSetTypeFromItems (final JsonObject json ) {
544
- final Object [] items = json .getJsonArray ();
545
- if (items != null && items .length != 0 ) {
546
- if (items [0 ] instanceof JsonObject ) {
547
- return ((JsonObject ) items [0 ]).getJavaType ();
546
+ final Object items = json .getJsonArray ();
547
+ if (items != null && Array .getLength (items ) != 0 ) {
548
+ Object value = Array .get (items , 0 );
549
+ if (value instanceof JsonObject ) {
550
+ return ((JsonObject ) value ).getJavaType ();
548
551
}
549
552
}
550
553
@@ -617,23 +620,25 @@ public boolean valueToTarget(JsonObject jsonObject) {
617
620
// TODO: Support multiple dimensions
618
621
// TODO: Support char
619
622
if (jsonObject .javaType .isArray () && isConvertable (jsonObject .javaType .getComponentType ())) {
620
- Object [] jsonItems = jsonObject .getJsonArray ();
623
+ Object jsonItems = jsonObject .getJsonArray ();
621
624
Class <?> componentType = jsonObject .javaType .getComponentType ();
622
625
if (jsonItems == null ) { // empty array
623
626
jsonObject .setFinishedTarget (null , true );
624
627
return true ;
625
628
}
626
- Object javaArray = Array .newInstance (componentType , jsonItems .length );
627
- for (int i = 0 ; i < jsonItems .length ; i ++) {
629
+ int len = Array .getLength (jsonItems );
630
+ Object javaArray = Array .newInstance (componentType , len );
631
+ for (int i = 0 ; i < len ; i ++) {
628
632
try {
629
633
Class <?> type = componentType ;
630
- if (jsonItems [i ] instanceof JsonObject ) {
631
- JsonObject jObj = (JsonObject ) jsonItems [i ];
634
+ Object item = Array .get (jsonItems , i );
635
+ if (item instanceof JsonObject ) {
636
+ JsonObject jObj = (JsonObject ) item ;
632
637
if (jObj .getJavaType () != null ) {
633
638
type = jObj .getJavaType ();
634
639
}
635
640
}
636
- Array .set (javaArray , i , converter .convert (jsonItems [ i ] , type ));
641
+ Array .set (javaArray , i , converter .convert (item , type ));
637
642
} catch (Exception e ) {
638
643
JsonIoException jioe = new JsonIoException (e .getMessage ());
639
644
jioe .setStackTrace (e .getStackTrace ());
0 commit comments