Releases: wneessen/niljson
v0.1.1: Support for setting values
This release adds the Set() method to the Variable type, which allows the user manually setting the value of the Variable. By using the Set() method the Variable automatically get set to a valid state as well.
What's Changed
- [StepSecurity] Apply security best practices by @step-security-bot in #11
- Bump actions/setup-go from 4.1.0 to 5.0.2 by @dependabot[bot] in #16
- Bump step-security/harden-runner from 2.9.1 to 2.10.1 by @dependabot[bot] in #15
- Bump golangci/golangci-lint-action from 3.7.0 to 6.1.0 by @dependabot[bot] in #14
- Bump codecov/codecov-action from 3.1.6 to 4.5.0 by @dependabot[bot] in #13
- Bump fsfe/reuse-action from 1.3.0 to 4.0.0 by @dependabot[bot] in #12
- Bump github/codeql-action from 3.26.6 to 3.26.7 by @dependabot[bot] in #17
- Set permissions to read for workflow by @wneessen in #20
- Add SECURITY.md for reporting vulnerabilities by @wneessen in #22
- Bump sonarsource/sonarqube-scan-action from 2af7c4bea3abd8c236b5edb80998f31374896f09 to f885e52a7572cf7943f28637e75730227df2dbf2 by @dependabot[bot] in #24
- Bump github/codeql-action from 3.26.7 to 3.26.8 by @dependabot[bot] in #23
- Bump github/codeql-action from 3.26.8 to 3.26.9 by @dependabot[bot] in #26
- Bump sonarsource/sonarqube-scan-action from f885e52a7572cf7943f28637e75730227df2dbf2 to 884b79409bbd464b2a59edc326a4b77dc56b2195 by @dependabot[bot] in #25
- Bump github/codeql-action from 3.26.9 to 3.26.10 by @dependabot[bot] in #27
- Bump codecov/codecov-action from 4.5.0 to 4.6.0 by @dependabot[bot] in #29
- Bump golang/govulncheck-action from 1.0.3 to 1.0.4 by @dependabot[bot] in #28
- Bump golangci/golangci-lint-action from 6.1.0 to 6.1.1 by @dependabot[bot] in #31
- Bump github/codeql-action from 3.26.10 to 3.26.11 by @dependabot[bot] in #30
- Bump github/codeql-action from 3.26.11 to 3.26.12 by @dependabot[bot] in #33
- Bump actions/upload-artifact from 4.4.0 to 4.4.1 by @dependabot[bot] in #32
- Bump actions/upload-artifact from 4.4.1 to 4.4.2 by @dependabot[bot] in #34
- Bump actions/upload-artifact from 4.4.2 to 4.4.3 by @dependabot[bot] in #35
- Bump github/codeql-action from 3.26.12 to 3.26.13 by @dependabot[bot] in #36
- Bump actions/dependency-review-action from 4.3.4 to 4.3.5 by @dependabot[bot] in #37
- Bump github/codeql-action from 3.26.13 to 3.27.0 by @dependabot[bot] in #38
- Bump actions/setup-go from 5.0.2 to 5.1.0 by @dependabot[bot] in #39
- Bump actions/dependency-review-action from 4.3.5 to 4.4.0 by @dependabot[bot] in #40
- Bump sonarsource/sonarqube-quality-gate-action from dc2f7b0dd95544cd550de3028f89193576e958b9 to 8406f4f1edaffef38e9fb9c53eb292fc1d7684fa by @dependabot[bot] in #41
- Bump sonarsource/sonarqube-scan-action from 3.0.0 to 3.1.0 by @dependabot[bot] in #43
- Bump github/codeql-action from 3.27.0 to 3.27.1 by @dependabot[bot] in #42
- Bump github/codeql-action from 3.27.1 to 3.27.3 by @dependabot[bot] in #44
- Bump sonarsource/sonarqube-scan-action from 3.1.0 to 4.0.0 by @dependabot[bot] in #45
- Bump github/codeql-action from 3.27.3 to 3.27.4 by @dependabot[bot] in #48
- Bump fsfe/reuse-action from 4.0.0 to 5.0.0 by @dependabot[bot] in #47
- Bump codecov/codecov-action from 4.6.0 to 5.0.0 by @dependabot[bot] in #46
- Bump codecov/codecov-action from 5.0.0 to 5.0.2 by @dependabot[bot] in #49
- Bump step-security/harden-runner from 2.10.1 to 2.10.2 by @dependabot[bot] in #50
- Bump codecov/codecov-action from 5.0.2 to 5.0.3 by @dependabot[bot] in #51
- Bump github/codeql-action from 3.27.4 to 3.27.5 by @dependabot[bot] in #54
- Bump codecov/codecov-action from 5.0.3 to 5.0.7 by @dependabot[bot] in #53
- Bump actions/dependency-review-action from 4.4.0 to 4.5.0 by @dependabot[bot] in #52
- Bump sonarsource/sonarqube-scan-action from 4.0.0 to 4.1.0 by @dependabot[bot] in #55
- Bump github/codeql-action from 3.27.5 to 3.27.6 by @dependabot[bot] in #56
- Bump codecov/codecov-action from 5.0.7 to 5.1.1 by @dependabot[bot] in #57
- Bump github/codeql-action from 3.27.6 to 3.27.7 by @dependabot[bot] in #58
- Bump github/codeql-action from 3.27.7 to 3.27.9 by @dependabot[bot] in #60
- Bump actions/setup-go from 5.1.0 to 5.2.0 by @dependabot[bot] in #59
- Bump sonarsource/sonarqube-scan-action from 4.1.0 to 4.2.1 by @dependabot[bot] in #62
- Bump actions/upload-artifact from 4.4.3 to 4.5.0 by @dependabot[bot] in #61
- Bump codecov/codecov-action from 5.1.1 to 5.1.2 by @dependabot[bot] in #63
- Add
Setmethod for Variable and associated test case by @wneessen in #64 - Workflow cleanup by @wneessen in #65
New Contributors
- @step-security-bot made their first contribution in #11
- @dependabot[bot] made their first contribution in #16
Full Changelog: v0.1.0...v0.1.1
v0.1.0: Omitted fields support
This release adds the Omitted() method to the Variable type, which allows the user to identify if a null JSON value was present as actual null or completely omitted from the JSON. This can be helpful in case the user requires the JSON to have some mandatory fields.
What's Changed
Full Changelog: v0.0.5...v0.1.0
v0.0.5: Cleanup release
This is a code cleanup release. It doesn't add any functionality but introduces some code cleanups (and CI/CD workflow additions).
What's Changed
- Add SonarQube integration for code analysis by @wneessen in #4
- Fix Go version syntax in SonarQube workflow by @wneessen in #5
- Code cleanup by @wneessen in #6
- Refactor error messages in niljson tests. by @wneessen in #7
- More code cleanup and security workflows by @wneessen in #8
- Fix typo and improve readability in README.md by @wneessen in #9
Full Changelog: v0.0.4...v0.0.5
v0.0.4: JSON marshalling support
This release introduces a NewVariable method for creating generics-based Variable types. I also added the MarshalJSON methods to support JSON encoding for the various Nil types, ensuring proper handling of nil values.
What's Changed
Full Changelog: v0.0.3...v0.0.4
v0.0.3: Removed Get()
The Get() method was simply an alias for the Value() method and did not add any functionality. This simplification makes the code cleaner and reduces unnecessary duplication, improving maintainability.
What's Changed
Full Changelog: v0.0.2...v0.0.3
v0.0.2: UInt types
This release adds null-able uint types.
What's Changed
New Contributors
Full Changelog: v0.0.1...v0.0.2
v0.0.1: Initial release
Welcome to niljson
niljson provides a simple and efficient way to handle nullable JSON fields during the unmarshalling process.
In JSON, it's common to encounter fields that can be null, but handling these fields in Go can be cumbersome,
especially when dealing with primitive types like int, float64, bool. These types can all be either 0 (as value)
or null. In Go you can always work with pointers but these, of course, can lead to unhandled nil pointer dereferences.
niljaon addresses this challenge by offering a set of types that can seamlessly handle null values during
unmarshalling, allowing your Go applications to work with JSON data more naturally and with fewer boilerplate
checks for nil values.
Key Features
- Nullable Types: Provides a range of nullable types (
NilString,NilInt,NilFloat,NilBool, etc.) that
are easy to use and integrate into your existing Go structs. - Seamless Integration: These types work just like Go's standard types but add support for
nullvalues,
enabling cleaner and more maintainable code. - JSON Unmarshalling Support: Automatically handles the unmarshalling of JSON fields, converting
nullJSON
values to Go'snilor zero values, depending on the context. - Minimalistic and Lightweight: Designed to be lightweight and unobtrusive, so it won't bloat your application
or introduce unnecessary dependencies (only relies on the Go standard library)
Example Usage
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/wneessen/niljson"
)
type JSONType struct {
Bool niljson.NilBoolean `json:"bool"`
Float32 niljson.NilFloat32 `json:"float32,omitempty"`
Float64 niljson.NilFloat64 `json:"float64"`
Int niljson.NilInt `json:"int"`
Int64 niljson.NilInt64 `json:"int64"`
NullString niljson.NilString `json:"nil"`
String niljson.NilString `json:"string"`
}
func main() {
data := []byte(`{
"bytes": "Ynl0ZXM=",
"bool": true,
"float32": null,
"float64":0,
"int": 123,
"int64": 12345678901234,
"nilvalue": null,
"string":"test"
}`)
var example JSONType
var output string
if err := json.Unmarshal(data, &example); err != nil {
fmt.Println("failed to unmarshal JSON:", err)
os.Exit(1)
}
if example.Bool.NotNil() {
output += fmt.Sprintf("Bool is: %t, ", example.Bool.Value())
}
if example.Float32.IsNil() {
output += "Float 32 is nil, "
}
if example.Float64.NotNil() {
output += fmt.Sprintf("Float 64 is: %f, ", example.Float64.Value())
}
if example.String.NotNil() {
output += fmt.Sprintf("String is: %s", example.String.Value())
}
fmt.Println(output)
}Full Changelog: https://github.com/wneessen/niljson/commits/v0.0.1