I need to serialize a Lucene.net Document instance. When I try the following
public bool Serialize(Document doc)
{
XmlSerializer serializer = new XmlSerializer(doc.GetType());
TextWriter writer = new StreamWriter(Path.Combine(_indexPath, String.Format("{0}{1}",Guid.NewGuid().ToString(), ".xml")));
serializer.Serialize(writer, doc);
writer.Close();
return true;
}
I receive an exception because the Lucene Field type doesn’t have a parameterless constructor.
"Lucene.Net.Documents.Field cannot be serialized because it does not have a parameterless constructor."
Any way around this? Is there a more generally accepted way of serializing a Lucene.Net document?
Even if you could, It wouldn’t help you much since
Document‘s all members are java style getXXX/setXXX methods(not properties or fields). The simplest way would be to form Field/Value pairs by yourself and then serialize them.For example, you can fill & serialize
MyDocumentclass