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

"java.lang.IllegalArgumentException: Don't know how to encode" when header contains Authorization Bearer token #3

Open
LayMui-Toh opened this issue Jan 4, 2020 · 0 comments

Comments

@LayMui-Toh
Copy link

My code snippet:

 String userAccount = String.format("{\"id\": null, \"login\": \"%s\", \"firstName\": \"%s\", \"lastName\": \"%s\", \"email\": \"%s\", \"activated\": true, \"langKey\": \"en\", \"createdBy\": null, \"createdDate\": null, \"lastModifiedBy\": null, \"lastModifiedDate\": null, \"resetDate\": null, \"authorities\": [\"%s\"]}",
                        login, firstName, lastName, email, role);

        System.out.println("USER ACCOUNT:" + userAccount);
       
        james.attemptsTo(
                Post.to("/api/users")
                        .with(request -> request.header("Content-Type", "application/json;charset:UTF8" , "Authorization", "Bearer " + idToken)
                                .body(userAccount)));

I got this error 
java.lang.IllegalArgumentException: Don't know how to encode {"id": null, "login": "john", "firstName": "john", "lastName": "tan", "email": "[email protected]", "activated": true, "langKey": "en", "createdBy": null, "createdDate": null, "lastModifiedBy": null, "lastModifiedDate": null, "resetDate": null, "authorities": ["ROLE_ADMIN"]} as a byte stream.

Please use EncoderConfig (EncoderConfig#encodeContentTypeAs) to specify how to serialize data for this content-type.
For example: "given().config(RestAssured.config().encoderConfig(encoderConfig().encodeContentTypeAs("Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOLFJPTEVfU1VQRVJfQURNSU4iLCJleHAiOjE1NzgxNDIyNDl9.QZ5jMLVOjrfawVTYrUV2IXigzZuzS38bBMGGRHe6IvZ7lK3w8WMsdtNF8qkpjAgov14TllATXuyxJ5fBCIWvCg", ContentType.TEXT))). .."
        at io.restassured.internal.http.EncoderRegistry.encodeStream(EncoderRegistry.java:132)
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

No branches or pull requests

1 participant