com.thoughtworks.xstream.mapper.Mapper.serializedClass()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中com.thoughtworks.xstream.mapper.Mapper.serializedClass()方法的一些代码示例,展示了Mapper.serializedClass()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mapper.serializedClass()方法的具体详情如下:
包路径:com.thoughtworks.xstream.mapper.Mapper
类名称:Mapper
方法名:serializedClass

Mapper.serializedClass介绍

[英]How a class name should be represented in its serialized form.
[中]类名应如何以序列化形式表示。

代码示例

代码示例来源:origin: jenkinsci/jenkins

public String serializedClass(Class type) {
  return delegate.serializedClass(type);
}

代码示例来源:origin: geoserver/geoserver

@Override
  public String serializedClass(final Class type) {
    return wrapped.serializedClass(type);
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public String serializedClass(Class type) {
  return serializedClassMapper.serializedClass(type);
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public String toString(Object obj) {
  return mapper.serializedClass(((Class) obj));
}

代码示例来源:origin: AxonFramework/AxonFramework

/**
 * Returns the type identifier for the given {@code type}. It uses the aliasing rules configured in XStream.
 *
 * @param type The type to get the type identifier of
 * @return A String containing the type identifier of the given class
 */
private String typeIdentifierOf(Class<?> type) {
  return xStream.getMapper().serializedClass(type);
}

代码示例来源:origin: jenkinsci/jenkins

public void marshal(Object original, final HierarchicalStreamWriter writer, final MarshallingContext context) {
  final Object source = serializationMethodInvoker.callWriteReplace(original);
  if (source.getClass() != original.getClass()) {
    writer.addAttribute(mapper.aliasForAttribute("resolves-to"), mapper.serializedClass(source.getClass()));
  }
  OwnerContext oc = OwnerContext.find(context);
  oc.startVisiting(writer, classOwnership.ownerOf(original.getClass()));
  try {
    doMarshal(source, writer, context);
  } finally {
    oc.stopVisiting();
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
  Map map = (Map) source;
  String entryName = mapper().serializedClass(Map.Entry.class);
  for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
    Map.Entry entry = (Map.Entry) iterator.next();
    ExtendedHierarchicalStreamWriterHelper.startNode(writer, entryName, entry.getClass());
    writeCompleteItem(entry.getKey(), context, writer);
    writeCompleteItem(entry.getValue(), context, writer);
    writer.endNode();
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

private void addInterfacesToXml(Object source, HierarchicalStreamWriter writer) {
  Class[] interfaces = source.getClass().getInterfaces();
  for (int i = 0; i < interfaces.length; i++) {
    Class currentInterface = interfaces[i];
    writer.startNode("interface");
    writer.setValue(mapper.serializedClass(currentInterface));
    writer.endNode();
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public void start(Object item, DataHolder dataHolder) {
  this.dataHolder = dataHolder;
  if (item == null) {
    writer.startNode(mapper.serializedClass(null));
    writer.endNode();
  } else {
    ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper
      .serializedClass(item.getClass()), item.getClass());
    convertAnother(item);
    writer.endNode();
  }
}

代码示例来源:origin: jenkinsci/jenkins

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);
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

private void writeNullField(final String propertyName) {
    final String serializedMember = mapper.serializedMember(source.getClass(), propertyName);
    ExtendedHierarchicalStreamWriterHelper.startNode(writer, serializedMember, Mapper.Null.class);
    writer.addAttribute(classAttributeName, mapper.serializedClass(Mapper.Null.class));
    writer.endNode();
  }
});

代码示例来源:origin: com.thoughtworks.xstream/xstream

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();
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public void writeToStream(final Object object) {
  if (object == null) {
    writer.startNode("null");
    writer.endNode();
  } else {
    ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedClass(object.getClass()), object.getClass());
    context.convertAnother(object);
    writer.endNode();
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

public void writeToStream(Object object) {
  if (object == null) {
    writer.startNode(ELEMENT_NULL);
    writer.endNode();
  } else {
    ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedClass(object.getClass()), object.getClass());
    context.convertAnother(object);
    writer.endNode();
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

/**
 * Write a null item of the collection into the writer. The method readItem should be able to process the written
 * data i.e. it has to write the tags or may not write anything at all.
 *
 * @param context the current marshalling context
 * @param writer the target writer
 * @since 1.4.11
 */
protected void writeNullItem(final MarshallingContext context, final HierarchicalStreamWriter writer) {
  final String name = mapper().serializedClass(null);
  ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, Mapper.Null.class);
  writer.endNode();
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

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();
}

代码示例来源:origin: geoserver/geoserver

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();
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

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));
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

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();
  }
}

代码示例来源:origin: com.thoughtworks.xstream/xstream

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);
}

相关文章