本文整理汇总了Java中com.thoughtworks.xstream.mapper.Mapper.Null方法的典型用法代码示例。如果您正苦于以下问题:Java Mapper.Null方法的具体用法?Java Mapper.Null怎么用?Java Mapper.Null使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.thoughtworks.xstream.mapper.Mapper
的用法示例。
在下文中一共展示了Mapper.Null方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: marshal
import com.thoughtworks.xstream.mapper.Mapper; //导入方法依赖的package包/类
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final int length = Array.getLength(source);
for (int i = 0; i < length; ++i) {
final Object item = Array.get(source, i);
final Class<?> itemType = item == null ? Mapper.Null.class : arrayType.getComponentType().isPrimitive()
? Primitives.unbox(item.getClass())
: item.getClass();
ExtendedHierarchicalStreamWriterHelper.startNode(writer, itemName, itemType);
if (!itemType.equals(arrayType.getComponentType())) {
final String attributeName = mapper.aliasForSystemAttribute("class");
if (attributeName != null) {
writer.addAttribute(attributeName, mapper.serializedClass(itemType));
}
}
if (item != null) {
context.convertAnother(item);
}
writer.endNode();
}
}
示例2: marshal
import com.thoughtworks.xstream.mapper.Mapper; //导入方法依赖的package包/类
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final Font font = (Font)source;
final Map<TextAttribute, ?> attributes = font.getAttributes();
if (mapper != null) {
final String classAlias = mapper.aliasForSystemAttribute("class");
for (final Map.Entry<TextAttribute, ?> entry : attributes.entrySet()) {
final String name = textAttributeConverter.toString(entry.getKey());
final Object value = entry.getValue();
final Class<?> type = value != null ? value.getClass() : Mapper.Null.class;
ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, type);
writer.addAttribute(classAlias, mapper.serializedClass(type));
if (value != null) {
context.convertAnother(value);
}
writer.endNode();
}
} else {
writer.startNode("attributes"); // <attributes>
context.convertAnother(attributes);
writer.endNode(); // </attributes>
}
}
示例3: writeItem
import com.thoughtworks.xstream.mapper.Mapper; //导入方法依赖的package包/类
protected void writeItem(final String name, final Class<?> type, final Object item,
final MarshallingContext context, final HierarchicalStreamWriter writer) {
final Class<?> itemType = item == null ? Mapper.Null.class : item.getClass();
ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType);
if (!itemType.equals(type)) {
final String attributeName = mapper().aliasForSystemAttribute("class");
if (attributeName != null) {
writer.addAttribute(attributeName, mapper().serializedClass(itemType));
}
}
if (item != null) {
context.convertAnother(item);
}
writer.endNode();
}
示例4: writeItem
import com.thoughtworks.xstream.mapper.Mapper; //导入方法依赖的package包/类
@Override
protected void writeItem(final Object item, final MarshallingContext context, final HierarchicalStreamWriter writer) {
final Class<?> itemType = item == null ? Mapper.Null.class : item.getClass();
ExtendedHierarchicalStreamWriterHelper.startNode(writer, name, itemType);
if (!itemType.equals(type)) {
final String attributeName = mapper().aliasForSystemAttribute("class");
if (attributeName != null) {
writer.addAttribute(attributeName, mapper().serializedClass(itemType));
}
}
if (item != null) {
context.convertAnother(item);
}
writer.endNode();
}
示例5: allows
import com.thoughtworks.xstream.mapper.Mapper; //导入方法依赖的package包/类
@Override
public boolean allows(Class<?> type) {
return type == null || type == Mapper.Null.class;
}
示例6: unmarshal
import com.thoughtworks.xstream.mapper.Mapper; //导入方法依赖的package包/类
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
TreeSet<Object> result = null;
final TreeMap<?, ?> treeMap;
final Comparator<?> unmarshalledComparator = treeMapConverter.unmarshalComparator(reader, context, null);
final boolean inFirstElement = unmarshalledComparator instanceof Mapper.Null;
@SuppressWarnings("unchecked")
final Comparator<Object> comparator = inFirstElement ? null : (Comparator<Object>)unmarshalledComparator;
if (sortedMapField != null) {
final TreeSet<Object> possibleResult = comparator == null ? new TreeSet<Object>() : new TreeSet<Object>(
comparator);
Object backingMap = null;
try {
backingMap = sortedMapField.get(possibleResult);
} catch (final IllegalAccessException e) {
throw new ConversionException("Cannot get backing map of TreeSet", e);
}
if (backingMap instanceof TreeMap) {
treeMap = (TreeMap<?, ?>)backingMap;
result = possibleResult;
} else {
treeMap = null;
}
} else {
treeMap = null;
}
if (treeMap == null) {
final PresortedSet<Object> set = new PresortedSet<Object>(comparator);
result = comparator == null ? new TreeSet<Object>() : new TreeSet<Object>(comparator);
if (inFirstElement) {
// we are already within the first element
addCurrentElementToCollection(reader, context, result, set);
reader.moveUp();
}
populateCollection(reader, context, result, set);
if (set.size() > 0) {
result.addAll(set); // comparator will not be called if internally optimized
}
} else {
treeMapConverter.populateTreeMap(reader, context, treeMap, unmarshalledComparator);
}
return result;
}
示例7: unmarshal
import com.thoughtworks.xstream.mapper.Mapper; //导入方法依赖的package包/类
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
final Map<TextAttribute, Object> attributes;
if (reader.hasMoreChildren()) {
reader.moveDown();
if (!reader.getNodeName().equals("attributes")) {
final String classAlias = mapper.aliasForSystemAttribute("class");
attributes = new HashMap<TextAttribute, Object>();
do {
if (!attributes.isEmpty()) {
reader.moveDown();
}
final Class<?> type = mapper.realClass(reader.getAttribute(classAlias));
final TextAttribute attribute = (TextAttribute)textAttributeConverter.fromString(reader.getNodeName());
final Object value = type == Mapper.Null.class ? null : context.convertAnother(null, type);
attributes.put(attribute, value);
reader.moveUp();
} while (reader.hasMoreChildren());
} else {
// in <attributes>
@SuppressWarnings("unchecked")
final Map<TextAttribute, Object> typedAttributes = (Map<TextAttribute, Object>)context.convertAnother(
null, Map.class);
attributes = typedAttributes;
reader.moveUp(); // out of </attributes>
}
} else {
attributes = Collections.emptyMap();
}
for (final Iterator<?> iter = attributes.values().iterator(); iter.hasNext();) {
if (iter.next() == null) {
iter.remove();
}
}
final Font font = Font.getFont(attributes);
if (context.getRequiredType() == FontUIResource.class) {
return new FontUIResource(font);
} else {
return font;
}
}
示例8: getType
import com.thoughtworks.xstream.mapper.Mapper; //导入方法依赖的package包/类
/**
* Method to return the appropriate JSON type for a Java type.
*
* @param clazz the type
* @return One of the {@link Type} instances
* @since 1.4.4
*/
protected Type getType(final Class<?> clazz) {
return clazz == Mapper.Null.class ? Type.NULL : clazz == Boolean.class || clazz == Boolean.TYPE
? Type.BOOLEAN
: NUMBER_TYPES.contains(clazz) ? Type.NUMBER : Type.STRING;
}