question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Search SDK: FieldBuilder tries to read a property marked with JsonIgnore

See original GitHub issue

We are using Microsoft.Azure.Search.dll (3.0.0) from NuGet Package 3.0.3

Here are our Interfaces:

public interface IResourceSearchDocument
{
	string RecordType { get; set; }
	string Title { get; set; }
	string Description { get; set; }
	DateTime? PublishedDate { get; set; }
	DateTime? LastUpdatedDate { get; set; }
	string ImageUrl { get; set; }
	string LinkToResource { get; set; }
}
	
public interface IEventSearchDocument
{
	string EventId { get; set; }
	string ProductId { get; set; }
	string EventCode { get; set; }
	string EventType { get; set; }
	string Location { get; set; }
	DateTime? EventStartDate { get; set; }
	DateTime? EventEndDate { get; set; }
}

This is our base class:

[SerializePropertyNamesAsCamelCase]
public abstract class SearchDocument : ISearchDocument
{
	/// <summary>
	/// Gets or sets the ID for the document. For consistency, this should never be updated or retrieved manually.
	/// All IDs should be set through the <see cref="Id"/> property.
	/// </summary>
	[Key]
	[JsonProperty("Id")]
	public string AzureId { get; set; }

	/// <summary>
	/// Gets or sets any unique IDs or compound IDs that might contain characters unsafe for transmission via URL.
	/// For consistency, all IDs should be set through this property.
	/// </summary>
	[JsonIgnore]
	[IsRetrievable(false)]
	public string Id
	{
		get
		{
			return AzureId.FromBase64EncodedString();
		}
		set
		{
			AzureId = value.ToBase64EncodedString();
		}
	}
}

Finally, this is the WebSiteSearchDocument:

[SerializePropertyNamesAsCamelCase]
public class WebSearchDocument : SearchDocument, IEventSearchDocument, IResourceSearchDocument
{
	#region Implementation of IEventSearchDocument
	[IsRetrievable(true)]
	public string EventId { get; set; }
	[IsRetrievable(true)]
	public string ProductId { get; set; }
	[IsRetrievable(true)]
	public string EventCode { get; set; }
	[IsRetrievable(true), IsFilterable]
	public string EventType { get; set; }
	public string Location { get; set; }
	[IsRetrievable(true), IsFilterable]
	public DateTime? EventStartDate { get; set; }
	[IsRetrievable(true), IsFilterable]
	public DateTime? EventEndDate { get; set; }

	#endregion Implementation of IEventSearchDocument

	#region Implementation of IResourceSearchDocument
	[IsRetrievable(true), IsFilterable]
	public string RecordType { get; set; }

	[JsonIgnore]
	[IsRetrievable(false)]
	public WebSearchRecordType RecordTypeEnum { get; set; }

	[IsRetrievable(true), IsSearchable]
	public string Title { get; set; }
	[IsRetrievable(true), IsSearchable]
	public string Description { get; set; }
	[IsRetrievable(true)]
	public DateTime? PublishedDate { get; set; }
	[IsRetrievable(true)]
	public DateTime? LastUpdatedDate { get; set; }
	[IsRetrievable(true)]
	public string ImageUrl { get; set; }
	[IsRetrievable(true)]
	public string LinkToResource { get; set; }

	#endregion Implementation of IResourceSearchDocument
}

We have set up an IndexManager and this method is called to ‘Create the Index’:

public Index Create<T>(string indexName) where T : class, ISearchDocument
{
	if (Exists(indexName))
	{
		throw new ArgumentException($"An index by the name of {indexName} already exists.", nameof(indexName));
	}

	var indexDefinition = new Index
	{
		Name = indexName,
		Fields = FieldBuilder.BuildForType<T>()
	};

	return _serviceClient.Indexes.Create(indexDefinition);
}

This is the exception we are getting back when we try to set the enum to JsonIgnore and IsRetrievable(false)

{“Property recordTypeEnum has unsupported type BACP.Web.Search.WebSearchRecordType\r\nParameter name: propertyType”} Data: {System.Collections.ListDictionaryInternal} HResult: -2147024809 HelpLink: null IPForWatsonBuckets: {140706498970467} InnerException: null IsTransient: false Message: “Property recordTypeEnum has unsupported type BACP.Web.Search.WebSearchRecordType\r\nParameter name: propertyType” ParamName: “propertyType” RemoteStackTrace: null Source: “Microsoft.Azure.Search” StackTrace: " at Microsoft.Azure.Search.FieldBuilder.GetDataType(Type propertyType, String propertyName)\r\n at Microsoft.Azure.Search.FieldBuilder.BuildForType[T](IContractResolver contractResolver)\r\n at Felinesoft.Search.IndexManager.<CreateAsync>d__51.MoveNext() in E:\\Felinesoft\\BACP\\DEV\\WEB\\BACP.Web\\Felinesoft.Search\\IndexManager.cs:line 86\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()\r\n at Felinesoft.Search.IndexManager.<RebuildAsync>d__7`1.MoveNext() in E:\Felinesoft\BACP\DEV\WEB\BACP.Web\Felinesoft.Search\IndexManager.cs:line 117\r\n— End of stack trace from previous location where exception was thrown —\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtim e.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at BACP.Web.Presentation.Infrastructure.Azure.SearchIndexBuilder.<>c__DisplayClass26_0.<<GetAsyncIndexBuilders>b__4>d.MoveNext() in E:\Felinesoft\BACP\DEV\WEB\BACP.Web\BACP.Web.Presentation\Infrastructure\Azure\SearchIndexBuilder.cs:line 180\r\n— End of stack trace from previous location where exception was thrown —\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at BACP.Web.Presentation.Controllers.AzureSearchToolsController.<RebuildIndex>d__6.MoveNext() in E:\Felinesoft\BACP\DEV\WEB\BACP.Web\BACP.Web.Presentation\Controllers\AzureSearchToolsController.cs:line 52" TargetSite: {Microsoft.Azure.Search.Models.DataType GetDataType(System.Type, System.String)} WatsonBuckets: null _HResult: -2147024809 _className: null _data: {System.Collections.ListDictionaryInternal} _dynamicMethods: null _exceptionMethod: {Microsoft.Azure.Search.Models.DataType GetDataType(System.Type, System.String)} _exceptionMethodString: null _helpURL: null _innerException: null _ipForWatsonBuckets: {140706498970467} _message: “Property recordTypeEnum has unsupported type BACP.Web.Search.WebSearchRecordType” _remoteStackIndex: 0 _remoteStackTraceString: null _safeSerializationManager: {System.Runtime.Serialization.SafeSerializationManager} _source: “Microsoft.Azure.Search” _stackTrace: {sbyte[768]} _stackTraceString: null _watsonBuckets: null _xcode: -532462766 _xptrs: {0} m_paramName: “propertyType”

It is my understanding that putting the JsonIgnore and IsRetrievable(false) attributes on the RecordTypeEnum property, then the Microsoft.Azure.Search.Models.DataType GetDataType(System.Type, System.String) should ignore it.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brjohnstmsftcommented, Feb 6, 2018

The fix for this issue shipped with version 3.0.5 to NuGet.

1reaction
Ganstedcommented, Dec 7, 2017

To make your workaround slightly more generic you could change

properties = properties.Where(p => p.PropertyName != "prices").ToList();

to

properties = properties.Where(p => !p.Ignored).ToList();

That way all properties marked with the JsonIgnore attribute will be ignored when building your fields.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Throw error when properties marked with @JsonIgnore are ...
I tried setting spring.jackson.deserialization.fail-on-unknown-properties=true , but that works only for properties that are truly unknown. The ...
Read more >
FieldBuilderIgnoreAttribute Class (Microsoft.Azure.Search)
This attribute is useful in situations where a property definition doesn't cleanly map to a Field object, but its values still need to...
Read more >
JsonIgnore Annotation in Java
The @JsonIgnore annotation is used to mark a property or a method that should be ignored by Jackson when serializing or deserializing a...
Read more >
PipelineOptions (Apache Beam 2.27.0)
Each property within PipelineOptions must be able to be serialized using Jackson's ObjectMapper or the getter method for the property annotated with @JsonIgnore...
Read more >
Subdocument mutation doesn't respect @JsonIgnore
I have an class with a property marked with @JsonIgnore annotation. This class is one of the data members of a couchbase document....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found