title: XStream Error Resolution
body: <p>I'm using a java application to parse some XML using XStream.</p>
  
  <p>The XML is : </p>
  
  <pre><code>&lt;object&gt;
        &lt;name&gt;an Object Name&lt;/name&gt;
        &lt;ncss&gt;154&lt;/ncss&gt;
        &lt;functions&gt;48&lt;/functions&gt;
        &lt;classes&gt;1&lt;/classes&gt;
        &lt;javadocs&gt;44&lt;/javadocs&gt;
      &lt;/object&gt;
  </code></pre>
  
  <p>When parsing this I get the following error :</p>
  
  <pre><code>Exception in thread "main" com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field java.lang.Object.name
  ---- Debugging information ----
  field               : name
  class               : java.lang.Object
  required-type       : java.lang.Object
  converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
  path                : /objects/object/name
  class[1]            : compareObjects.input.Objects
  version             : null
  -------------------------------
      at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.determineType(AbstractReflectionConverter.java:453)
      at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:294)
      at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234)
      at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
      at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
      at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
      at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
      at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:322)
      at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234)
      at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
      at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
      at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
      at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
      at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
      at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
      at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1058)
      at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1042)
      at com.thoughtworks.xstream.XStream.fromXML(XStream.java:913)
      at com.thoughtworks.xstream.XStream.fromXML(XStream.java:904)
      at compareObjects.Logic.mainClass.main(mainClass.java:60)
  </code></pre>
  
  <p>This is due to the fact that my code contains an Object class with a member name , but the JDK is referring to java.lang.Object class , which has no such field.</p>
  
  <p>How do I resolve this conflict ?
  Any help would be welcome.
  Thanks in advance.</p>
  
  <p>Edit : The code for the same is :</p>
  
  <pre><code>package compareObjects.Logic;
  
  
      import java.io.BufferedReader;
      import java.io.File;
      import java.io.FileReader;
      import java.io.IOException;
      import java.util.ArrayList;
  
      import com.thoughtworks.xstream.XStream;
      import com.thoughtworks.xstream.io.xml.DomDriver;
      import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;
  
  import compareObjects.input.*;
  import compareObjects.outPut.changedObject;
  import compareObjects.outPut.changedObjects;
  
  
  
      public class mainClass {
  
      public static void main(String[] args) throws IOException{
  
          BufferedReader br = new BufferedReader(new FileReader(new File("D:\\Object\\old_code_complexity.xml")));
          BufferedReader br2 = new BufferedReader(new FileReader(new File("D:\\Object\\new_code_complexity.xml")));
  
          String line;  //two strings to hold the old and new file's contents
          String line2;
  
  
          StringBuilder sb = new StringBuilder();
          StringBuilder sb2 = new StringBuilder();
  
  
          //Objects representing the output to be stored in XML Format
  
          changedObjects oPack = new changedObjects();
  
          // remove multiple occurrences of space in the xml input file old_code_complexity.xml
          while((line=br.readLine())!= null){
              sb.append(line.trim());
          }
  
          String x = sb.toString();
  
       // remove multiple consecutive occurrences of spaces in contents of new_code_complexity.xml
          while((line2=br2.readLine())!= null){
              sb2.append(line2.trim());
          }
  
          //Create xstream instance to disable xstream from pushing extra _ character as escape sequence
  
          XStream xstream = new XStream(new DomDriver("UTF-8", new XmlFriendlyNameCoder("_-", " ")));
  
          // Create aliases to shorten class names in output file.
  
  
          xstream.alias("objects",Objects.class);
  
          Objects oList = (Objects)xstream.fromXML(x);
  
          String x2 = sb2.toString();
          Objects oList2 = (Objects)xstream.fromXML(x2);
  
  
          for(int i = 0; i&lt; oList.getSize();i++)
          {
             for(int j = 0; j&lt; oList2.getSize();j++)
  
          {
             if(oList.getObject(i).getName().equals(oList2.getObject(j).getName()))
             {
  
                 if(oList.getObject(i).equals(oList2.getObject(j)))
                      {
                        oPack.addSimilarObject(((new changedObject("old_code_complexity.xml",oList.getObject(i),"new_code_complexity.xml",oList2.getObject(j)))));
                      }
              else
              {
                  oPack.addChangedObject(((new changedObject("old_code_complexity.xml",oList.getObject(i),"new_code_complexity.xml",oList2.getObject(j)))));
  
              }
  
           }
            }
  
  
  
          }
  
          System.out.println(xstream.toXML(oPack));
          System.out.println("Objects Changed " + oPack.getDifferentObjects());
          System.out.println("Packages Not Changed" + oPack.getSimilarObjects());
  
      }
      }
  </code></pre>