Skip to content

Commit

Permalink
Avoid creating ObjectMapper but using JsonSerialization utility class…
Browse files Browse the repository at this point in the history
… when managing event details

Closes keycloak#35457

Signed-off-by: Pedro Igor <[email protected]>
  • Loading branch information
pedroigor authored and ahus1 committed Dec 2, 2024
1 parent e5f1c9a commit 1c872de
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

package org.keycloak.events.jpa;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.jboss.logging.Logger;
import org.keycloak.common.util.Time;
import org.keycloak.events.Event;
Expand All @@ -37,6 +35,8 @@

import jakarta.persistence.EntityManager;
import jakarta.persistence.TypedQuery;
import org.keycloak.util.JsonSerialization;

import java.io.IOException;
import java.util.List;
import java.util.Map;
Expand All @@ -49,9 +49,6 @@
*/
public class JpaEventStoreProvider implements EventStoreProvider {

private static final ObjectMapper mapper = new ObjectMapper();
private static final TypeReference<Map<String, String>> mapType = new TypeReference<Map<String, String>>() {
};
private static final Logger logger = Logger.getLogger(JpaEventStoreProvider.class);

private final KeycloakSession session;
Expand Down Expand Up @@ -264,7 +261,7 @@ protected void clearExpiredAdminEvents() {
private static void setDetails(Consumer<String> setter, Map<String, String> details) {
if (details != null) {
try {
setter.accept(mapper.writeValueAsString(details));
setter.accept(JsonSerialization.writeValueAsString(details));
} catch (IOException e) {
logger.error("Failed to write event details", e);
}
Expand All @@ -274,7 +271,7 @@ private static void setDetails(Consumer<String> setter, Map<String, String> deta
private static void setDetails(Consumer<Map<String, String>> setter, String details) {
if (details != null) {
try {
setter.accept(mapper.readValue(details, mapType));
setter.accept(JsonSerialization.readValue(details, Map.class));
} catch (IOException e) {
logger.error("Failed to read event details", e);
}
Expand Down

0 comments on commit 1c872de

Please sign in to comment.