public Class defaultImplementationOf(Class type) { return delegate.defaultImplementationOf(type); }
public Class defaultImplementationOf(Class type) { return defaultImplementationOfMapper.defaultImplementationOf(type); }
private Map writeValueToImplicitCollection(UnmarshallingContext context, Object value, Map implicitCollections, Object result, String itemFieldName) { String fieldName = mapper.getFieldNameForItemTypeAndName(context.getRequiredType(), value.getClass(), itemFieldName); if (fieldName != null) { if (implicitCollections == null) { implicitCollections = new HashMap(); // lazy instantiation } Collection collection = (Collection) implicitCollections.get(fieldName); if (collection == null) { Class fieldType = mapper.defaultImplementationOf(reflectionProvider.getFieldType(result, fieldName, null)); if (!Collection.class.isAssignableFrom(fieldType)) { throw new ObjectAccessException("Field " + fieldName + " of " + result.getClass().getName() + " is configured for an implicit Collection, but field is of type " + fieldType.getName()); } if (pureJavaReflectionProvider == null) { pureJavaReflectionProvider = new PureJavaReflectionProvider(); } collection = (Collection)pureJavaReflectionProvider.newInstance(fieldType); reflectionProvider.writeField(result, fieldName, collection, null); implicitCollections.put(fieldName, collection); } collection.add(value); } return implicitCollections; }
protected Class impl(Class interfce) { // special case case classes, they don't get registered as default implementations // only concrete classes do if (interfce == ServiceInfo.class) { return ServiceInfoImpl.class; } if (interfce == StoreInfo.class) { return StoreInfoImpl.class; } if (interfce == ResourceInfo.class) { return ResourceInfoImpl.class; } Class clazz = getXStream().getMapper().defaultImplementationOf(interfce); if (clazz == null) { throw new RuntimeException("No default mapping for " + interfce); } return clazz; }
protected Object createCollection(Class type) { ErrorWritingException ex = null; Class defaultType = mapper().defaultImplementationOf(type); try { return defaultType.newInstance(); } catch (InstantiationException e) { ex = new ConversionException("Cannot instantiate default collection", e); } catch (IllegalAccessException e) { ex = new ObjectAccessException("Cannot instantiate default collection", e); } ex.add("collection-type", type.getName()); ex.add("default-type", defaultType.getName()); throw ex; } }
private void writeField(String propertyName, Class fieldType, Object newObj) { Class actualType = newObj.getClass(); Class defaultType = mapper.defaultImplementationOf(fieldType); String serializedMember = mapper.serializedMember(source.getClass(), propertyName); ExtendedHierarchicalStreamWriterHelper.startNode(writer, serializedMember, actualType); if (!actualType.equals(defaultType) && classAttributeName != null) { writer.addAttribute(classAttributeName, mapper.serializedClass(actualType)); } context.convertAnother(newObj); writer.endNode(); }
private Class determineType(HierarchicalStreamReader reader, boolean validField, Object result, String fieldName, Class definedInCls) { String classAttribute = reader.getAttribute(mapper.aliasForAttribute("class")); Class fieldType = reflectionProvider.getFieldType(result, fieldName, definedInCls); if (classAttribute != null) { Class specifiedType = mapper.realClass(classAttribute); if(fieldType.isAssignableFrom(specifiedType)) // make sure that the specified type in XML is compatible with the field type. // this allows the code to evolve in more flexible way. return specifiedType; } if (!validField) { Class itemType = mapper.getItemTypeForItemFieldName(result.getClass(), fieldName); if (itemType != null) { return itemType; } else { return mapper.realClass(reader.getNodeName()); } } else { return mapper.defaultImplementationOf(fieldType); } }
private void writeField(String fieldName, String aliasName, Class fieldType, Class definedIn, Object newObj) { try { if (!mapper.shouldSerializeMember(definedIn, aliasName)) { return; } ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(definedIn, aliasName), fieldType); Class actualType = newObj.getClass(); Class defaultType = mapper.defaultImplementationOf(fieldType); if (!actualType.equals(defaultType)) { String serializedClassName = mapper.serializedClass(actualType); if (!serializedClassName.equals(mapper.serializedClass(defaultType))) { writer.addAttribute(mapper.aliasForSystemAttribute("class"), serializedClassName); } } if (seenFields.contains(aliasName)) { writer.addAttribute(mapper.aliasForAttribute("defined-in"), mapper.serializedClass(definedIn)); } Field field = reflectionProvider.getField(definedIn,fieldName); marshallField(context, newObj, field); writer.endNode(); } catch (RuntimeException e) { // intercept an exception so that the stack trace shows how we end up marshalling the object in question throw new RuntimeException("Failed to serialize "+definedIn.getName()+"#"+fieldName+" for "+source.getClass(),e); } }
public Object convertAnother(Object parent, Class type, Converter converter) { type = mapper.defaultImplementationOf(type); if (converter == null) { converter = converterLookup.lookupConverterForType(type); } else { if (!converter.canConvert(type)) { ConversionException e = new ConversionException( "Explicit selected converter cannot handle type"); e.add("item-type", type.getName()); e.add("converter-type", converter.getClass().getName()); throw e; } } return convert(parent, type, converter); }
private Class determineType(HierarchicalStreamReader reader, Object result, String fieldName) { final String classAttributeName = classAttributeIdentifier != null ? classAttributeIdentifier : mapper.aliasForSystemAttribute("class"); String classAttribute = classAttributeName == null ? null : reader.getAttribute(classAttributeName); if (classAttribute != null) { return mapper.realClass(classAttribute); } else { return mapper.defaultImplementationOf(beanProvider.getPropertyType(result, fieldName)); } }
collection = new ArraysList(physicalFieldType); } else { Class fieldType = mapper.defaultImplementationOf(physicalFieldType); if (!(Collection.class.isAssignableFrom(fieldType) || Map.class .isAssignableFrom(fieldType))) {
final Class defaultType = mapper.defaultImplementationOf(fieldType[0]); if (!actualType.equals(defaultType)) { final String serializedClassName = mapper.serializedClass(actualType);
public void writeField(String fieldName, String aliasName, Class fieldType, Class definedIn, Object newObj) { Class actualType = newObj != null ? newObj.getClass() : fieldType; ExtendedHierarchicalStreamWriterHelper.startNode(writer, aliasName != null ? aliasName : mapper.serializedMember(sourceType, fieldName), actualType); if (newObj != null) { Class defaultType = mapper.defaultImplementationOf(fieldType); if (!actualType.equals(defaultType)) { String serializedClassName = mapper.serializedClass(actualType); if (!serializedClassName.equals(mapper.serializedClass(defaultType))) { String attributeName = mapper.aliasForSystemAttribute("class"); if (attributeName != null) { writer.addAttribute(attributeName, serializedClassName); } } } final Field defaultField = (Field)defaultFieldDefinition.get(fieldName); if (defaultField.getDeclaringClass() != definedIn) { String attributeName = mapper.aliasForSystemAttribute("defined-in"); if (attributeName != null) { writer.addAttribute( attributeName, mapper.serializedClass(definedIn)); } } Field field = reflectionProvider.getField(definedIn, fieldName); marshallField(context, newObj, field); } writer.endNode(); }
type = mapper.realClass(classAttribute); } else { type = mapper.defaultImplementationOf(reflectionProvider.getFieldType( result, fieldName, classDefiningField));
type = mapper.realClass(classAttribute); } else { type = mapper.defaultImplementationOf(field.getType());
writtenClassWrapper[0] = true; writer.startNode(mapper.serializedClass(currentType[0])); if (currentType[0] != mapper.defaultImplementationOf(currentType[0])) { String classAttributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS); if (classAttributeName != null) { if (currentType[0] != mapper.defaultImplementationOf(currentType[0])) { String classAttributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS); if (classAttributeName != null) {
ExtendedHierarchicalStreamWriterHelper.startNode( writer, mapper.serializedMember(source.getClass(), field.getName()), actualType); Class defaultType = mapper.defaultImplementationOf(field.getType()); if (!actualType.equals(defaultType)) { String attributeName = mapper.aliasForSystemAttribute(ATTRIBUTE_CLASS);
public void defaultReadObject() { if (serializationMembers.getSerializablePersistentFields(currentType[0]) != null) { readFieldsFromStream(); return; } if (!reader.hasMoreChildren()) { return; } reader.moveDown(); if (!reader.getNodeName().equals(ELEMENT_DEFAULT)) { throw new ConversionException("Expected <" + ELEMENT_DEFAULT + "/> element in readObject() stream"); } while (reader.hasMoreChildren()) { reader.moveDown(); String fieldName = mapper.realMember(currentType[0], reader.getNodeName()); if (mapper.shouldSerializeMember(currentType[0], fieldName)) { String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); final Class type; if (classAttribute != null) { type = mapper.realClass(classAttribute); } else { type = mapper.defaultImplementationOf(reflectionProvider.getFieldType(result, fieldName, currentType[0])); } Object value = context.convertAnother(result, type); reflectionProvider.writeField(result, fieldName, value, currentType[0]); } reader.moveUp(); } reader.moveUp(); }
String classAttribute = HierarchicalStreams.readClassAttribute(reader, mapper); if (classAttribute == null) { currentType[0] = mapper.defaultImplementationOf(mapper.realClass(nodeName)); } else { currentType[0] = mapper.realClass(classAttribute);
private Class<?> determineType(HierarchicalStreamReader reader, Object result, String fieldName) { final String classAttributeName = mapper.attributeForAlias("class"); String classAttribute = reader.getAttribute(classAttributeName); if (classAttribute != null) { return mapper.realClass(classAttribute); } else { return mapper.defaultImplementationOf(beanProvider.getPropertyType( result, fieldName)); } } }