﻿using Utf8Json;

namespace Nest
{
	internal class RelationNameFormatter : IJsonFormatter<RelationName>
	{
		public RelationName Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
		{
			if (reader.GetCurrentJsonToken() == JsonToken.String)
			{
				RelationName relationName = reader.ReadString();
				return relationName;
			}

			return null;
		}

		public void Serialize(ref JsonWriter writer, RelationName value, IJsonFormatterResolver formatterResolver)
		{
			if (value == null)
			{
				writer.WriteNull();
				return;
			}

			var settings = formatterResolver.GetConnectionSettings();
			writer.WriteString(settings.Inferrer.RelationName(value));
		}
	}
}

﻿using Utf8Json;

namespace Nest
{
	internal class RelationNameFormatter : IJsonFormatter<RelationName>, IObjectPropertyNameFormatter<RelationName>
	{
		public RelationName Deserialize(ref JsonReader reader, IJsonFormatterResolver formatterResolver)
		{
			if (reader.GetCurrentJsonToken() == JsonToken.String)
			{
				RelationName relationName = reader.ReadString();
				return relationName;
			}

			return null;
		}

		public void Serialize(ref JsonWriter writer, RelationName value, IJsonFormatterResolver formatterResolver)
		{
			if (value == null)
			{
				writer.WriteNull();
				return;
			}

			var settings = formatterResolver.GetConnectionSettings();
			writer.WriteString(settings.Inferrer.RelationName(value));
		}

		public void SerializeToPropertyName(ref JsonWriter writer, RelationName value, IJsonFormatterResolver formatterResolver) =>
			Serialize(ref writer, value, formatterResolver);

		public RelationName DeserializeFromPropertyName(ref JsonReader reader, IJsonFormatterResolver formatterResolver) =>
			Deserialize(ref reader, formatterResolver);
	}
}

Support RelationName as dictionary key
Support RelationName as dictionary key
