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

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

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

Mapper.serializedMember介绍

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

代码示例

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

public String serializedMember(Class type, String memberName) {
  return delegate.serializedMember(type, memberName);
}

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

public String serializedMember(Class type, String memberName) {
  return serializedMemberMapper.serializedMember(type, memberName);
}

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

private void write(final String fieldName, final long value, final HierarchicalStreamWriter writer) {
    ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(ValueRange.class, fieldName),
      long.class);
    writer.setValue(String.valueOf(value));
    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

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: 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

@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
  final WeekFields weekFields = (WeekFields)source;
  ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(WeekFields.class,
    "minimalDays"), int.class);
  writer.setValue(String.valueOf(weekFields.getMinimalDaysInFirstWeek()));
  writer.endNode();
  ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(WeekFields.class,
    "firstDayOfWeek"), DayOfWeek.class);
  context.convertAnother(weekFields.getFirstDayOfWeek());
  writer.endNode();
}

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

@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
  final Clock clock = (Clock)source;
  ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper.serializedMember(Clock.class, "zone"), null);
  context.convertAnother(clock.getZone());
  writer.endNode();
}

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

public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
  Field field = (Field) source;
  Class type = field.getDeclaringClass();
  writer.startNode("name");
  writer.setValue(mapper.serializedMember(type, field.getName()));
  writer.endNode();
  writer.startNode("clazz");
  writer.setValue(javaClassConverter.toString(type));
  writer.endNode();
}

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

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

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

fieldName, type, definedIn);
if (converter != null) {
  final String attribute = mapper.aliasForAttribute(mapper.serializedMember(
    definedIn, fieldName));
  if (value != null) {

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

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

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

final String alias = mapper.serializedMember(definedIn, fieldName);
if (!defaultFieldDefinition.containsKey(alias)) {
  final Class lookupType = sourceType;

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

writer, mapper.serializedMember(source.getClass(), field.getName()), actualType);
Class defaultType = mapper.defaultImplementationOf(field.getType());
if (!actualType.equals(defaultType)) {

代码示例来源:origin: x-stream/xstream

private void write(final String fieldName, final long value, final HierarchicalStreamWriter writer) {
    writer.startNode(mapper.serializedMember(ValueRange.class, fieldName), long.class);
    writer.setValue(String.valueOf(value));
    writer.endNode();
  }
}

代码示例来源:origin: org.apache.shindig/shindig-common

private void writeField(String propertyName, String aliasName,
   Class<?> fieldType, Class<?> definedIn, Object newObj) {
  ExtendedHierarchicalStreamWriterHelper.startNode(writer, mapper
    .serializedMember(source.getClass(), aliasName), fieldType);
  context.convertAnother(newObj);
  writer.endNode();
 }
});

代码示例来源:origin: x-stream/xstream

private void writeField(final String propertyName, final Class<?> fieldType, final Object newObj) {
  final Class<?> actualType = newObj.getClass();
  final Class<?> defaultType = mapper.defaultImplementationOf(fieldType);
  final String serializedMember = mapper.serializedMember(source.getClass(), propertyName);
  writer.startNode(serializedMember, actualType);
  if (!actualType.equals(defaultType) && classAttributeName != null) {
    writer.addAttribute(classAttributeName, mapper.serializedClass(actualType));
  }
  context.convertAnother(newObj);
  writer.endNode();
}

代码示例来源:origin: x-stream/xstream

@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
  final WeekFields weekFields = (WeekFields)source;
  writer.startNode(mapper.serializedMember(WeekFields.class, "minimalDays"), int.class);
  writer.setValue(String.valueOf(weekFields.getMinimalDaysInFirstWeek()));
  writer.endNode();
  writer.startNode(mapper.serializedMember(WeekFields.class, "firstDayOfWeek"), DayOfWeek.class);
  context.convertAnother(weekFields.getFirstDayOfWeek());
  writer.endNode();
}

代码示例来源:origin: x-stream/xstream

@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
  final Clock clock = (Clock)source;
  writer.startNode(mapper.serializedMember(Clock.class, "zone"), null);
  context.convertAnother(clock.getZone());
  writer.endNode();
}

代码示例来源:origin: x-stream/xstream

@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
  final Field field = (Field)source;
  final Class<?> type = field.getDeclaringClass();
  writer.startNode("name");
  writer.setValue(mapper.serializedMember(type, field.getName()));
  writer.endNode();
  writer.startNode("clazz");
  writer.setValue(javaClassConverter.toString(type));
  writer.endNode();
}

相关文章