Skip to content

System.Text.json deserialize doesn't support case insensitive Hashset  #67311

Closed
@lyndaidaii

Description

@lyndaidaii

Description

We initialized hashset with case insensitive in object, we used system.text.json deserialize content from json file to object.
Noticed that Hashset was case sensitive, not insensitive as expected

Reproduction Steps

public class Config
{
  public HashSet<string>Set {get; set;}
  public Config(){
      Set = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
  } 

// json contains a list of string. 
public class initialize
{
  var options = new JsonSerializerOptions
  {
      PropertyNameCaseInsensitive = true
  };
  Config config = JsonSerializer.Deserialize<Config>(json, options);
}

Expected behavior

expected to be case insensitive.

Actual behavior

HashSet is case sensitive

Regression?

No response

Known Workarounds

public class Config
{
  public HashSet<string>Set {get;}
  public Config(HashSet<string> set){
      Set = new HashSet<string>(set, StringComparer.OrdinalIgnoreCase);
  } 

// json contains a list of string. 
public class initialize
{
  var options = new JsonSerializerOptions
  {
      PropertyNameCaseInsensitive = true
  };
  Config config = JsonSerializer.Deserialize<Config>(json, options);
}

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Text.Jsonneeds-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions