-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#46 - Implement KafkaSerializer for JSON serialization instead using …
…explicit object mapping
- Loading branch information
Showing
7 changed files
with
64 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/java/com/github/snuk87/keycloak/kafka/serializer/JsonSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.github.snuk87.keycloak.kafka.serializer; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.apache.kafka.common.errors.SerializationException; | ||
import org.apache.kafka.common.serialization.Serializer; | ||
|
||
import java.util.Map; | ||
|
||
public class JsonSerializer implements Serializer<Object> { | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
public JsonSerializer() { | ||
|
||
} | ||
|
||
@Override | ||
public void configure(Map<String, ?> config, boolean isKey) { | ||
|
||
} | ||
|
||
@Override | ||
public byte[] serialize(String topic, Object data) { | ||
if (data == null) { | ||
return null; | ||
} | ||
try { | ||
return objectMapper.writeValueAsBytes(data); | ||
} catch (JsonProcessingException e) { | ||
throw new SerializationException("Error serializing JSON message", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...ka/KafkaEventListenerProviderFactory.java → ...pi/KafkaEventListenerProviderFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters