01: /*
02: * Copyright (C) 2003, 2004 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 03. October 2003 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.converters.basic;
13:
14: import com.thoughtworks.xstream.converters.Converter;
15: import com.thoughtworks.xstream.converters.MarshallingContext;
16: import com.thoughtworks.xstream.converters.UnmarshallingContext;
17: import com.thoughtworks.xstream.io.HierarchicalStreamReader;
18: import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
19: import com.thoughtworks.xstream.io.ExtendedHierarchicalStreamWriterHelper;
20: import com.thoughtworks.xstream.mapper.Mapper;
21:
22: /**
23: * Special converter to signify nulls at the root level.
24: *
25: * @author Joe Walnes
26: */
27: public class NullConverter implements Converter {
28:
29: public boolean canConvert(Class type) {
30: return type == null || Mapper.Null.class.isAssignableFrom(type);
31: }
32:
33: public void marshal(Object source, HierarchicalStreamWriter writer,
34: MarshallingContext context) {
35: ExtendedHierarchicalStreamWriterHelper.startNode(writer,
36: "null", null);
37: writer.endNode();
38: }
39:
40: public Object unmarshal(HierarchicalStreamReader reader,
41: UnmarshallingContext context) {
42: return null;
43: }
44: }
|