temirlan100

Untitled

Dec 2nd, 2024
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.44 KB | None | 0 0
  1. import com.google.gson.Gson;
  2. import java.nio.charset.StandardCharsets;
  3. import org.apache.kafka.common.serialization.Serializer;
  4.  
  5. public class GsonSerializer<T> implements Serializer<T> {
  6.     private final Gson gson = new Gson();
  7.  
  8.     @Override
  9.     public byte[] serialize(String topic, T data) {
  10.         if (data == null) {
  11.             return null;
  12.         }
  13.         return gson.toJson(data).getBytes(StandardCharsets.UTF_8);
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment