Java Code Examples for com.thoughtworks.xstream.mapper.Mapper#Null

The following examples show how to use com.thoughtworks.xstream.mapper.Mapper#Null . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NamedArrayConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
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();
    }
}
 
Example 2
Source File: FontConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void marshal(Object source, HierarchicalStreamWriter writer,
    MarshallingContext context) {
    Font font = (Font)source;
    Map attributes = font.getAttributes();
    if (mapper != null) {
        String classAlias = mapper.aliasForSystemAttribute("class");
        for (Iterator iter = attributes.entrySet().iterator(); iter.hasNext();) {
            Map.Entry entry = (Map.Entry)iter.next();
            String name = textAttributeConverter.toString(entry.getKey());
            Object value = entry.getValue();
            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>
    }
}
 
Example 3
Source File: NamedMapConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 4
Source File: NamedCollectionConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @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();
}
 
Example 5
Source File: AbstractJsonWriter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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(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;
}
 
Example 6
Source File: NullPermission.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public boolean allows(Class type) {
    return type == null || type == Mapper.Null.class;
}