public String aliasForSystemAttribute(String attribute) { return delegate.aliasForSystemAttribute(attribute); }
public String aliasForSystemAttribute(String attribute) { return aliasForSystemAttributeMapper.aliasForSystemAttribute(attribute); }
public static String readClassAttribute(HierarchicalStreamReader reader, Mapper mapper) { String attributeName = mapper.aliasForSystemAttribute("resolves-to"); String classAttribute = attributeName == null ? null : reader.getAttribute(attributeName); if (classAttribute == null) { attributeName = mapper.aliasForSystemAttribute("class"); if (attributeName != null) { classAttribute = reader.getAttribute(attributeName); } } return classAttribute; }
protected void fireValidReference(Object referenceKey) { String attributeName = getMapper().aliasForSystemAttribute("id"); if (attributeName != null) { writer.addAttribute(attributeName, referenceKey.toString()); } } }
private Class readDeclaringClass(HierarchicalStreamReader reader) { String attributeName = mapper.aliasForSystemAttribute("defined-in"); String definedIn = attributeName == null ? null : reader.getAttribute(attributeName); return definedIn == null ? null : mapper.realClass(definedIn); }
protected Object getCurrentReferenceKey() { String attributeName = getMapper().aliasForSystemAttribute("id"); return attributeName == null ? null : reader.getAttribute(attributeName); } }
@SuppressWarnings("unchecked") public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { String attributeName = mapper.aliasForSystemAttribute("enum-type"); if (attributeName == null) { throw new ConversionException("No EnumType specified for EnumSet"); } Class enumTypeForSet = mapper.realClass(reader.getAttribute(attributeName)); EnumSet set = EnumSet.noneOf(enumTypeForSet); String[] enumValues = reader.getValue().split(","); for (int i = 0; i < enumValues.length; i++) { String enumValue = enumValues[i]; if(enumValue.length() > 0) { set.add(Enum.valueOf(enumTypeForSet, enumValue)); } } return set; }
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 void marshal(Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) { final Object source = serializationMembers.callWriteReplace(original); if (source != original && context instanceof ReferencingMarshallingContext) { ((ReferencingMarshallingContext)context).replace(original, source); } if (source.getClass() != original.getClass()) { String attributeName = mapper.aliasForSystemAttribute("resolves-to"); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(source.getClass())); } context.convertAnother(source); } else { doMarshal(source, writer, context); } }
@Override public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) { final boolean oldFormat = "custom".equals(reader.getAttribute(mapper.aliasForSystemAttribute("serialization"))); if (oldFormat) { reader.moveDown(); reader.moveDown(); } final Map<String, Long> elements = new HashMap<>(); while (reader.hasMoreChildren()) { reader.moveDown(); final String name = reader.getNodeName(); elements.put(oldFormat ? name : mapper.realMember(ValueRange.class, name), Long.valueOf(reader.getValue())); reader.moveUp(); } if (oldFormat) { reader.moveUp(); reader.moveUp(); } return ValueRange.of(elements.get("minSmallest").longValue(), elements.get("minLargest").longValue(), elements .get("maxSmallest") .longValue(), elements.get("maxLargest").longValue()); }
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { InvocationHandler invocationHandler = Proxy.getInvocationHandler(source); addInterfacesToXml(source, writer); writer.startNode("handler"); String attributeName = mapper.aliasForSystemAttribute("class"); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(invocationHandler.getClass())); } context.convertAnother(invocationHandler); writer.endNode(); }
protected static void marshalComparator( Mapper mapper, Comparator comparator, HierarchicalStreamWriter writer, MarshallingContext context) { if (comparator != null) { writer.startNode("comparator"); writer.addAttribute( mapper.aliasForSystemAttribute("class"), mapper.serializedClass(comparator.getClass())); context.convertAnother(comparator); writer.endNode(); } }
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)); } }
@SuppressWarnings("unchecked") public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) { String attributeName = mapper().aliasForSystemAttribute("enum-type"); if (attributeName == null) { throw new ConversionException("No EnumType specified for EnumMap"); } Class type = mapper().realClass(reader.getAttribute(attributeName)); EnumMap map = new EnumMap(type); populateMap(reader, context, map); return map; } }
protected void writeItem(String name, Class type, Object item, MarshallingContext context, HierarchicalStreamWriter writer) { Class itemType = item == null ? Mapper.Null.class : item.getClass(); ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType); if (!itemType.equals(type)) { String attributeName = mapper().aliasForSystemAttribute("class"); if (attributeName != null) { writer.addAttribute(attributeName, mapper().serializedClass(itemType)); } } if (item != null) { context.convertAnother(item); } writer.endNode(); }
/** * @deprecated As of 1.4.11 use {@link #writeCompleteItem(Object, MarshallingContext, HierarchicalStreamWriter)} * instead. */ protected void writeItem(Object item, MarshallingContext context, HierarchicalStreamWriter writer) { final Class itemType = item == null ? Mapper.Null.class : item.getClass(); ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType); if (!itemType.equals(type)) { String attributeName = mapper().aliasForSystemAttribute("class"); if (attributeName != null) { writer.addAttribute(attributeName, mapper().serializedClass(itemType)); } } if (item != null) { context.convertAnother(item); } writer.endNode(); }
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { EnumSet set = (EnumSet) source; Class enumTypeForSet = (Class) Fields.read(typeField, set); String attributeName = mapper.aliasForSystemAttribute("enum-type"); if (attributeName != null) { writer.addAttribute(attributeName, mapper.serializedClass(enumTypeForSet)); } writer.setValue(joinEnumValues(set)); }
protected void marshalComparator(Comparator comparator, HierarchicalStreamWriter writer, MarshallingContext context) { if (comparator != null) { writer.startNode("comparator"); writer.addAttribute(mapper().aliasForSystemAttribute("class"), mapper().serializedClass(comparator.getClass())); context.convertAnother(comparator); writer.endNode(); } }
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Class type = (Class) Fields.read(typeField, source); String attributeName = mapper().aliasForSystemAttribute("enum-type"); if (attributeName != null) { writer.addAttribute(attributeName, mapper().serializedClass(type)); } super.marshal(source, writer, context); }
protected Object instantiateNewInstance(HierarchicalStreamReader reader, UnmarshallingContext context) { String attributeName = mapper.aliasForSystemAttribute("resolves-to"); String readResolveValue = attributeName == null ? null : reader .getAttribute(attributeName); Object currentObject = context.currentObject(); if (currentObject != null) { return currentObject; } else if (readResolveValue != null) { return reflectionProvider.newInstance(mapper.realClass(readResolveValue)); } else { return reflectionProvider.newInstance(context.getRequiredType()); } }