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

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

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

  1. {
  2. "hash": "ABC",
  3. "height": 107900,
  4. "time": 1297626305,
  5. "txs": [
  6. {
  7. "hash": "XYZ1",
  8. "index": 0,
  9. "version": 1,
  10. "inputs": [
  11. {
  12. "prevout": {
  13. "hash": "IN1",
  14. "index": 4294967295
  15. },
  16. "script": "045285021b0173",
  17. "address": null
  18. }
  19. ],
  20. "outputs": [
  21. {
  22. "value": 5001000000,
  23. "address": "OUT1"
  24. }
  25. ],
  26. "locktime": 0
  27. },
  28. {
  29. "hash": "XYZ2",
  30. "index": 1,
  31. "version": 1,
  32. "inputs": [
  33. {
  34. "prevout": {
  35. "hash": "IN12",
  36. "index": 1
  37. },
  38. "coin": {
  39. "version": 1,
  40. "height": 107899,
  41. "value": 34645000000,
  42. "address": "IN2",
  43. "coinbase": false
  44. }
  45. }
  46. ],
  47. "outputs": [
  48. {
  49. "value": 6000000,
  50. "address": "OUT2"
  51. },
  52. {
  53. "value": 70000000,
  54. "address": "OUT4"
  55. }
  56. ],
  57. "locktime": 0
  58. }
  59. ]
  60. }

我想得到这样的结果:

  1. {
  2. address: IN2
  3. result : {
  4. output : OUT2,
  5. value: 6000000
  6. },
  7. result : {
  8. output : OUT4,
  9. value: 70000000
  10. },

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

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

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

暂无答案!

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

相关问题