From b68d955bc41c9ef13afda378fab2266e2bf894b9 Mon Sep 17 00:00:00 2001 From: Greg Marzouka Date: Sat, 6 Sep 2014 20:13:51 -0400 Subject: [PATCH] Remove class/interface validation when retrieving type from ElasticType Since #731, this was causing an ArgumentException to be thrown when mapping generic objects with value type parameters (List, Dictionary, etc..). The check doesn't seem necessary since ElasticTypeAttribute is already constained to classes at compile time. Also cleaned up PropertyNameResolver a bit. Closes #926 --- src/Nest/Resolvers/PropertyNameResolver.cs | 13 ------- .../Nest.Tests.Unit/Nest.Tests.Unit.csproj | 1 + .../Reproduce/Reproduce926Tests.cs | 39 +++++++++++++++++++ 3 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 src/Tests/Nest.Tests.Unit/Reproduce/Reproduce926Tests.cs diff --git a/src/Nest/Resolvers/PropertyNameResolver.cs b/src/Nest/Resolvers/PropertyNameResolver.cs index 99a695cca53..08c246c1256 100644 --- a/src/Nest/Resolvers/PropertyNameResolver.cs +++ b/src/Nest/Resolvers/PropertyNameResolver.cs @@ -32,25 +32,12 @@ public static IElasticPropertyAttribute Property(MemberInfo info) return null; } - public static ElasticTypeAttribute Type() where T : class - { - return _Type(typeof(T)); - } - public static ElasticTypeAttribute Type(Type type) - { - return _Type(type); - } - - private static ElasticTypeAttribute _Type(Type type) { ElasticTypeAttribute attr = null; if (CachedTypeLookups.TryGetValue(type, out attr)) return attr; - if (!type.IsClass && !type.IsInterface) - throw new ArgumentException("Type is not a class or interface", "type"); - var attributes = type.GetCustomAttributes(typeof(ElasticTypeAttribute), true); if (attributes.HasAny()) attr = ((ElasticTypeAttribute)attributes.First()); diff --git a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj index 4f278821972..64bc68a8699 100644 --- a/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj +++ b/src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj @@ -377,6 +377,7 @@ + diff --git a/src/Tests/Nest.Tests.Unit/Reproduce/Reproduce926Tests.cs b/src/Tests/Nest.Tests.Unit/Reproduce/Reproduce926Tests.cs new file mode 100644 index 00000000000..4f569bc35a8 --- /dev/null +++ b/src/Tests/Nest.Tests.Unit/Reproduce/Reproduce926Tests.cs @@ -0,0 +1,39 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Nest.Tests.Unit.Reproduce +{ + class SomeClass + { + public SomeClass() + { + this.Data = new Dictionary(); + } + + public long ID { get; set; } + + [ElasticProperty(Type = FieldType.Object)] + public Dictionary Data { get; set; } + } + + class SomeOtherClass + { + public string Value1 { get; set; } + public string Value2 { get; set; } + } + + [TestFixture] + public class Reproduce926Tests : BaseJsonTests + { + [Test] + public void ObjectMappingOnDictionaryCausesArgumentException() + { + var mapResult = this._client.Map(m => m + .MapFromAttributes()); + } + } +}