avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Fengyun RAO <raofeng...@gmail.com>
Subject Re: Error reading map type in C# version but not java version
Date Fri, 16 May 2014 06:43:17 GMT
I finally find a way to make it work, although ugly:

using (var reader = DataFileReader<Dictionary<string, MyType>>.OpenReader(
stream,
CACHE_SCHEMA,
(writerSchema, readerSchema) => new SpecificReader<Dictionary<string,
MyType>>(writerSchema, readerSchema)))
{
  while (reader.HasNext())
  {
     reader.Next(); // Here reads right.
  }
}

2014-05-15 20:15 GMT+08:00, Fengyun RAO <raofengyun@gmail.com>:
> 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#?
>


-- 
----------------------------------------------------------------
RAO Fengyun
Center for Astrophysics, Tsinghua University
Tel: +86 13810626496
Email: raofengyun@gmail.com
          rfy02@mails.tsinghua.edu.cn
-----------------------------------------------------------------

Mime
View raw message