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

POJO conversion doesn't work on Content-Type = application/json; charset=UTF-8 #1165

Closed
kst9395 opened this issue Nov 4, 2021 · 5 comments
Closed

Comments

@kst9395
Copy link

kst9395 commented Nov 4, 2021

In ControllerRunner#getRequestObject method, the implicit conversion from json to pojo will only happen if the Content-Type request header is equals to application/json.

boolean jsonRequest = contentType != null && contentType.equals("application/json");

The conversion of request body to Map in HttpSupport however uses .contains

 private void checkJsonContentType(){
        if(!(header("Content-Type") != null && header("Content-Type").toLowerCase().contains("application/json")) ){
            throw new WebException("Trying to convert JSON to object, but Content-Type is " + header("Content-Type") + ", not 'application/json'");
        }
    }
        

Should the ControllerRunner use the same validation logic when doing implicit conversion?

@ipolevoy
Copy link
Member

ipolevoy commented Nov 4, 2021

@kst9395 is this causing an issue for you? Is there a way you can provide an example where this is not working?

@ipolevoy
Copy link
Member

ipolevoy commented Nov 4, 2021

@kst9395 you are correct, this is a valid bug. What version of JavaLite are you using?

@kst9395
Copy link
Author

kst9395 commented Nov 4, 2021

Hi @ipolevoy , I am using javalite version: 2.5-j8.
This is causing an issue because I am using mithril.js as my frontend framework and seems like the default implementation of ajax call is actually defaulting the Content-Type header to be application/json; charset=utf-8 and there's no way for me to remove the request header.
The current workaround is actually to use raw XMLHttpRequest but it will be nice if this is enable by default in the framework :)

@ipolevoy
Copy link
Member

ipolevoy commented Nov 4, 2021

got it, no prob. I implement a fix and make a new release next week

@ipolevoy
Copy link
Member

@kst9395 this is fixed, you can pull a current snapshot 2.6-j8-SNAPSHOT for Java8 or 3.0-SNAPSHOT for Java16.

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

No branches or pull requests

2 participants