My data type is Dictionary<String, MyType>, I serialize it using:
var datumWriter = new SpecificDatumWriter<Dictionary<string,
MyType>>(CACHE_SCHEMA);using (var writer =
DataFileWriter<Dictionary<string, MyType>>.OpenWriter(datumWriter,
stream)){
writer.Append(dictionary);}
I deserialize it using:
using (var reader = DataFileReader<Dictionary<string,
MyType>>.OpenReader(stream, CACHE_SCHEMA)){
while (reader.HasNext())
{
reader.Next(); // Here throws an EXCEPTION.
}}
The Exception says sth like : System.InvalidCastException:
System.Collections.Generic.Dictionary`2[System.String,System.Object]
to System.Collections.Generic.Dictionary`2[System.String,MyType]”
I understand the reader gets a Dictionay<string, object> and failed to
converts it to Dictionary<string, MyType>.
While in java, I deserialize it using:
DatumReader<Map<String, MyType>> datumReader = new
SpecificDatumReader<>(CACHE_SCHEMA);
try (DataFileStream<Map<String, MyType>> dataFileStream = new
DataFileStream<>(inputStream, datumReader)) {
while (dataFileStream.hasNext()) {
dataFileStream.next(); // Here reads right.
}}
Since java version works fine, I guess both the data and schema are
correct, then how to deserialize in C#?