package com.walker.push.rocketmq; import com.walker.infrastructure.utils.DateUtils; import com.walker.infrastructure.utils.JsonUtils; import com.walker.push.rocketmq.tcp.MqResponse; import org.junit.Test; import java.util.HashMap; import java.util.Map; public class MqResponseSerialize { @Test public void testSerialize() throws Exception{ Map map = new HashMap<>(2); map.put("protocolNum", "data"); map.put("name", "0"); MqResponse mqResponse = new MqResponse(); mqResponse.setTopic("myTopic"); mqResponse.setSendTime(DateUtils.getDateTimeNumber()); mqResponse.setKey("123456"); mqResponse.setResponse(JsonUtils.objectToJsonString(map)); String json = JsonUtils.objectToJsonString(mqResponse); System.out.println("json = " + json); MqResponse data = JsonUtils.jsonStringToObject(json, MqResponse.class); System.out.println("response = " + data.getResponse()); } }