public void visitArray(Object array, Type arrayType) {
   assignToRoot(new JsonArray());
   int length = Array.getLength(array);
   TypeInfoArray fieldTypeInfo = TypeInfoFactory.getTypeInfoForArray(arrayType);
   Type componentType = fieldTypeInfo.getSecondLevelType();
   for (int i = 0; i < length; ++i) {
     Object child = Array.get(array, i);
     Type childType = componentType;
     // we should not get more specific component type yet since it is possible
     // that a custom
     // serializer is registered for the componentType
     addAsArrayElement(new ObjectTypePair(child, childType, false));
   }
 }
示例#2
0
 private void navigateClassFields(Object obj, Class<?> clazz, Visitor visitor) {
   Field[] fields = clazz.getDeclaredFields();
   AccessibleObject.setAccessible(fields, true);
   for (Field f : fields) {
     FieldAttributes fieldAttributes = new FieldAttributes(clazz, f);
     if (exclusionStrategy.shouldSkipField(fieldAttributes)
         || exclusionStrategy.shouldSkipClass(fieldAttributes.getDeclaredClass())) {
       continue; // skip
     }
     TypeInfo fieldTypeInfo = TypeInfoFactory.getTypeInfoForField(f, objTypePair.type);
     Type declaredTypeOfField = fieldTypeInfo.getActualType();
     boolean visitedWithCustomHandler =
         visitor.visitFieldUsingCustomHandler(fieldAttributes, declaredTypeOfField, obj);
     if (!visitedWithCustomHandler) {
       if (fieldTypeInfo.isArray()) {
         visitor.visitArrayField(fieldAttributes, declaredTypeOfField, obj);
       } else {
         visitor.visitObjectField(fieldAttributes, declaredTypeOfField, obj);
       }
     }
   }
 }