XStream
  1. XStream
  2. XSTR-579

omitField does not omit a field while unserializing

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.1
    • Fix Version/s: 1.4
    • Component/s: Converters
    • Labels:
      None
    • JDK version and platform:
      IcedTea 1.70 for Linux

      Description

      In my program, I serialize some objects which contain a field called "scenario". Depending on the case, I sometimes do not want this fiels to be unserialized. So, in these cases, I call xstream.omitField(MyClass.class, "scenario").

      But the program still try to unserialize this field. I think that the problem comes from JavaBeanConverter.java, in fact, the shouldSerializeMember function is not called before the attempt to unserialize the object. I'm short on time so I can't make a minimal testcase before 2 or 3 days. Here is a proposed patch (I couldn't test it because I have some problems with apache Harmony) :

      JavaBeanConverter.java
          public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
              final Object result = instantiateNewInstance(context);
      
              while (reader.hasMoreChildren()) {
                  reader.moveDown();
      
                  String propertyName = mapper.realMember(result.getClass(), reader.getNodeName());
      
                  boolean propertyExistsInClass = beanProvider.propertyDefinedInClass(propertyName, result.getClass());
      
                  if (mapper.shouldSerializeMember(result.getClass(), propertyName)) {
                  	if (propertyExistsInClass) {
                  		Class type = determineType(reader, result, propertyName);
                  		Object value = context.convertAnother(result, type);
                  		beanProvider.writeProperty(result, propertyName, value);
                  	} else {
                  		throw new ConversionException("Property '" + propertyName + "' not defined in class " + result.getClass().getName());
                  	}
                  }
      
                  reader.moveUp();
              }
      
              return result;
          }
      

        Issue Links

          People

          • Assignee:
            Jörg Schaible
            Reporter:
            Alexandre Abraham
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: