# HG changeset patch # Parent 698e9f1d6348fc1066ceaac7d264cbbf63bdcd21 diff --git a/src/main/java/org/yaml/snakeyaml/introspector/PropertyUtils.java b/src/main/java/org/yaml/snakeyaml/introspector/PropertyUtils.java --- a/src/main/java/org/yaml/snakeyaml/introspector/PropertyUtils.java +++ b/src/main/java/org/yaml/snakeyaml/introspector/PropertyUtils.java @@ -15,11 +15,7 @@ */ package org.yaml.snakeyaml.introspector; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; import java.lang.reflect.Field; -import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Collection; import java.util.HashMap; @@ -37,64 +33,31 @@ private BeanAccess beanAccess = BeanAccess.DEFAULT; private boolean allowReadOnlyProperties = false; - protected Map getPropertiesMap(Class type, BeanAccess bAccess) - throws IntrospectionException { + protected Map getPropertiesMap(Class type, BeanAccess bAccess) { if (propertiesCache.containsKey(type)) { return propertiesCache.get(type); } Map properties = new LinkedHashMap(); - boolean inaccessableFieldsExist = false; - switch (bAccess) { - case FIELD: - for (Class c = type; c != null; c = c.getSuperclass()) { - for (Field field : c.getDeclaredFields()) { - int modifiers = field.getModifiers(); - if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers) - && !properties.containsKey(field.getName())) { - properties.put(field.getName(), new FieldProperty(field)); - } + for (Class c = type; c != null; c = c.getSuperclass()) { + for (Field field : c.getDeclaredFields()) { + int modifiers = field.getModifiers(); + if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers) + && !properties.containsKey(field.getName())) { + properties.put(field.getName(), new FieldProperty(field)); } } - break; - default: - // add JavaBean properties - for (PropertyDescriptor property : Introspector.getBeanInfo(type) - .getPropertyDescriptors()) { - Method readMethod = property.getReadMethod(); - if (readMethod == null || !readMethod.getName().equals("getClass")) { - properties.put(property.getName(), new MethodProperty(property)); - } - } + } - // add public fields - for (Class c = type; c != null; c = c.getSuperclass()) { - for (Field field : c.getDeclaredFields()) { - int modifiers = field.getModifiers(); - if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)) { - if (Modifier.isPublic(modifiers)) { - properties.put(field.getName(), new FieldProperty(field)); - } else { - inaccessableFieldsExist = true; - } - } - } - } - break; - } - if (properties.isEmpty() && inaccessableFieldsExist) { - throw new YAMLException("No JavaBean properties found in " + type.getName()); - } propertiesCache.put(type, properties); return properties; } - public Set getProperties(Class type) throws IntrospectionException { + public Set getProperties(Class type) { return getProperties(type, beanAccess); } - public Set getProperties(Class type, BeanAccess bAccess) - throws IntrospectionException { + public Set getProperties(Class type, BeanAccess bAccess) { if (readableProperties.containsKey(type)) { return readableProperties.get(type); } @@ -103,8 +66,7 @@ return properties; } - protected Set createPropertySet(Class type, BeanAccess bAccess) - throws IntrospectionException { + protected Set createPropertySet(Class type, BeanAccess bAccess) { Set properties = new TreeSet(); Collection props = getPropertiesMap(type, bAccess).values(); for (Property property : props) { @@ -115,13 +77,11 @@ return properties; } - public Property getProperty(Class type, String name) - throws IntrospectionException { + public Property getProperty(Class type, String name) { return getProperty(type, name, beanAccess); } - public Property getProperty(Class type, String name, BeanAccess bAccess) - throws IntrospectionException { + public Property getProperty(Class type, String name, BeanAccess bAccess) { Map properties = getPropertiesMap(type, bAccess); Property property = properties.get(name); if (property == null || !property.isWritable()) {