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 passed to view that return HttpResponse doesn't works with GraalVM and Handlebars with Micronaut 3 #252

Open
ilopmar opened this issue Jul 26, 2021 · 2 comments

Comments

@ilopmar
Copy link
Contributor

ilopmar commented Jul 26, 2021

All the GraalVM Micronaut Views applications have the same structure and have a controller like:

@Controller("/views")
public class ViewsController {

    @Get("/handlebars")
    public ModelAndView<User> handlebars() {
        return new ModelAndView<>("handlebars/home", new User("Iván", true));
    }

    @View("/handlebars/home")
    @Get("/handlebars-view")
    public HttpResponse<User> handlebarsPojoView() {
        return HttpResponse.ok(new User("Iván", true));
    }
}

Then in the html template rendered we check if the user is logged in and render they name.

This works for all the view technologies except for Handlebars and only when returning an HttpResponse. When returning a ModelAndView it also works.

It works in JIT mode but it fails now as a GraalVM native image.

Steps to Reproduce

  • git clone https://github.com/micronaut-graal-tests/micronaut-views-graal
  • cd micronaut-views-graal
  • git checkout handlebars-micronaut3-error
  • sdk use java 21.2.0.r11-grl
  • ./gradlew nativeImage
  • ./build/native-image/views-handlebars
  • curl localhost:8080/views/handlebars-view
  • curl localhost:8080/views/handlebars

Expected Behaviour

Both curl requests should return the same

Actual Behaviour

$ curl localhost:8080/views/handlebars-view

<!DOCTYPE html>
<html>
<head>
    <title>Handlebars</title>
    <meta charset="utf-8">
</head>
<body>
    
    <h1>You are not logged in</h1>
    
</body>
</html>
$ curl localhost:8080/views/handlebars
<!DOCTYPE html>
<html>
<head>
    <title>Handlebars</title>
    <meta charset="utf-8">
</head>
<body>
    
    <h1>username: <span>Iván</span></h1>
    
</body>
</html>

Environment Information

  • Operating System: Linux Mint 20.1
  • Micronaut Version: 3.0.0-SNAPSHOT
  • JDK Version: 11
@sdelamo
Copy link
Contributor

sdelamo commented Jul 26, 2021

is User annotated with @Introspected?

@ilopmar
Copy link
Contributor Author

ilopmar commented Jul 26, 2021

Yes https://github.com/micronaut-graal-tests/micronaut-views-graal/blob/3.0.x_handlebars/src/main/java/example/micronaut/User.java#L5. Please keep in mind that the same application works for the other technologies: Thymeleaf, Freemarker,...

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