You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ru...@apache.org on 2001/08/04 21:01:34 UTC

cvs commit: xml-axis/java/test/encoding TestDeser2001.java

rubys       01/08/04 12:01:34

  Modified:    java/src/org/apache/axis/encoding MapSerializer.java
                        SerializationContext.java
               java/test/encoding TestDeser2001.java
  Log:
  Support nil key and values in maps
  
  Revision  Changes    Path
  1.2       +8 -2      xml-axis/java/src/org/apache/axis/encoding/MapSerializer.java
  
  Index: MapSerializer.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/MapSerializer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MapSerializer.java	2001/07/29 13:43:25	1.1
  +++ MapSerializer.java	2001/08/04 19:01:33	1.2
  @@ -59,6 +59,7 @@
   import java.io.IOException;
   import org.xml.sax.*;
   
  +import org.apache.axis.Constants;
   import org.apache.axis.message.SOAPHandler;
   import org.apache.axis.utils.*;
   
  @@ -81,6 +82,7 @@
       // Fixed objects to act as hints to the valueReady() callback
       public static final Object KEYHINT = new Object();
       public static final Object VALHINT = new Object();
  +    public static final Object NILHINT = new Object();
       
       // Our static deserializer factory
       public static class Factory implements DeserializerFactory {
  @@ -149,7 +151,7 @@
                   key = val;
               } else if (hint == VALHINT) {
                   myValue = val;
  -            } else {
  +            } else if (hint != NILHINT) {
                   return;
               }
               numSet++;
  @@ -171,8 +173,12 @@
                                    getDeserializer(typeQName);
               if (dser == null)
                   dser = new Deserializer();
  +
  +            String isNil = attributes.getValue(Constants.URI_2001_SCHEMA_XSI, "nil");
               
  -            if (localName.equals("key")) {
  +            if (isNil != null && isNil.equals("true")) {
  +                dser.registerCallback(this, NILHINT);
  +            } else if (localName.equals("key")) {
                   dser.registerCallback(this, KEYHINT);
               } else if (localName.equals("value")) {
                   dser.registerCallback(this, VALHINT);
  
  
  
  1.28      +11 -2     xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java
  
  Index: SerializationContext.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/SerializationContext.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- SerializationContext.java	2001/08/04 13:37:26	1.27
  +++ SerializationContext.java	2001/08/04 19:01:33	1.28
  @@ -204,6 +204,8 @@
        */
       public boolean isPrimitive(Object value)
       {
  +        if (value == null) return true;
  +
           Class type = value.getClass();
           if (type.isArray()) type = type.getComponentType();
   
  @@ -218,8 +220,15 @@
       public void serialize(QName qName, Attributes attributes, Object value)
           throws IOException
       {
  -        if (value == null)
  -            return;
  +        if (value == null) {
  +            AttributesImpl attrs = new AttributesImpl();
  +            if (attributes != null)
  +                attrs.setAttributes(attributes);
  +            attrs.addAttribute(Constants.URI_2001_SCHEMA_XSI, "nil", "xsi:nil",
  +                               "CDATA", "true");
  +            startElement(qName, attrs);
  +            endElement();
  +        }
           
           if (doMultiRefs && (value != currentSer) && !isPrimitive(value)) {
               if (multiRefIndex == -1)
  
  
  
  1.5       +18 -0     xml-axis/java/test/encoding/TestDeser2001.java
  
  Index: TestDeser2001.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/test/encoding/TestDeser2001.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TestDeser2001.java	2001/07/10 16:05:04	1.4
  +++ TestDeser2001.java	2001/08/04 19:01:34	1.5
  @@ -4,6 +4,7 @@
   import junit.framework.TestCase;
   import java.util.Calendar;
   import java.util.TimeZone;
  +import java.util.HashMap;
   
   /** 
    * Test deserialization of SOAP responses
  @@ -49,6 +50,23 @@
                          "1999-05-31T12:01:30.150-05:00" + 
                        "</result>",
                        date.getTime());
  +    }
  +
  +    public void testMapWithNils() throws Exception {
  +        HashMap m = new HashMap();
  +        m.put(null, new Boolean("false"));
  +        m.put("hi", null);
  +        deserialize("<result xsi:type=\"xmlsoap:Map\" " +
  +                    "xmlns:xmlsoap=\"http://xml.apache.org/xml-soap\"> " +
  +                      "<item>" +
  +                       "<key xsi:nil=\"true\"/>" +
  +                       "<value xsi:type=\"xsd:boolean\">false</value>" + 
  +                      "</item><item>" +
  +                       "<key xsi:type=\"string\">hi</key>" +
  +                       "<value xsi:nil=\"true\"/>" +
  +                      "</item>" +
  +                    "</result>",
  +                    m);
       }
   
   }