java 测试代码 + string 和 pb 转化

import com.alibaba.fastjson2.JSONObject;
import com.google.protobuf.util.JsonFormat;


public class helloworld {
    public static void main(String[] args) throws InvalidProtocolBufferException {
        System.out.println(LocalDateTime.now());
        System.out.println(10 != 20);
        System.out.println("sss".equals("2"));
        Integer hhh = 2;
        System.out.println(! hhh.equals(222));
        System.out.println(1 / 3);
        System.out.println(1 / 3.0);

        
        System.out.println("=======");
        ObjectUtils.Null hh = null;
        System.out.println("====hh===" + hh);
        if (hh == null) {
            System.out.println("==hh.equals=null====");
        }

        // string -> pb
        String fullDocumentString = "real_data";
        JSONObject fullJson = JSONObject.parseObject(fullDocumentString);
        ProtoMeta.Builder aa = ProtoMeta.newBuilder();
        JsonFormat.parser().ignoringUnknownFields().merge(fullJson, aa)
        // pb -> string
        ProtoMeta.Builder hh = ProtoMeta.newBuilder();
        String msgJson = JsonFormat.printer()
                .printingEnumsAsInts()
                .print(hh);

        // replace 后要重新赋值;加上转义是为了执行的时候不报错
        String sql = "select `#xray_id` hh `#xray_id`";
        System.out.println(sql);
        sql = sql.replace("`", "\\`");
        sql = sql.replace("xray_id", "\\`xray_id222");
        System.out.println(sql);
    }
}

你可能感兴趣的:(java,java,开发语言)