Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lyndaidaii opened this issue Mar 29, 2022 · 6 comments
Closed
Labels
area-System.Text.Json needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration

Comments

@lyndaidaii
Copy link

lyndaidaii commented Mar 29, 2022

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

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Mar 29, 2022
@ghost
Copy link

ghost commented Mar 29, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

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

ExampleList
{
HashSet set;
example(){
set = new HashSet(StringComparison.OrdinalIgnoreCase)
}
}

json contains a list of string.
exampleList = JsonSerializer.Deserialize(json);
exampleList.set is case sensitive

Expected behavior

expected to be case insensitive.

Actual behavior

HashSet is case sensitive

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: lyndaidaii
Assignees: -
Labels:

area-System.Text.Json, untriaged

Milestone: -

@danmoseley
Copy link
Member

@lyndaidaii can you please update your sample with a minimal, runnable repro example? BTW you can use triple back ticks above and below to format as code.

@eiriktsarpalis
Copy link
Member

Likely related to #30258. System.Text.Json does not currently support appending elements to properties with existing collections and we're looking to get this addressed in .NET 7.

@eiriktsarpalis eiriktsarpalis added the needs-author-action An issue or pull request that requires more info or actions from the author. label Mar 30, 2022
@ghost
Copy link

ghost commented Mar 30, 2022

This issue has been marked needs-author-action since it may be missing important information. Please refer to our contribution guidelines for tips on how to report issues effectively.

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Mar 30, 2022
@lyndaidaii
Copy link
Author

Likely related to #30258. System.Text.Json does not currently support appending elements to properties with existing collections and we're looking to get this addressed in .NET 7.

It's related to issue #30258, anyway, I updated the example above

@ghost ghost added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed needs-author-action An issue or pull request that requires more info or actions from the author. labels Mar 30, 2022
@eiriktsarpalis
Copy link
Member

Closing as duplicate of #30258. I should point out that the PropertyNameCaseInsensitive concerns matching JSON properties to POCO properties, and does not have any impact on the case sensitivity of deserialized dictionary types.

@ghost ghost locked as resolved and limited conversation to collaborators May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration
Projects
None yet
Development

No branches or pull requests

3 participants