Java Code Examples for com.alibaba.fastjson.JSONObject#toJSONBytes()

The following examples show how to use com.alibaba.fastjson.JSONObject#toJSONBytes() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: YuRPC   File: ZKDiscoveryServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 注册
 *
 * @param endpoint 服务信息
 */
@Override
public void register(Endpoint endpoint) {
    try {
        if (this.client.checkExists().forPath(YURPC_ROOT) == null) {
            this.client.create().withMode(CreateMode.PERSISTENT).forPath(YURPC_ROOT);
        }
        if (this.client.checkExists().forPath(String.format(YURPC_SERVICE_PATTERN, endpoint.getName())) == null) {
            this.client.create().withMode(CreateMode.PERSISTENT).forPath(String.format(YURPC_SERVICE_PATTERN, endpoint.getName()));
        }
        String path = String.format(YURPC_INSTANCE_PATTERN, endpoint.getName(), endpoint.getInstanceId());
        byte[] value = JSONObject.toJSONBytes(endpoint, SerializerFeature.DisableCircularReferenceDetect);
        this.client.create()
                .withMode(CreateMode.EPHEMERAL)
                .forPath(path, value);
        this.pathValue.put(path, value);
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
    }
}
 
Example 2
Source Project: iot-mqtt   File: SerializeHelper.java    License: Apache License 2.0 4 votes vote down vote up
public static <T> byte[] serialize(T obj){
    if(obj instanceof String){
        return ((String) obj).getBytes();
    }
    return JSONObject.toJSONBytes(obj);
}
 
Example 3
Source Project: jmqtt   File: SerializeHelper.java    License: Apache License 2.0 4 votes vote down vote up
public static <T> byte[] serialize(T obj){
    if(obj instanceof String){
        return ((String) obj).getBytes();
    }
    return JSONObject.toJSONBytes(obj);
}