diff --git a/jooby/src/main/java/io/jooby/internal/RouterImpl.java b/jooby/src/main/java/io/jooby/internal/RouterImpl.java index 4c7819e191..a93b96fa38 100644 --- a/jooby/src/main/java/io/jooby/internal/RouterImpl.java +++ b/jooby/src/main/java/io/jooby/internal/RouterImpl.java @@ -911,7 +911,8 @@ private void copy(Route src, Route it) { it.setExecutorKey(src.getExecutorKey()); it.setTags(src.getTags()); it.setDescription(src.getDescription()); - it.setDecoders(src.getDecoders()); + // DO NOT COPY: See https://github.com/jooby-project/jooby/issues/3500 + // it.setDecoders(src.getDecoders()); it.setMvcMethod(src.getMvcMethod()); it.setNonBlocking(src.isNonBlocking()); it.setSummary(src.getSummary()); @@ -983,7 +984,7 @@ private static void override( Jooby app = (Jooby) router; override(src, app.getRouter(), consumer); } else if (router instanceof RouterImpl that) { - consumer.accept((RouterImpl) src, that); + consumer.accept(src, that); } } diff --git a/tests/pom.xml b/tests/pom.xml index 34db24a170..b6e277b2f4 100644 --- a/tests/pom.xml +++ b/tests/pom.xml @@ -33,6 +33,11 @@ jooby-jackson ${jooby.version} + + io.jooby + jooby-gson + ${jooby.version} + io.jooby jooby-avaje-jsonb @@ -250,7 +255,6 @@ 1.37 test - diff --git a/tests/src/test/java/io/jooby/i3400/Issue3400.java b/tests/src/test/java/io/jooby/i3400/Issue3400.java new file mode 100644 index 0000000000..7c3a49a664 --- /dev/null +++ b/tests/src/test/java/io/jooby/i3400/Issue3400.java @@ -0,0 +1,45 @@ +/* + * Jooby https://jooby.io + * Apache License Version 2.0 https://jooby.io/LICENSE.txt + * Copyright 2014 Edgar Espina + */ +package io.jooby.i3400; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import io.jooby.Jooby; +import io.jooby.jackson.JacksonModule; +import io.jooby.junit.ServerTest; +import io.jooby.junit.ServerTestRunner; +import okhttp3.MediaType; +import okhttp3.RequestBody; + +public class Issue3400 { + + static class AppA extends Jooby { + { + post("/pets", ctx -> ctx.body(Pet3400.class)); + } + } + + @ServerTest + public void shouldShareDecodersOnMountedResources(ServerTestRunner runner) { + runner + .define( + app -> { + app.install(new JacksonModule()); + app.mount(new AppA()); + }) + .ready( + http -> { + http.post( + "/pets", + RequestBody.create( + "{\"id\": 1, \"name\": \"Cheddar\"}", MediaType.parse("application/json")), + rsp -> { + assertEquals("{\"id\":1,\"name\":\"Cheddar\"}", rsp.body().string()); + assertEquals("application/json;charset=UTF-8", rsp.header("Content-Type")); + }); + }); + } +} diff --git a/tests/src/test/java/io/jooby/i3400/Pet3400.java b/tests/src/test/java/io/jooby/i3400/Pet3400.java new file mode 100644 index 0000000000..a7fbb20a4f --- /dev/null +++ b/tests/src/test/java/io/jooby/i3400/Pet3400.java @@ -0,0 +1,32 @@ +/* + * Jooby https://jooby.io + * Apache License Version 2.0 https://jooby.io/LICENSE.txt + * Copyright 2014 Edgar Espina + */ +package io.jooby.i3400; + +public class Pet3400 { + private int id; + private String name; + + public Pet3400(int id, String name) { + this.id = id; + this.name = name; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/tests/src/test/java/io/jooby/i3500/Issue3500.java b/tests/src/test/java/io/jooby/i3500/Issue3500.java new file mode 100644 index 0000000000..85fecbc6b6 --- /dev/null +++ b/tests/src/test/java/io/jooby/i3500/Issue3500.java @@ -0,0 +1,37 @@ +/* + * Jooby https://jooby.io + * Apache License Version 2.0 https://jooby.io/LICENSE.txt + * Copyright 2014 Edgar Espina + */ +package io.jooby.i3500; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import io.jooby.junit.ServerTest; +import io.jooby.junit.ServerTestRunner; +import okhttp3.MediaType; +import okhttp3.RequestBody; + +public class Issue3500 { + + @ServerTest + public void shouldShareDecodersOnMountedResources(ServerTestRunner runner) { + runner + .use(WidgetService::new) + .ready( + http -> { + http.post( + "/api/widgets1", + RequestBody.create("{\"id\": 1}", MediaType.get("application/json")), + rsp -> { + assertEquals(201, rsp.code()); + }); + http.post( + "/api/widgets2", + RequestBody.create("{\"id\": 1}", MediaType.get("application/json")), + rsp -> { + assertEquals(201, rsp.code()); + }); + }); + } +} diff --git a/tests/src/test/java/io/jooby/i3500/Widget.java b/tests/src/test/java/io/jooby/i3500/Widget.java new file mode 100644 index 0000000000..e2ad4a7a5b --- /dev/null +++ b/tests/src/test/java/io/jooby/i3500/Widget.java @@ -0,0 +1,18 @@ +/* + * Jooby https://jooby.io + * Apache License Version 2.0 https://jooby.io/LICENSE.txt + * Copyright 2014 Edgar Espina + */ +package io.jooby.i3500; + +public class Widget { + private int id; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } +} diff --git a/tests/src/test/java/io/jooby/i3500/WidgetService.java b/tests/src/test/java/io/jooby/i3500/WidgetService.java new file mode 100644 index 0000000000..59330c3ce9 --- /dev/null +++ b/tests/src/test/java/io/jooby/i3500/WidgetService.java @@ -0,0 +1,44 @@ +/* + * Jooby https://jooby.io + * Apache License Version 2.0 https://jooby.io/LICENSE.txt + * Copyright 2014 Edgar Espina + */ +package io.jooby.i3500; + +import io.jooby.Jooby; +import io.jooby.StatusCode; +import io.jooby.gson.GsonModule; + +public class WidgetService extends Jooby { + + public WidgetService() { + install(new GsonModule()); + + post( + "/api/widgets1", + ctx -> { + Widget widget = ctx.body().to(Widget.class); + System.out.println("Created " + widget); + return ctx.send(StatusCode.CREATED); + }); + + mount(new WidgetRouter()); + } + + public static void main(String[] args) { + new WidgetService().start(); + } +} + +class WidgetRouter extends Jooby { + + public WidgetRouter() { + + post( + "/api/widgets2", + ctx -> { + Widget widget = ctx.body().to(Widget.class); + return ctx.send(StatusCode.CREATED); + }); + } +}