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

unmarshal: support encoding.TextUnmarshaler #375

Merged
merged 4 commits into from
May 4, 2020

Conversation

oncilla
Copy link
Contributor

@oncilla oncilla commented Apr 25, 2020

This PR adds support for decoding fields of primitive types that implement
encoding.TextUnmarshaler by calling the custom method.

Fields in anonymous structs are not supported at this point.

fixes #329

@codecov
Copy link

codecov bot commented Apr 25, 2020

Codecov Report

Merging #375 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #375      +/-   ##
==========================================
+ Coverage   95.09%   95.12%   +0.02%     
==========================================
  Files          10       10              
  Lines        2202     2214      +12     
==========================================
+ Hits         2094     2106      +12     
  Misses         68       68              
  Partials       40       40              
Impacted Files Coverage Δ
marshal.go 94.54% <100.00%> (+0.10%) ⬆️

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 2b8e33f...2b9b2f7. Read the comment docs.

This PR adds support for decoding fields of primitive types that implement
encoding.TextUnmarshaler by calling the custom method.

Fields in anonymous structs are not supported at this point.
@oncilla
Copy link
Contributor Author

oncilla commented Apr 28, 2020

@pelletier I rebased on top of master.
I don't really know how to improve the code coverage.

One miss I can see is from:

func (d *Decoder) unmarshalText(tval interface{}, mval reflect.Value) error { 
	...
	default:
		return fmt.Errorf("unspported type: %t", val)
	...

But that should never executed, if the parser does not have a bug. Should I just put a panic there?
I think writing a test that actually triggers this error path is pretty brittle and does not really add value.

I did not figure out where the second miss comes from.

marshal.go Outdated Show resolved Hide resolved
marshal.go Outdated Show resolved Hide resolved
oncilla and others added 3 commits April 29, 2020 18:01
As suggested by @lmb

Co-Authored-By: Lorenz Bauer <lmb@users.noreply.github.com>
@pelletier
Copy link
Owner

Looks good to me! Thanks for taking care of it. Sorry it took me a while to get to it!

@pelletier pelletier merged commit e29a498 into pelletier:master May 4, 2020
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.

allow custom struct unmarshal with UnmarshalText
3 participants