如何使用kafka streaming java8从jsonobject(数组)中获取particluar字段
你能解决我的疑问吗。在我的卡夫卡主题中,通过使用卡夫卡流,我能够从jsonObject如何使用kafka streaming java8从jsonobject(数组)中获取particluar字段,stream,apache-kafka,apache-kafka-streams,confluent-platform,Stream,Apache Kafka,Apache Kafka Streams,Confluent Platform,你能解决我的疑问吗。在我的卡夫卡主题中,通过使用卡夫卡流,我能够从jsonObject(一个-->{“host”:“mou”,“type”:“kat”})中获得一个字段,下面的代码是Java8 KStream sources=builder .stream(Serdes.String(),jsonSerde,“示例”) .map((k,v)->新的键值(k,(String)v.path(“a”).toString()); foreach((w,c)->System.out.println(“wo
(一个-->{“host”:“mou”,“type”:“kat”})
中获得一个字段,下面的代码是Java8
KStream sources=builder
.stream(Serdes.String(),jsonSerde,“示例”)
.map((k,v)->新的键值(k,(String)v.path(“a”).toString());
foreach((w,c)->System.out.println(“word:->”+c));
sources.print(“获取字段值”);
但是如果我的输入是
{“type”:“abc”,“name”:“abc”,“a”[{“host”:“mouni”}]}
我得到了序列化错误。(请就我的问题发送一份POC。)以及以下代码行
KStream<String, String> sources = builder.stream(Serdes.String(), jsonSerde, "example")
.map((k,v) -> new KeyValue<>(k, v.path("l").path(0).path("a").toString()));
KStream sources=builder.stream(Serdes.String(),jsonSerde,“示例”)
.map((k,v)->新的键值(k,v.path(“l”).path(0.path(“a”).toString());
输入值是否为JSON?我不是JSON方面的专家。是的,输入是JSON,正如我在上面的问题中提到的。