package io.geekidea.springbootplus.test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.json.JsonMapper;
import com.wecloud.im.ws.model.request.ReceiveModel;

public class JsonTest {

    public static void main(String[] args) throws JsonProcessingException {

//        jsonTest();
    }

    private static void jsonTest() throws JsonProcessingException {
        String data = "{\n" +
                "\"reqId\":\"123123\",\n" +
                "\"cmd\":1,\n" +
                "\"data\":{\n" +
                "    \"type\":-1,\n" +
                "    \"text\":\"这是一个纯文本消息\",\n" +
                "    \"attrs\":{\n" +
                "    \"a\":\"attrs是用来存储用户自定义的一些键值对\"}}\n" +
                "}\n";

        // json转换成对象
        JsonMapper jsonMapper = new JsonMapper();
        ReceiveModel receiveModel = jsonMapper.readValue(data, ReceiveModel.class);

        // data对象转换成json
        ObjectMapper objectMapper = new ObjectMapper();
        String s = objectMapper.writeValueAsString(receiveModel.getData());
    }


}
