Skip to content

Map keys of custom types should serialize using MarshalText when available #461

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

Merged
merged 2 commits into from
May 8, 2020

Conversation

styeung
Copy link
Contributor

@styeung styeung commented May 5, 2020

This is to address the issue filed here.

@codecov
Copy link

codecov bot commented May 5, 2020

Codecov Report

Merging #461 into master will decrease coverage by 0.41%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #461      +/-   ##
==========================================
- Coverage   86.63%   86.22%   -0.42%     
==========================================
  Files          41       41              
  Lines        5103     5103              
==========================================
- Hits         4421     4400      -21     
- Misses        541      562      +21     
  Partials      141      141              
Impacted Files Coverage Δ
reflect_map.go 87.37% <87.50%> (-0.49%) ⬇️
reflect_struct_decoder.go 82.42% <0.00%> (-2.67%) ⬇️

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 0f8241d...a275d40. Read the comment docs.

@AllenX2018
Copy link
Collaborator

Thanks for the bug report and the patch.

  1. Could you please also check if map keys of custom types are deserialized correctly? I think they may have the similar problem
  2. Can you move the test case to value_tests/map_test.go?

- this brings unmarshaling behavior in line with encoding/json
- in general, any types that implement the interfaces from the encoding package (TextUnmarshaler, TextMarshaler, etc.) should use the provided method when available 
- this commit also moves test cases from jsoniter_map_test.go to value/tests/map_test.go
@styeung
Copy link
Contributor Author

styeung commented May 6, 2020

Thanks for the feedback.

  1. Yes, turns out unmarshal had the same problem as well. Updated the decoderOfMapKey method correct this behavior.
  2. Tests moved

@styeung
Copy link
Contributor Author

styeung commented May 8, 2020

@AllenX2018 ping!

@AllenX2018 AllenX2018 merged commit 8961be9 into json-iterator:master May 8, 2020
@AllenX2018
Copy link
Collaborator

Merged, Thanks!

zhenzou pushed a commit to zhenzou/jsoniter that referenced this pull request Feb 2, 2022
…lable (json-iterator#461)

* Map keys of custom types should serialize/deserialize using MarshalText/UnmarshalText when available

- this brings marshaling/unmarshaling behavior in line with encoding/json
- in general, any types that implement the interfaces from the encoding package (TextUnmarshaler, TextMarshaler, etc.) should use the provided method when available
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.

2 participants