jsonschema:l无法从kafka流序列化反序列化json

aemubtdh  于 2021-06-06  发布在  Kafka
关注(0)|答案(0)|浏览(351)

我把json发布到我的Kafka主题之一:

{
 "hash": "ABC",
 "height": 107900,
 "time": 1297626305,
 "txs": [
    {
        "hash": "XYZ1",
        "index": 0,
        "version": 1,
        "inputs": [
            {
                "prevout": {
                    "hash": "IN1",
                    "index": 4294967295
                },
                "script": "045285021b0173",
                "address": null
            }
        ],
        "outputs": [
            {
                "value": 5001000000,
                "address": "OUT1"
            }
        ],
        "locktime": 0
    },
    {
        "hash": "XYZ2",
        "index": 1,
        "version": 1,
        "inputs": [
            {
                "prevout": {
                    "hash": "IN12",
                    "index": 1
                },
                "coin": {
                    "version": 1,
                    "height": 107899,
                    "value": 34645000000,
                    "address": "IN2",
                    "coinbase": false
                }
            }
        ],
        "outputs": [
            {
                "value": 6000000,
                "address": "OUT2"
            },
            {
                "value": 70000000,
                "address": "OUT4"
            }
        ],
        "locktime": 0
    }
 ]
}

我想得到这样的结果:

{
  address: IN2
  result : {
     output : OUT2,
     value: 6000000
  },
  result : {
     output : OUT4,
     value: 70000000
  },

我尝试使用apache kafka streaming解析json数据后给出的相同方法,但出现以下错误:
我正在尝试创建不同的pojo,并尝试上述参考答案中提供的解决方案。但是得到错误:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/kafka/common/serialization/Deserializer
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
    Caused by: java.lang.ClassNotFoundException: 
    org.apache.kafka.common.serialization.Deserializer
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

在运行java-cp时,我尝试将这个类添加到classpath中,但是当我为这个jar添加时,其他jar就会出现错误。接下来就是请给出解决方案。
提前谢谢。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题