Skip to content

[BUG] The content type of the request takes precedence over the default content-type when determining the response content-type  #5

@lestephane

Description

@lestephane

Describe the bug

in MapMateSerializerAndDeserializer at line 93, the content-type of the response is hijacked by the content-type of the request (if present).

if (!contentType.isEmpty()) {
    responseContentType = contentType;
} else {
    responseContentType = defaultContentType;
}

This leads to awkward behaviour. For example, in the case where the incoming request is application/x-www-form-urlencoded, and I've configured

httpmate.assumingTheDefaultContentType(ContentType.json())

httpmate attempts to marshall the response to application/x-www-form-urlencoded, which is not the expected behaviour.

To Reproduce

....mappingRequestsAndResponsesUsing(mapMate()
        .matchingTheContentType(fromString("application/x-www-form-urlencoded"))
            .toTheMarshallerType(marshallingType("application/x-www-form-urlencoded"))
        .assumingTheDefaultContentType(ContentType.json())
            .usingTheSerializer(...)
            .andTheDeserializer(...))

Expected behavior

Expected the response content-type to be the content type specified in assumingTheDefaultContentType(...), as there is to my knowledger no way to specify the response content-type in any other way at the moment (The concept of a HttpMateChainKeys.RESPONSE_CONTENT_TYPE separate from HttpMateChainKeys.CONTENT_TYPE does not exist yet).

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions