Skip to content

Add TypeConverter for JsonPointer, JsonPath, etc. to allow easy configuration binding #585

@wazzamatazz

Description

@wazzamatazz

Nuget Package

JsonPointer.Net

Package Version

3.2.2

Can this library make doing something simpler?

When using the .NET configuration system, it is not currently possible to bind an entry from an IConfiguration to a JsonPointer on an options class. For example, the following always results in a null value for the MyPointer member on the MyOptions class:

// appsettings.json
{
  "MyOptions": {
    "MyPointer": "/some/pointer"
  }
}
// Application code

public class MyOptions {
  public JsonPointer MyPointer { get; set; }
}

// ...

void AddMyOptions(IServiceCollection services, IConfiguration configuration) {
  services.AddOptions<MyOptions>().Bind(configuration.GetSection("MyOptions"));
}

The .NET configuration binder uses TypeConverters to convert from strings to the target target type. By adding TypeConverter implementations for types such as JsonPointer and JsonPath it would allow options classes to easily make use of the types in this repository.

Describe alternatives you've considered.

No response

Is there any other information you'd like to share regarding this enhancement?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions