我正在尝试使用java json 库 jackson序列化jnativehook捕获的键事件。
我按照此说明无法获得基本的 Jackson Mixin来序列化 3rd 方类。
但是它失败了,但有以下异常:
The class of event object is : org.jnativehook.keyboard.NativeKeyEvent
com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.jnativehook.GlobalScreen and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: org.jnativehook.keyboard.NativeKeyEvent["source"])
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:59)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:26)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:569)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:597)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:142)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:118)
at com.fasterxml.jackson.databind.ObjectWriter._configAndWriteValue(ObjectWriter.java:681)
at com.fasterxml.jackson.databind.ObjectWriter.writeValueAsString(ObjectWriter.java:567)
at GlobalKeyListenerExample.nativeKeyReleased(GlobalKeyListenerExample.java:45)
at org.jnativehook.GlobalScreen.processKeyEvent(Unknown Source)
at org.jnativehook.GlobalScreen$1.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
此gist中提供了 jar 文件的源代码和链接。
我试图查看杰克逊在调试器中序列化的元素是什么。我看到了在 jnativehook 库中看不到的“源”属性。这是杰克逊无法序列化的元素。我认为这个元素是在运行时添加的,但不确定为什么以及何时添加。
杰克逊有什么办法可以指示它不序列化这个字段或只序列化几个选择属性?