You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by GitBox <gi...@apache.org> on 2022/07/04 03:46:43 UTC

[GitHub] [avro] KalleOlaviNiemitalo commented on a diff in pull request #1728: AVRO-3540: Support dictionaries keyed by types other than string

KalleOlaviNiemitalo commented on code in PR #1728:
URL: https://github.com/apache/avro/pull/1728#discussion_r912605714


##########
lang/csharp/src/apache/main/Reflect/ClassCache.cs:
##########
@@ -249,33 +249,19 @@ public void LoadClassCache(Type objType, Schema s)
                     LoadClassCache(objType.GenericTypeArguments[0], ars.ItemSchema);
                     break;
                 case MapSchema ms:
-                    if (!objType.IsGenericType && !typeof(IDictionary).IsAssignableFrom(objType))
-                    {
-                        throw new AvroException($"Cant map type {objType.Name} to map {ms.Name}");
-                    }
-
-                    if (!objType.IsGenericType)
-                    {
-                        throw new AvroException($"Cant map non-generic type {objType.Name} to map {ms.Name}");
+                    var dictionaryType = FindOpenGenericInterface(typeof(IDictionary<,>), objType);
+                    if (dictionaryType == null)
+                    { 
+                        throw new AvroException($"Can't map type {objType.Name} to map {ms.Name}");

Review Comment:
   I wonder if some of these exceptions should be AvroTypeException. The exception types are not very clearly documented. When I call the Avro library from an application, I end up just catching AvroException and treating all derived types the same.
   
   On the master branch, ClassCache throws only AvroException. I suppose it can then be kept that way in this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@avro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org