# Class ObjectIdConverter

Namespace
  adas_core.Domain.Utils

Assembly
  adas-core.Domain.dll

Provides a JSON converter for serializing and deserializing MongoDB.Bson.ObjectId values.

    public class ObjectIdConverter : JsonConverter

Inheritance
  object
  JsonConverter
  ObjectIdConverter

Inherited Members
  JsonConverter.CanRead
  JsonConverter.CanWrite
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## Remarks

Inherits from Newtonsoft.Json.JsonConverter to customize JSON representation for the type it targets.

## Methods

### CanConvert(Type)

Determines whether the converter can convert the specified type by checking if the type is assignable from MongoDB.Bson.ObjectId.

    public override bool CanConvert(Type objectType)

#### Parameters

`objectType` Type

  The type to evaluate for compatibility with the converter.

#### Returns

bool

  true if `objectType` can be assigned from MongoDB.Bson.ObjectId; otherwise, false.

### ReadJson(JsonReader, Type, object?, JsonSerializer)

Reads a JSON value and converts it to an MongoDB.Bson.ObjectId instance. When the token is a non-empty string different from the default ObjectId representation and parses successfully, the parsed value is returned; otherwise the method falls back to MongoDB.Bson.ObjectId.Empty for non-nullable target types or `null` for nullable target types.

    public override object? ReadJson(JsonReader reader, Type objectType, object? existingValue, JsonSerializer serializer)

#### Parameters

`reader` JsonReader

  The JSON reader positioned on the value to deserialize.

`objectType` Type

  The target type expected by the deserializer, used to decide between returning MongoDB.Bson.ObjectId.Empty or `null` when the value cannot be parsed.

`existingValue` object

  The existing value being populated, passed through from the deserializer.

`serializer` JsonSerializer

  The JSON serializer invoking this converter.

#### Returns

object

  An MongoDB.Bson.ObjectId instance when the value can be parsed or when the target type is non-nullable; `null` when the target type is nullable and no valid value is found.

### WriteJson(JsonWriter, object?, JsonSerializer)

Serializes an MongoDB.Bson.ObjectId instance to JSON by writing its string representation; if the value is not an MongoDB.Bson.ObjectId, writes a JSON null instead.

    public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)

#### Parameters

`writer` JsonWriter

  The Newtonsoft.Json.JsonWriter used to emit the JSON output.

`value` object

  The value to serialize, expected to be an MongoDB.Bson.ObjectId instance.

`serializer` JsonSerializer

  The Newtonsoft.Json.JsonSerializer invoking this converter.