-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
NEST/Elasticsearch.Net version: 6.4.0
Elasticsearch version: 6.2.2
Description: I want to use $type only on root object. I tried to use ContractResolver from this
answer but it didn't work. Then I tried to modify this resolver, even threw exceptions from it but it didn't change anything. Seems like it is not used at all.
Client creation:
ConnectionSettings.SourceSerializerFactory sourceSerializerFactory = (builtin, setts) => new JsonNetSerializer(
builtin, setts,
() => new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All,
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = SuppressItemTypeNameContractResolver.Instance,
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple,
}
);
var connectionSettings =
new ConnectionSettings(connectionPool, sourceSerializer: sourceSerializerFactory);
Resolver:
public class SuppressItemTypeNameContractResolver : DefaultContractResolver
{
static SuppressItemTypeNameContractResolver()
{
Instance = new SuppressItemTypeNameContractResolver();
}
public static SuppressItemTypeNameContractResolver Instance { get; }
protected override JsonContract CreateContract(Type objectType)
{
var contract = base.CreateContract(objectType);
if (contract is JsonContainerContract containerContract)
{
if (containerContract.ItemTypeNameHandling == null)
containerContract.ItemTypeNameHandling = TypeNameHandling.None;
}
return contract;
}
}
Metadata
Metadata
Assignees
Labels
No labels