我在卡夫卡有两门序列化和脱硫。 帝国化工作受到罚款,但我对帝国化有问题。
我找到了许多解决办法,但没有任何结果。
A. 通用等级T的发射器
public class DeserializerU<T> implements Deserializer<T> {
@Override
public void configure(Map map, boolean bln) {
}
@Override
public void close() {
}
@Override
public T deserialize(String string, byte[] bytes) {
ObjectMapper mapper = new ObjectMapper();
T object = null;
try {
object = mapper.readValue(bytes, new TypeReference<T>() {});
} catch (Exception e) {
e.printStackTrace();
}
return object;
}
航天员
public class MyObject航天员 implements 航天员 {
@Override
public void configure(Map map, boolean bln) {
}
@Override
public byte[] serialize(String string, Object t) {
byte[] retVal = null;
ObjectMapper objectMapper = new ObjectMapper();
try {
retVal = objectMapper.writeValueAsString(t).getBytes();
} catch (Exception e) {
e.printStackTrace();
}
return retVal;
}
@Override
public void close() {
}
1. 不动产
Properties props = new Properties();
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, new DeserializerU<MyOwnObject>().getClass());
If I replace "TypeRefence(){}" for specific type then deserializer works but i need deserializer for many objects. I also tried convertValue instead of readValue but everything return LinkedHashMap which cannot be converted to my object. Any advice on how to do this? Thanks for help