Repository: go
Issue: proposal: net: add MarshalText/UnmarshalText to IPMask
Labels: Proposal

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
1.14.6
</pre>

### Does this issue reproduce with the latest release?

Yes

### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/cswanson/Library/Caches/go-build"
GOENV="/Users/cswanson/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/cswanson/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/cswanson/go/src/github.com/golang/go/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wb/vtqrcvns4h7ghfrl_m75_z7c0000gn/T/go-build009589323=/tmp/go-build -gno-record-gcc-switches -fno-common"
</pre></details>

### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->

I'm trying to json marshal and unmarshal `net.IPNet` objects, but the `net.IPMask` object currently does not support marshalling to text formats in a human readable/parsable format.  When a `net.IPMask` object is attempted to be json marshalled, it is currently being transformed from a byte slice to a base64 string (as per the `encode/json` standards).

Here's an example:
https://play.golang.org/p/EGjSJeVQ9W-

Right now I am working around this, through type aliasing and methods, but it would be nice if this were either in its hex format, that it is displayed as in when using the `String` method to keep with backwards compatibility.
This seems to be a somewhat known issue to some regard as it is mentioned within a previous issue, although not yet followed up upon from what I was able to see: https://github.com/golang/go/issues/29678#issuecomment-456928119
Ideally in a future update, it would be great if the IPMask `String` method and potentially this text marshal were in a more well known format such as dot-decimal notation, for IPv4 instead of encoded to hex, as it is currently displayed, but that sounds like another issue aside from the json marshaling issue I am currently filing for.

### What did you expect to see?

I expect `net.IPMask` to be marshaled to a text format, and consistent with `net.IP` and enable `net.IPNet` to be json marshaled leaving all objects in a human readable/parsable format.

### What did you see instead?

A json marshaled version of these items in a non human readable fashion (base64 encoded translation of the byte slice).