Commit 876625de authored by zhoushiguang's avatar zhoushiguang

json转换

parent 0474913b
package net.wanji.datacenter.kafka;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
......@@ -180,10 +182,14 @@ public class ConsumerHandler implements KafkaListenerErrorHandler {
ObjectMapper objectMapper = new ObjectMapper();
String recordStr = String.valueOf(record.value());
LineCongestion dto = JacksonUtils.getInstance().readValue(recordStr, LineCongestion.class);
String redisElement = objectMapper.writeValueAsString(dto);
//LineCongestion dto = JacksonUtils.getInstance().readValue(recordStr, LineCongestion.class);
//LineCongestion dto = JSONObject.parseObject(recordStr, LineCongestion.class);//objectMapper.readValue(element.toString(), LineCongestion.class);
String redisElement = recordStr; //JSONObject.toJSONString(dto, SerializerFeature.WriteNonStringValueAsString); //objectMapper.writeValueAsString(dto);
String redisKey = "line_congestion_sink";
log.info("消费干线指标信息:{}",redisElement);
redisUtils.addToSortedSetWithExpiry(redisKey, redisElement, TTL_IN_MILLIS);
} catch (Exception e) {
log.error("Kafka收到路口事件数据异常", e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment