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

Handle different type property name case #39

Merged
merged 3 commits into from
Apr 17, 2018

Conversation

manuc66
Copy link
Owner

@manuc66 manuc66 commented Apr 16, 2018

Now handle different type property name case
resolve #31
resolve #38

@codecov
Copy link

codecov bot commented Apr 16, 2018

Codecov Report

Merging #39 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #39      +/-   ##
==========================================
+ Coverage   99.37%   99.41%   +0.03%     
==========================================
  Files           3        3              
  Lines         161      170       +9     
==========================================
+ Hits          160      169       +9     
  Misses          1        1
Impacted Files Coverage Δ
JsonSubTypes/JsonSubtypesConverter.cs 100% <100%> (ø) ⬆️
JsonSubTypes/JsonSubtypes.cs 99.21% <100%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 555bd75...95acc66. Read the comment docs.

@manuc66 manuc66 changed the title now handle different type property name as suggested in #31 and #38 Handle different type property name case Apr 16, 2018


var persons = JsonConvert.DeserializeObject<ICollection<Person>>(json);
Assert.AreEqual("Painter", (persons.Last() as Artist)?.Skill);
Copy link

@Pzixel Pzixel Apr 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm suggesting to add yet another Artist with Skill to show that both cases are valid

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I have only seen the diff.

Copy link

@Pzixel Pzixel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm suggesting to add yet another Artist with Skill to show that both cases are valid

@Pzixel
Copy link

Pzixel commented Apr 17, 2018

You can also use predefined phrases such as Fixes #38 to make issue automatically close when PR is merged, see doc: https://help.github.com/articles/closing-issues-using-keywords/

@manuc66
Copy link
Owner Author

manuc66 commented Apr 17, 2018

SonarQube analysis reported 3 issues

Note: The following issues were found on lines that were not modified in the pull request. Because these issues can't be reported as line comments, they are summarized here:

  1. CRITICAL JsonSubtypesConverter.cs#L74: Remove this set, which updates a 'static' field from an instance property. rule
  2. CRITICAL JsonSubtypesConverter.cs#L86: Remove this set, which updates a 'static' field from an instance method. rule
  3. CRITICAL JsonSubtypesConverter.cs#L87: Remove this set, which updates a 'static' field from an instance method. rule

@Pzixel
Copy link

Pzixel commented Apr 17, 2018

Well, Sonar is right, it's not good idea to update static fields from instance methods.

@manuc66
Copy link
Owner Author

manuc66 commented Apr 17, 2018

@Pzixel I would agree but those fields are thread static and it's the only "hack" that I could find to transmit information through stack calls without modifying JSON.NET. And even if it's considered bad practice in general in this particular case it's safe and tested for thread safety, see at least:

public void ConcurrentThreadDeserializeHierachyDeeperTest()

public void TestNestedObjectInBothWayParallel()

public void ConcurrentThreadTest()

If you have a better idea you're really welcome ;-)

@Pzixel
Copy link

Pzixel commented Apr 17, 2018

@manuc66 why not just make it instance fields? In this case it should't be threadlocal. If you consider single instance accessing from different threads just use Interlocked to update values. See https://stackoverflow.com/a/18027246/2559709

@manuc66
Copy link
Owner Author

manuc66 commented Apr 17, 2018

@Pzixel it's per thread instance

@Pzixel
Copy link

Pzixel commented Apr 17, 2018

@manuc66 why should one instance update this value for another one?

@manuc66
Copy link
Owner Author

manuc66 commented Apr 17, 2018

@Pzixel static field annotated with thread local means that each thread has it own value and this library "remember" that the converter has already been called on a thread so that it could delegate the current and subtree de-serialisation to JSON.NET once the subtype information has been discovered. It also handle the case where the converter in invoked in a subtree.

@Pzixel
Copy link

Pzixel commented Apr 17, 2018

@manuc66 thank you, I know what does it mean. I'd like to ask more high level aspect: why should one instance affect another instance in same thread?

@manuc66
Copy link
Owner Author

manuc66 commented Apr 17, 2018

@Pzixel it shouldn't need but should not produce nasty effect since the purpose is to skip the second call to converter once it has already been called and in between there is no possibility to be in another converter instance.

@Pzixel
Copy link

Pzixel commented Apr 17, 2018

@manuc66 I propose to not introduce premature optimization until it's really required.

@manuc66
Copy link
Owner Author

manuc66 commented Apr 17, 2018

@Pzixel I I assure you that the use of thread static has really not been taken inconsiderately from my side. If you think you can solve the problematic with a cleaner approach feel free to submit a PR.

@Pzixel
Copy link

Pzixel commented Apr 17, 2018

@manuc66 if you have some benchmark that shows that it really worth it then I have to arguments why it shouldn't be done this way. Otherwise I suggest either add them or just make it instance fields and check if it works fine.

I'd like to suggest some cleaner solution for the former case too, but I don't really get the whole requirements set yet.

@manuc66
Copy link
Owner Author

manuc66 commented Apr 17, 2018

@Pzixel The benchmark are in the test suite, if you could solve it without breaking the test suite you got it. Currently if you remove [ThreadStatic] static qualifier you have 3 failing tests.

@Pzixel
Copy link

Pzixel commented Apr 17, 2018

Well, if you are this sure about the solution then this warning should be ignored via some attribute or something, I guress.

@manuc66
Copy link
Owner Author

manuc66 commented Apr 17, 2018

@Pzixel The warning popout in pull request but are marked as wont fix/false positive on sonar cloud for the master branch see: https://sonarcloud.io/project/issues?id=manuc66%3AJsonSubtypes%3Amaster&resolutions=WONTFIX&types=CODE_SMELL

@manuc66 manuc66 merged commit e52102e into master Apr 17, 2018
@manuc66 manuc66 deleted the feature/handleDifferentPropertyNameCase branch April 17, 2018 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JsonConverter doesn't respect naming rules Support for both camel case and non camel case parameters
2 participants