/** * Locates a property descriptor. * * @param type * @param name * @throws MissingFieldException if property does not exist */ public PropertyDescriptor propertyDescriptor(Class type, String name) { PropertyDescriptor descriptor = propertyDescriptorOrNull(type, name); if (descriptor == null) { throw new MissingFieldException(type.getName(), name); } return descriptor; }
/** * Returns an specific field of some class. If definedIn is null, it searches for the field named 'name' inside the * class cls. If definedIn is different than null, tries to find the specified field name in the specified class cls * which should be defined in class definedIn (either equals cls or a one of it's superclasses) * * @param cls the class where the field is to be searched * @param name the field name * @param definedIn the superclass (or the class itself) of cls where the field was defined * @return the field itself * @throws ObjectAccessException if no field can be found */ public Field field(final Class cls, final String name, final Class definedIn) { final Field field = fieldOrNull(cls, name, definedIn); if (field == null) { throw new MissingFieldException(cls.getName(), name); } else { return field; } }
/** * Locates a serializable property. * * @param cls * @param name * @deprecated As of 1.3.1, use {@link #propertyDescriptor(Class, String)} instead */ public BeanProperty property(Class cls, String name) { BeanProperty beanProperty = null; PropertyDescriptor descriptor = propertyDescriptorOrNull(cls, name); if (descriptor == null) { throw new MissingFieldException(cls.getName(), name); } if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) { beanProperty = new BeanProperty( cls, descriptor.getName(), descriptor.getPropertyType()); } return beanProperty; }
public void writeFieldsToStream(Map fields) { ObjectStreamClass objectStreamClass = ObjectStreamClass.lookup(currentType[0]); writer.startNode(ELEMENT_DEFAULT); for (Iterator iterator = fields.keySet().iterator(); iterator.hasNext();) { String name = (String) iterator.next(); if (!mapper.shouldSerializeMember(currentType[0], name)) { continue; } ObjectStreamField field = objectStreamClass.getField(name); Object value = fields.get(name); if (field == null) { throw new MissingFieldException(value.getClass().getName(), name); } if (value != null) { ExtendedHierarchicalStreamWriterHelper.startNode( writer, mapper.serializedMember(source.getClass(), name), value.getClass()); if (field.getType() != value.getClass() && !field.getType().isPrimitive()) { String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(value.getClass())); } } context.convertAnother(value); writer.endNode(); } } writer.endNode(); }
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { final Object result = instantiateNewInstance(context); final Set seenProperties = new HashSet() { public boolean add(Object e) { if (!super.add(e)) { throw new DuplicatePropertyException(((FastField)e).getName()); } return true; } }; Class resultType = result.getClass(); while (reader.hasMoreChildren()) { reader.moveDown(); String propertyName = mapper.realMember(resultType, reader.getNodeName()); if (mapper.shouldSerializeMember(resultType, propertyName)) { boolean propertyExistsInClass = beanProvider.propertyDefinedInClass(propertyName, resultType); if (propertyExistsInClass) { Class type = determineType(reader, result, propertyName); Object value = context.convertAnother(result, type); beanProvider.writeProperty(result, propertyName, value); seenProperties.add(new FastField(resultType, propertyName)); } else if (!mapper.isIgnoredElement(propertyName)) { throw new MissingFieldException(resultType.getName(), propertyName); } } reader.moveUp(); } return result; }
ObjectStreamField field = objectStreamClass.getField(name); if (field == null) { throw new MissingFieldException(currentType[0].getName(), name);
/** * Locates a property descriptor. * * @param type * @param name */ public PropertyDescriptor propertyDescriptor(Class type, String name) { PropertyDescriptor descriptor = (PropertyDescriptor)buildMap(type).get(name); if (descriptor == null) { throw new MissingFieldException(type.getName(), name); } return descriptor; }
/** * Locates a property descriptor. * * @param type * @param name * @throws MissingFieldException if property does not exist */ public PropertyDescriptor propertyDescriptor(final Class<?> type, final String name) { final PropertyDescriptor descriptor = propertyDescriptorOrNull(type, name); if (descriptor == null) { throw new MissingFieldException(type.getName(), name); } return descriptor; }
/** * Locates a property descriptor. * * @param type * @param name */ public PropertyDescriptor propertyDescriptor(Class type, String name) { PropertyDescriptor descriptor = (PropertyDescriptor)buildMap(type).get(name); if (descriptor == null) { throw new MissingFieldException(type.getName(), name); } return descriptor; }
/** * Locates a property descriptor. * * @param type * @param name * @throws MissingFieldException if property does not exist */ public PropertyDescriptor propertyDescriptor(Class type, String name) { PropertyDescriptor descriptor = propertyDescriptorOrNull(type, name); if (descriptor == null) { throw new MissingFieldException(type.getName(), name); } return descriptor; }
/** * Locates a property descriptor. * * @param type * @param name * @throws MissingFieldException if property does not exist */ public PropertyDescriptor propertyDescriptor(Class type, String name) { PropertyDescriptor descriptor = propertyDescriptorOrNull(type, name); if (descriptor == null) { throw new MissingFieldException(type.getName(), name); } return descriptor; }
/** * Locates a property descriptor. * * @param type * @param name * @throws MissingFieldException if property does not exist */ public PropertyDescriptor propertyDescriptor(Class type, String name) { PropertyDescriptor descriptor = propertyDescriptorOrNull(type, name); if (descriptor == null) { throw new MissingFieldException(type.getName(), name); } return descriptor; }
/** * Returns an specific field of some class. If definedIn is null, it searches for the field named 'name' inside the * class cls. If definedIn is different than null, tries to find the specified field name in the specified class cls * which should be defined in class definedIn (either equals cls or a one of it's superclasses) * * @param cls the class where the field is to be searched * @param name the field name * @param definedIn the superclass (or the class itself) of cls where the field was defined * @return the field itself * @throws ObjectAccessException if no field can be found */ public Field field(final Class<?> cls, final String name, final Class<?> definedIn) { final Field field = fieldOrNull(cls, name, definedIn); if (field == null) { throw new MissingFieldException(cls.getName(), name); } else { return field; } }
/** * Returns an specific field of some class. If definedIn is null, it searches for the field named 'name' inside the * class cls. If definedIn is different than null, tries to find the specified field name in the specified class cls * which should be defined in class definedIn (either equals cls or a one of it's superclasses) * * @param cls the class where the field is to be searched * @param name the field name * @param definedIn the superclass (or the class itself) of cls where the field was defined * @return the field itself * @throws ObjectAccessException if no field can be found */ public Field field(final Class cls, final String name, final Class definedIn) { final Field field = fieldOrNull(cls, name, definedIn); if (field == null) { throw new MissingFieldException(cls.getName(), name); } else { return field; } }
/** * Returns an specific field of some class. If definedIn is null, it searches for the field * named 'name' inside the class cls. If definedIn is different than null, tries to find the * specified field name in the specified class cls which should be defined in class * definedIn (either equals cls or a one of it's superclasses) * * @param cls the class where the field is to be searched * @param name the field name * @param definedIn the superclass (or the class itself) of cls where the field was defined * @return the field itself * @throws ObjectAccessException if no field can be found */ public Field field(Class cls, String name, Class definedIn) { Field field = fieldOrNull(cls, name, definedIn); if (field == null) { throw new MissingFieldException(cls.getName(), name); } else { return field; } }
/** * Locates a serializable property. * * @param cls * @param name * @deprecated As of 1.3.1, use {@link #propertyDescriptor(Class, String)} instead */ public BeanProperty property(Class cls, String name) { BeanProperty beanProperty = null; PropertyDescriptor descriptor = propertyDescriptorOrNull(cls, name); if (descriptor == null) { throw new MissingFieldException(cls.getName(), name); } if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) { beanProperty = new BeanProperty( cls, descriptor.getName(), descriptor.getPropertyType()); } return beanProperty; }
/** * Locates a serializable property. * * @param cls * @param name * @deprecated As of 1.3.1, use {@link #propertyDescriptor(Class, String)} instead */ @Deprecated public BeanProperty property(final Class<?> cls, final String name) { BeanProperty beanProperty = null; final PropertyDescriptor descriptor = propertyDescriptorOrNull(cls, name); if (descriptor == null) { throw new MissingFieldException(cls.getName(), name); } if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) { beanProperty = new BeanProperty(cls, descriptor.getName(), descriptor.getPropertyType()); } return beanProperty; }
/** * Locates a serializable property. * * @param cls * @param name * @deprecated As of 1.3.1, use {@link #propertyDescriptor(Class, String)} instead */ public BeanProperty property(Class cls, String name) { BeanProperty beanProperty = null; PropertyDescriptor descriptor = (PropertyDescriptor)buildMap(cls).get(name); if (descriptor == null) { throw new MissingFieldException(cls.getName(), name); } if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) { beanProperty = new BeanProperty( cls, descriptor.getName(), descriptor.getPropertyType()); } return beanProperty; }
/** * Locates a serializable property. * * @param cls * @param name * @deprecated As of 1.3.1, use {@link #propertyDescriptor(Class, String)} instead */ public BeanProperty property(Class cls, String name) { BeanProperty beanProperty = null; PropertyDescriptor descriptor = (PropertyDescriptor)buildMap(cls).get(name); if (descriptor == null) { throw new MissingFieldException(cls.getName(), name); } if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) { beanProperty = new BeanProperty( cls, descriptor.getName(), descriptor.getPropertyType()); } return beanProperty; }
/** * Locates a serializable property. * * @param cls * @param name * @deprecated As of 1.3.1, use {@link #propertyDescriptor(Class, String)} instead */ public BeanProperty property(Class cls, String name) { BeanProperty beanProperty = null; PropertyDescriptor descriptor = propertyDescriptorOrNull(cls, name); if (descriptor == null) { throw new MissingFieldException(cls.getName(), name); } if (descriptor.getReadMethod() != null && descriptor.getWriteMethod() != null) { beanProperty = new BeanProperty( cls, descriptor.getName(), descriptor.getPropertyType()); } return beanProperty; }