From 1e2e8d895c2e9b5543c2185abdaeb99c2d9fc748 Mon Sep 17 00:00:00 2001 From: Vaadin Bot Date: Tue, 14 Jan 2025 11:38:51 +0100 Subject: [PATCH] fix: fix dependency conflict for ObjectMapper in PushEndpoint (#3137) (CP: 24.6) (#3138) fix: fix dependency conflict for ObjectMapper in PushEndpoint (#3137) * fix: fix dependency conflict for PushEndpoint Fixes #3136 * test Co-authored-by: Artur Co-authored-by: Luciano Vernaschi --- .../com/vaadin/hilla/push/PushConfigurer.java | 9 +++++++-- .../java/com/vaadin/hilla/push/PushEndpoint.java | 15 +++++++++------ .../vaadin/hilla/test/reactgrid/Application.java | 12 ++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/java/endpoint/src/main/java/com/vaadin/hilla/push/PushConfigurer.java b/packages/java/endpoint/src/main/java/com/vaadin/hilla/push/PushConfigurer.java index fb9bacb4f8..305840df49 100644 --- a/packages/java/endpoint/src/main/java/com/vaadin/hilla/push/PushConfigurer.java +++ b/packages/java/endpoint/src/main/java/com/vaadin/hilla/push/PushConfigurer.java @@ -4,6 +4,8 @@ import java.util.Collections; import java.util.List; +import com.fasterxml.jackson.databind.ObjectMapper; + import com.vaadin.hilla.EndpointProperties; import org.atmosphere.client.TrackMessageSizeInterceptor; import org.atmosphere.cpr.ApplicationConfig; @@ -14,6 +16,7 @@ import org.atmosphere.interceptor.AtmosphereResourceLifecycleInterceptor; import org.atmosphere.interceptor.SuspendTrackerInterceptor; import org.atmosphere.util.SimpleBroadcaster; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.web.servlet.ServletContextInitializer; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; @@ -46,8 +49,10 @@ public PushConfigurer(EndpointProperties endpointProperties) { } @Bean - PushEndpoint pushEndpoint() { - return new PushEndpoint(); + PushEndpoint pushEndpoint( + @Qualifier("hillaEndpointObjectMapper") ObjectMapper objectMapper, + PushMessageHandler pushMessageHandler) { + return new PushEndpoint(objectMapper, pushMessageHandler); } @Bean diff --git a/packages/java/endpoint/src/main/java/com/vaadin/hilla/push/PushEndpoint.java b/packages/java/endpoint/src/main/java/com/vaadin/hilla/push/PushEndpoint.java index cc1912ec24..57411abf03 100644 --- a/packages/java/endpoint/src/main/java/com/vaadin/hilla/push/PushEndpoint.java +++ b/packages/java/endpoint/src/main/java/com/vaadin/hilla/push/PushEndpoint.java @@ -4,6 +4,8 @@ import java.security.Principal; import java.util.function.Consumer; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import org.atmosphere.cpr.AtmosphereRequest; import org.atmosphere.cpr.AtmosphereResource; import org.atmosphere.cpr.AtmosphereResourceEvent; @@ -12,14 +14,11 @@ import org.atmosphere.util.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextImpl; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - import com.vaadin.hilla.push.messages.fromclient.AbstractServerMessage; import com.vaadin.hilla.push.messages.toclient.AbstractClientMessage; @@ -28,11 +27,15 @@ */ public class PushEndpoint extends AtmosphereHandlerAdapter { - @Autowired private ObjectMapper objectMapper; - @Autowired private PushMessageHandler pushMessageHandler; + PushEndpoint(ObjectMapper objectMapper, + PushMessageHandler pushMessageHandler) { + this.objectMapper = objectMapper; + this.pushMessageHandler = pushMessageHandler; + } + @Override public void onRequest(AtmosphereResource resource) throws IOException { String method = resource.getRequest().getMethod(); diff --git a/packages/java/tests/spring/react-grid-test/src/main/java/com/vaadin/hilla/test/reactgrid/Application.java b/packages/java/tests/spring/react-grid-test/src/main/java/com/vaadin/hilla/test/reactgrid/Application.java index 07389166e3..f8b693e6e7 100644 --- a/packages/java/tests/spring/react-grid-test/src/main/java/com/vaadin/hilla/test/reactgrid/Application.java +++ b/packages/java/tests/spring/react-grid-test/src/main/java/com/vaadin/hilla/test/reactgrid/Application.java @@ -1,7 +1,10 @@ package com.vaadin.hilla.test.reactgrid; +import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Primary; import com.vaadin.flow.component.page.AppShellConfigurator; import com.vaadin.flow.theme.Theme; @@ -13,4 +16,13 @@ public class Application implements AppShellConfigurator { public static void main(String[] args) { SpringApplication.run(Application.class, args); } + + @Bean + @Primary + ObjectMapper myObjectMapper() { + // This is only to test that you can have a custom object mapper without + // causing problems for Hilla + return new ObjectMapper(); + } + }