Skip to content

Conversation

@ErykKul
Copy link
Collaborator

@ErykKul ErykKul commented Jan 16, 2026

What this PR does / why we need it:

Fixes the ok(String msg, JsonObjectBuilder bld) method in AbstractApiBean.java which incorrectly wraps the message in a nested object:

// Before (incorrect):
{"status":"OK","message":{"message":"actual message"},"data":{...}}

// After (correct):
{"status":"OK","message":"actual message","data":{...}}

The bug was introduced in commit f311312c34 on May 12, 2020, as part of #4813.

Which issue(s) this PR closes:

Special notes for your reviewer:

This is a one-line fix in AbstractApiBean.java line 1000:

// From:
.add("message", Json.createObjectBuilder().add("message",msg))
// To:
.add("message", msg)

The following 7 API endpoints are affected:

File Line API Endpoint
Datasets.java 3087 POST /api/datasets/{id}/add (duplicate file warning)
Admin.java 233 PUT /api/admin/settings
Dataverses.java 754 PUT /api/dataverses/{id}
Dataverses.java 788 PUT /api/dataverses/{id}/inputLevels
SavedSearches.java 161 POST /api/admin/savedsearches
HarvestingClients.java 309 PUT /api/harvest/clients/{nickName}
HarvestingServer.java 228 PUT /api/harvest/server/oaisets/{specname}

Suggestions on how to test this:

  1. Upload a file to a dataset via API
  2. Upload the same file again (duplicate)
  3. Check that the response message field is a string, not a nested object:
curl -X POST "http://localhost:8080/api/datasets/:persistentId/add?persistentId=doi:..." \
  -H "X-Dataverse-key: $API_TOKEN" \
  -F "[email protected]"
# Upload again to trigger duplicate warning
curl -X POST "http://localhost:8080/api/datasets/:persistentId/add?persistentId=doi:..." \
  -H "X-Dataverse-key: $API_TOKEN" \
  -F "[email protected]"

Does this PR introduce a user interface change? If mockups are available, please link/include them here:

No

Is there a release notes update needed for this change?:

Yes, included in this PR: doc/release-notes/12096-fix-ok-message-nested-object.md

Additional documentation:

N/A

@github-actions github-actions bot added the Type: Bug a defect label Jan 16, 2026
@ErykKul ErykKul changed the title Fix nested message object in API responses #12096 Fix nested message object in API responses Jan 16, 2026
@coveralls
Copy link

coveralls commented Jan 16, 2026

Coverage Status

coverage: 24.317% (+0.003%) from 24.314%
when pulling 0a9ce32 on 12096-fix-ok-message-nested-object
into f214ee4 on develop.

@github-actions

This comment has been minimized.

@pdurbin pdurbin moved this to Ready for Triage in IQSS Dataverse Project Jan 16, 2026
Copy link
Member

@pdurbin pdurbin left a comment

Choose a reason for hiding this comment

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

A couple quick comments.

Also, @poikilotherm noticed this double message bug, which lead to this API v2 proposal: https://docs.google.com/document/d/1XtXPF_PZCuhPbm4HCu28yRge_4_--ah604NhigPdjPk/edit?usp=sharing . And these related issues:

- `PUT /api/harvest/clients/{nickName}`
- `PUT /api/harvest/server/oaisets/{specname}`

**Note:** If you implemented a workaround to handle the nested `message` object, you may need to update your code to expect a plain string instead.
Copy link
Member

Choose a reason for hiding this comment

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

@ErykKul please also put this information in doc/sphinx-guides/source/api/changelog.rst

.add("message", msg)
.add("data", bld).build())
.type(MediaType.APPLICATION_JSON)
.build();
Copy link
Member

Choose a reason for hiding this comment

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

I'll just note here that Jenkins tests are failing due to this change. Please fix them. Thanks!

@ErykKul
Copy link
Collaborator Author

ErykKul commented Jan 17, 2026

@pdurbin Thanks for the quick review and the context about the API v2 proposal!

I was a bit hesitant to make this change since it could break existing API consumers that have implemented workarounds for the nested message object. However, I think it's worth fixing. The current behavior is clearly a bug, and the affected endpoints are relatively niche (the bug was actually discovered through duplicate file uploads, while regular file additions work fine).

That said, I can see the argument for keeping this for API v2 if you think the breaking change risk is too high. Let me know your thoughts - happy to go either way.

I've fixed the integration tests and added the changelog entry as requested. The docs build should pass now too (had a small RST syntax issue with the reference).

@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link

📦 Pushed preview images as

ghcr.io/gdcc/dataverse:12096-fix-ok-message-nested-object
ghcr.io/gdcc/configbaker:12096-fix-ok-message-nested-object

🚢 See on GHCR. Use by referencing with full name as printed above, mind the registry name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug a defect

Projects

Status: Ready for Triage

Development

Successfully merging this pull request may close these issues.

API returns malformed JSON with nested message object instead of string in ok(String, JsonObjectBuilder) responses

4 participants