Skip to content

Remove charset from application/json mimetype#10109

Merged
nielsm5 merged 4 commits intomasterfrom
bug/remove-charset-from-json-type
Dec 9, 2025
Merged

Remove charset from application/json mimetype#10109
nielsm5 merged 4 commits intomasterfrom
bug/remove-charset-from-json-type

Conversation

@nielsm5
Copy link
Member

@nielsm5 nielsm5 commented Dec 7, 2025

No description provided.

@nielsm5 nielsm5 force-pushed the bug/remove-charset-from-json-type branch from db663e3 to 2e26525 Compare December 7, 2025 21:52
fullContentType = fullContentType.withCharset(getCharSet());
if(StringUtils.isNotEmpty(getContentType()) && headerParamsSet.stream().noneMatch(e -> e.equalsIgnoreCase("content-type"))) {
defaultContentType = ContentType.parse(getContentType());
if(defaultContentType.getCharset() == null && !"application/json".equals(defaultContentType.getMimeType())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Kan je hier wellicht naar org.apache.http.entity.ContentType#APPLICATION_JSON kijken?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hoe bedoel je?

Copy link
Contributor

Choose a reason for hiding this comment

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

ipv de application/json string

Copy link
Member Author

Choose a reason for hiding this comment

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

Maar het is toch niet handig een object met een string te vergelijken?

}
MimeType mimeType = message != null ? message.getContext().getMimeType() : null;

MimeType mimeType = message != null ? MessageUtils.computeMimeType(message) : null;
Copy link
Member Author

Choose a reason for hiding this comment

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

This is now always a compute step.

t.transform(xmlSource, outputTarget);

setEntity(new ByteArrayEntity(outputStream.toByteArray()));
setEntity(new ByteArrayEntity(outputStream.toByteArray(), CONTENT_TYPE));
Copy link
Member Author

Choose a reason for hiding this comment

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

Since the ContentType is always known, no need to compute.


case DELETE:
HttpDelete deleteMethod = new HttpDelete(relativePath.toString());
if (null != getFullContentType()) { // Manually set Content-Type header
Copy link
Member Author

Choose a reason for hiding this comment

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

GET, DELETE and REPORT don't use Content-Types 😄

// check if computedType is one of the supported types, or else use the defaultMediaType
return Arrays.stream(SupportedMediaType.values())
.filter(supportedType -> supportedType.mediaType.equals(computedType))
.filter(supportedType -> supportedType.mediaType.equalsTypeAndSubtype(computedType))
Copy link
Member Author

Choose a reason for hiding this comment

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

Found a little bug

@nielsm5 nielsm5 requested a review from tnleeuw December 8, 2025 18:25
@nielsm5 nielsm5 marked this pull request as ready for review December 8, 2025 18:25
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 8, 2025

@nielsm5 nielsm5 merged commit dd72ed9 into master Dec 9, 2025
32 checks passed
@nielsm5 nielsm5 deleted the bug/remove-charset-from-json-type branch December 9, 2025 12:56
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