• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SerializationUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.github.ddth.commons.utils.SerializationUtils的典型用法代码示例。如果您正苦于以下问题:Java SerializationUtils类的具体用法?Java SerializationUtils怎么用?Java SerializationUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SerializationUtils类属于com.github.ddth.commons.utils包,在下文中一共展示了SerializationUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: parseRequest

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static Map<String, Object> parseRequest() {
    RequestBody requestBody = request().body();
    String requestContent = null;
    JsonNode jsonNode = requestBody.asJson();
    if (jsonNode != null) {
        requestContent = jsonNode.toString();
    } else {
        RawBuffer rawBuffer = requestBody.asRaw();
        if (rawBuffer != null) {
            requestContent = new String(rawBuffer.asBytes(), Constants.UTF8);
        } else {
            requestContent = requestBody.asText();
        }
    }
    return SerializationUtils.fromJsonString(requestContent, Map.class);
}
 
开发者ID:btnguyen2k,项目名称:queue-server,代码行数:18,代码来源:Application.java


示例2: initQueueMetadata

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected boolean initQueueMetadata(String queueName) {
    if (!isValidQueueName(queueName)) {
        return false;
    }

    String normalizedQueueName = normalizeQueueName(queueName);
    try (Jedis jedis = jedisPool.getResource()) {
        Map<String, Object> queueMetadata = new HashMap<String, Object>();
        queueMetadata.put("queue_name", normalizedQueueName);
        queueMetadata.put("queue_timestamp_create", new Date());
        byte[] data = SerializationUtils.toJsonString(queueMetadata).getBytes(UTF8);
        byte[] field = normalizedQueueName.getBytes(UTF8);
        Long result = jedis.hset(metadataRedisHashName, field, data);
        return result != null && result.longValue() > 0;
    }
}
 
开发者ID:btnguyen2k,项目名称:queue-server,代码行数:21,代码来源:RedisQueueApi.java


示例3: callApi

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Map<String, Object> callApi(String url) {
    try {
        HttpResponse httpResponse = HttpRequest.get(url).timeout(5000).send();
        try {
            if (httpResponse.statusCode() != 200) {
                return null;
            }

            int contentLength = Integer.parseInt(httpResponse.contentLength());
            if (contentLength == 0 || contentLength > 1024) {
                LOGGER.warn("Invalid response length: " + contentLength);
                return null;
            }

            return SerializationUtils.fromJsonString(httpResponse.body(), Map.class);
        } finally {
            httpResponse.close();
        }
    } catch (Exception e) {
        LOGGER.warn(e.getMessage(), e);
        return null;
    }
}
 
开发者ID:btnguyen2k,项目名称:id-jclient,代码行数:25,代码来源:RestIdClient.java


示例4: fromBytes

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
/**
 * Deserializes from a {@code byte[]} - which has been serialized by
 * {@link #toBytes()}.
 *
 * @param msgData
 * @return
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
@SuppressWarnings("unchecked")
public static <T extends BaseUniversalQueueMessage<ID>, ID> T fromBytes(byte[] msgData,
        Class<T> clazz) throws InstantiationException, IllegalAccessException {
    // firstly, deserialize the input data to a map
    String msgDataJson = msgData != null ? new String(msgData, QueueUtils.UTF8) : null;
    Map<String, Object> dataMap = null;
    try {
        dataMap = msgDataJson != null
                ? SerializationUtils.fromJsonString(msgDataJson, Map.class) : null;
    } catch (Exception e) {
        dataMap = null;
    }
    if (dataMap == null) {
        return null;
    }
    T msg = clazz.newInstance();
    msg.fromMap(dataMap);
    return msg;
}
 
开发者ID:DDTH,项目名称:ddth-queue,代码行数:29,代码来源:BaseUniversalQueueMessage.java


示例5: loadAsMap

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Map<Object, Object> loadAsMap(String tableName, String entryId) {
    long timestampStart = System.currentTimeMillis();
    final String CQL = MessageFormat.format(CQL_LOAD, tableName);
    try {
        Session session = getSession();
        List<Row> rows = CqlUtils.execute(session, CQL, entryId).all();
        if (rows == null || rows.size() == 0) {
            // not found
            return null;
        }
        Map<Object, Object> result = new HashMap<Object, Object>();
        for (Row row : rows) {
            String key = row.getString(COL_KEY);
            String value = row.getString(COL_VALUE);
            result.put(key, SerializationUtils.fromJsonString(value, Object.class));
        }
        return result;
    } finally {
        BaseDao.addProfiling(timestampStart, CQL, System.currentTimeMillis() - timestampStart);
    }
}
 
开发者ID:DDTH,项目名称:ddth-dao,代码行数:26,代码来源:WideRowJsonCassandraNosqlEngine.java


示例6: store

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void store(String tableName, String entryId, Map<Object, Object> data) {
    long timestampStart = System.currentTimeMillis();
    final String CQL = MessageFormat.format(CQL_STORE, tableName, COL_ID, COL_KEY, COL_VALUE);
    try {
        Session session = getSession();
        for (Entry<Object, Object> entry : data.entrySet()) {
            String key = entry.getKey().toString();
            String value = SerializationUtils.toJsonString(entry.getValue());
            CqlUtils.executeNonSelect(session, CQL, entryId, key, value);
        }
    } finally {
        BaseDao.addProfiling(timestampStart, CQL, System.currentTimeMillis() - timestampStart);
    }
}
 
开发者ID:DDTH,项目名称:ddth-dao,代码行数:19,代码来源:WideRowJsonCassandraNosqlEngine.java


示例7: fromJson

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
/**
 * Deserializes a BO from a JSON string.
 * 
 * @param json
 *            the JSON string obtained from {@link #toJson(BaseBo)}
 * @param clazz
 * @param classLoader
 * @return
 * @since 0.6.0.3
 */
@SuppressWarnings("unchecked")
public static <T extends BaseBo> T fromJson(String json, Class<T> clazz,
        ClassLoader classLoader) {
    if (StringUtils.isBlank(json) || clazz == null) {
        return null;
    }
    try {
        Map<String, Object> data = SerializationUtils.fromJsonString(json, Map.class);
        String boClassName = DPathUtils.getValue(data, FIELD_CLASSNAME, String.class);
        T bo = createObject(boClassName, classLoader, clazz);
        if (bo != null) {
            bo.fromJson(DPathUtils.getValue(data, FIELD_BODATA, String.class));
            return bo;
        } else {
            return null;
        }
    } catch (Exception e) {
        throw e instanceof DeserializationException ? (DeserializationException) e
                : new DeserializationException(e);
    }
}
 
开发者ID:DDTH,项目名称:ddth-dao,代码行数:32,代码来源:BoUtils.java


示例8: fromBytes

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
/**
 * Deserializes a BO from a byte array.
 * 
 * @param bytes
 *            the byte array obtained from {@link #toBytes(BaseBo)}
 * @param clazz
 * @param classLoader
 * @return
 * @since 0.6.0.3
 */
@SuppressWarnings("unchecked")
public static <T extends BaseBo> T fromBytes(byte[] bytes, Class<T> clazz,
        ClassLoader classLoader) {
    if (bytes == null || clazz == null) {
        return null;
    }
    try {
        Map<String, Object> data = SerializationUtils.fromByteArray(bytes, Map.class);
        String boClassName = DPathUtils.getValue(data, FIELD_CLASSNAME, String.class);
        T bo = createObject(boClassName, classLoader, clazz);
        if (bo != null) {
            bo.fromByteArray(DPathUtils.getValue(data, FIELD_BODATA, byte[].class));
            return bo;
        } else {
            return null;
        }
    } catch (Exception e) {
        throw e instanceof DeserializationException ? (DeserializationException) e
                : new DeserializationException(e);
    }
}
 
开发者ID:DDTH,项目名称:ddth-dao,代码行数:32,代码来源:BoUtils.java


示例9: setAttributes

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
/**
 * Set all BO's attributes.
 * 
 * @param attrs
 * @return
 */
@SuppressWarnings("unchecked")
public BaseBo setAttributes(Map<String, Object> attrs) {
    lock();
    try {
        if (attrs == null) {
            attributes = attrs;
        } else {
            attributes = SerializationUtils.fromByteArray(SerializationUtils.toByteArray(attrs),
                    Map.class);
        }
        triggerPopulate();
        return this;
    } finally {
        unlock();
    }
}
 
开发者ID:DDTH,项目名称:ddth-dao,代码行数:23,代码来源:BaseBo.java


示例10: setSubAttr

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
/**
 * Set a sub-attribute.
 * 
 * @param attrName
 * @param value
 * @return
 */
public BaseJsonBo setSubAttr(String attrName, String dPath, Object value) {
    lock();
    try {
        JsonNode attr = cacheJsonObjs.get(attrName);
        if (attr == null) {
            String[] paths = DPathUtils.splitDpath(dPath);
            if (paths[0].matches("^\\[(.*?)\\]$")) {
                setAttribute(attrName, "[]");
            } else {
                setAttribute(attrName, "{}");
            }
            attr = cacheJsonObjs.get(attrName);
        }
        JacksonUtils.setValue(attr, dPath, value, true);
        return (BaseJsonBo) setAttribute(attrName, SerializationUtils.toJsonString(attr),
                false);
    } finally {
        unlock();
    }
}
 
开发者ID:DDTH,项目名称:ddth-dao,代码行数:28,代码来源:BaseJsonBo.java


示例11: triggerPopulate

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
protected void triggerPopulate() {
    super.triggerPopulate();
    lock();
    try {
        cacheJsonObjs.clear();
        for (Entry<String, Object> entry : attributeMap().entrySet()) {
            String attrName = entry.getKey();
            String attrValue = entry.getValue().toString();
            cacheJsonObjs.put(attrName, SerializationUtils.readJson(attrValue));
        }
    } finally {
        unlock();
    }
}
 
开发者ID:DDTH,项目名称:ddth-dao,代码行数:19,代码来源:BaseJsonBo.java


示例12: deserialize

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
public static CacheEntry deserialize(byte[] data) throws TException {
    TCacheEntry cacheEntry = com.github.ddth.commons.utils.ThriftUtils.fromBytes(data,
            TCacheEntry.class);
    if (cacheEntry == null) {
        return null;
    }
    try {
        CacheEntry ce = new CacheEntry();
        ce.setExpireAfterAccess(cacheEntry.expireAfterAccess)
                .setExpireAfterWrite(cacheEntry.expireAfterWrite).setKey(cacheEntry.key);
        ce.setCreationTimestamp(cacheEntry.creationTimestampMs)
                .setLastAccessTimestamp(cacheEntry.lastAccessTimestampMs);
        if (cacheEntry.valueClass != null) {
            ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
            Class<?> clazz = Class.forName(cacheEntry.valueClass, false, classLoader);
            ce.setValue(SerializationUtils.fromByteArray(cacheEntry.getValue(), clazz));
        }
        return ce;
    } catch (ClassNotFoundException e) {
        throw new TException(e);
    }
}
 
开发者ID:DDTH,项目名称:ddth-cache-adapter,代码行数:23,代码来源:ThriftUtils.java


示例13: toBytes

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * 
 * @since 0.5.0
 */
@Override
public byte[] toBytes() throws SerializationException {
    Map<String, Object> dataMap = new HashMap<>();
    dataMap.put("k", this.key);
    dataMap.put("tac", this.lastAccessTimestampMs);
    dataMap.put("tcr", this.creationTimestampMs);
    dataMap.put("eac", this.expireAfterAccess);
    dataMap.put("ewr", this.expireAfterWrite);

    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    if (value != null) {
        dataMap.put("_c_", value.getClass().getName());
        dataMap.put("v", SerializationUtils.toByteArray(this.value, cl));
    }

    return SerializationUtils.toByteArrayFst(dataMap, cl);
}
 
开发者ID:DDTH,项目名称:ddth-cache-adapter,代码行数:23,代码来源:CacheEntry.java


示例14: main

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    {
        // bootstrap
        CacheEntry ce = new CacheEntry();
        SerializationUtils.toByteArray(ce);
        SerializationUtils.toByteArrayKryo(ce);
        ThriftUtils.serialize(ce);
    }

    Map<String, Object> value1 = new HashMap<String, Object>();
    {
        value1.put("first_name", "Thành");
        value1.put("last_name", "Nguyễn");
        value1.put("email", "[email protected]");
        value1.put("dob", new Date());
    }
    test(value1);
    System.out.println("========================================");
    TestValue.Value value2 = new TestValue.Value();
    test(value2);
}
 
开发者ID:DDTH,项目名称:ddth-cache-adapter,代码行数:22,代码来源:QndCacheSize.java


示例15: newInstance

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static FileInfo newInstance(byte[] data) {
    if (data == null || data.length <= 8) {
        return null;
    }
    Map<String, Object> dataMap = SerializationUtils.fromByteArray(data, Map.class);
    if (dataMap == null) {
        return null;
    }
    FileInfo fileInfo = newInstance();
    fileInfo.fromMap(dataMap);
    return fileInfo;
}
 
开发者ID:DDTH,项目名称:redir,代码行数:14,代码来源:FileInfo.java


示例16: doResponse

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
private static Result doResponse(int status, String message, boolean result, Object value) {
    Map<String, Object> responseData = new HashMap<String, Object>();
    responseData.put(Constants.RESPONSE_FIELD_STATUS, status);
    responseData.put(Constants.RESPONSE_FIELD_MESSAGE, message);
    responseData.put(Constants.RESPONSE_FIELD_RESULT, result);
    if (value != null) {
        responseData.put(Constants.RESPONSE_FIELD_VALUE, value);
    }
    response().setHeader(CONTENT_TYPE, "application/json");
    Registry.updateCounters(status);
    return ok(SerializationUtils.toJsonString(responseData));
}
 
开发者ID:btnguyen2k,项目名称:queue-server,代码行数:13,代码来源:Application.java


示例17: doResponse

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
private static Result doResponse(int status, long id, String message) {
    Map<String, Object> result = new HashMap<String, Object>();
    result.put(Constants.RESPONSE_FIELD_STATUS, status);
    result.put(Constants.RESPONSE_FIELD_ID, id);
    result.put(Constants.RESPONSE_FIELD_MESSAGE, message);
    response().setHeader(CONTENT_TYPE, "application/json");
    response().setHeader(CONTENT_ENCODING, "utf-8");
    return ok(SerializationUtils.toJsonString(result));
}
 
开发者ID:btnguyen2k,项目名称:id-server,代码行数:10,代码来源:Application.java


示例18: loadAsMap

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public Map<Object, Object> loadAsMap(String storageId, String entryId) {
    String json = loadAsJson(storageId, entryId);
    return SerializationUtils.fromJsonString(json, Map.class);
}
 
开发者ID:DDTH,项目名称:ddth-dao,代码行数:10,代码来源:BaseCassandraNosqlEngine.java


示例19: toJson

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
/**
 * Serializes a BO to JSON string.
 * 
 * @param bo
 * @return
 */
public static String toJson(BaseBo bo) {
    if (bo == null) {
        return null;
    }
    String clazz = bo.getClass().getName();
    Map<String, Object> data = new HashMap<>();
    data.put(FIELD_CLASSNAME, clazz);
    data.put(FIELD_BODATA, bo.toJson());
    return SerializationUtils.toJsonString(data);
}
 
开发者ID:DDTH,项目名称:ddth-dao,代码行数:17,代码来源:BoUtils.java


示例20: toBytes

import com.github.ddth.commons.utils.SerializationUtils; //导入依赖的package包/类
/**
 * Serializes a BO to a byte array.
 * 
 * @param bo
 * @return
 */
public static byte[] toBytes(BaseBo bo) {
    if (bo == null) {
        return null;
    }
    String clazz = bo.getClass().getName();
    Map<String, Object> data = new HashMap<>();
    data.put(FIELD_CLASSNAME, clazz);
    data.put(FIELD_BODATA, bo.toBytes());
    return SerializationUtils.toByteArray(data);
}
 
开发者ID:DDTH,项目名称:ddth-dao,代码行数:17,代码来源:BoUtils.java



注:本文中的com.github.ddth.commons.utils.SerializationUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StdRandom类代码示例发布时间:2022-05-22
下一篇:
Java NameSuggestionProvider类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap