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

refactor(JSONObject): extend JSONObject.Delete() to delete multiple entries #1729

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jskelin
Copy link
Contributor

@jskelin jskelin commented Feb 20, 2025

This PR brings small improvement which enables deleting multiple entries at once.
Instead current

object.Delete("key1")
object.Delete("key2")

it is possible to:

object.Delete("key1", "key2")

@jskelin jskelin requested a review from a team as a code owner February 20, 2025 13:52
Copy link

Unit Test Results

1 825 tests  +5   1 824 ✅ +5   53s ⏱️ ±0s
  132 suites ±0       1 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit ae2a9cf. ± Comparison against base commit a088dab.

"github.com/dynatrace/dynatrace-configuration-as-code/v2/pkg/config/parameter/value"
)

type JSONObject map[string]any

// NewJSONObject is a function that creates a JSONObject from a raw JSON byte slice.
func NewJSONObject(raw []byte) (JSONObject, error) {
func NewJSONObject(raw json.RawMessage) (JSONObject, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why you changed this here to json.RawMessage.
Without this change, I would've approved the PR immediately, as it's straightforward enough.

Since json.RawMessage is also not a type alias but a real type, I am really not sure if we should introduce it everywhere 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - is there a need for this change? I believe the reason for json.RawMessage is be able to implement Marshaler and Unmarshaler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage of json.RawMessage emphasizes that the input should be JSON.

Could you explain the problems that defining an argument as json.RawMessage causes?

@arthurpitman arthurpitman self-requested a review February 21, 2025 11:04
Copy link
Contributor

@arthurpitman arthurpitman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is stylistic:

  • The current version,

    r.Delete(bucketName)
    r.Delete(status)
    r.Delete(version)
    r.Delete(updatable)
    

    is easier to read.

  • The proposed version r.Delete(bucketName, status, version, updatable) is less verbose.

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.

3 participants