![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Go's encoding/json
stdlib package with some minor enhancements that are very
hard achieve without modifying the json package.
This is a drop-in 100% compatible replacement.
Currently included patches:
Encode both a nil slice (a slice without a backing array, e.g. var x []string
)
as []
rather than null
, similar to how a slice with a len of 0 is encoded.
This is implemented as a Encoder.NullArray
setting for now, which avoids
having to add loads of struct tags everywhere. The default is unchanged use
NullArray(false)
to always encode to JSON []
).
Let's say you have a type like this:
type Foo {
ID int `json:"id"`
UserID int `json:"user_id"`
Name string `json:"name"`
}
In a REST API, you will probably want to have:
POST /foo Create a new foo
GET /foo/{id} Get a foo by ID
The problem is that in the API you want to display all the fields in the GET
request, but don't want to allow people to set ID
or UserID
fields in the
POST request.
Turns out this is kind of a tricky problem to solve. You can solve it by
creating a new type or a custom json.Unmarshaler, but there are various caveats
and it's tricky (see issue for details). With this change, you can add
readonly
which tells json.Unmarshal
to never set these fields:
type Foo {
ID int `json:"id,readonly"`
UserID int `json:"user_id,readonly"`
Name string `json:"name"`
}
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.