Java Code Examples for com.alibaba.fastjson.parser.ParserConfig#setDefaultClassLoader()

The following examples show how to use com.alibaba.fastjson.parser.ParserConfig#setDefaultClassLoader() . 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 File: TransactionMessageServiceImpl.java    From tcc-transaction with Apache License 2.0 6 votes vote down vote up
private ServiceExecutePayload parsePayload(TransactionInfo transactionInfo) {
    String json = transactionInfo.getContext();
    //获取模块的名称
    String moduleId= transactionInfo.getModuleId();
    ClassLoader classLoader= SpringContextUtil.getClassLoader(moduleId);
    ParserConfig config= new ParserConfig();
    //指定类加载器
    config.setDefaultClassLoader(classLoader);
    ServiceExecutePayload payload= JSON.parseObject(json, ServiceExecutePayload.class, config, null, JSON.DEFAULT_PARSER_FEATURE, new Feature[0]);
    final Object[] values= payload.getArgs();
    int index=0 ;
    for(Class<?> each: payload.getActualTypes()){
        Object val= values[index];
        if(val!= null) {
            values[index] = JSON.parseObject(val.toString(), each, config, null, JSON.DEFAULT_PARSER_FEATURE, new Feature[0]);
        }
        index++;
    }
    return payload;
}
 
Example 2
Source File: TransactionMessageServiceImpl.java    From galaxy with Apache License 2.0 6 votes vote down vote up
private ServiceExecutePayload parsePayload(TransactionInfo transactionInfo) {
    String json = transactionInfo.getContext();
    //获取模块的名称
    String moduleId= transactionInfo.getModuleId();
    ClassLoader classLoader= SpringContextUtil.getClassLoader(moduleId);
    ParserConfig config= new ParserConfig();
    //指定类加载器
    config.setDefaultClassLoader(classLoader);
    ServiceExecutePayload payload= JSON.parseObject(json, ServiceExecutePayload.class, config, null, JSON.DEFAULT_PARSER_FEATURE, new Feature[0]);
    final Object[] values= payload.getArgs();
    int index=0 ;
    for(Class<?> each: payload.getActualTypes()){
        Object val= values[index];
        if(val!= null) {
            values[index] = JSON.parseObject(val.toString(), each, config, null, JSON.DEFAULT_PARSER_FEATURE, new Feature[0]);
        }
        index++;
    }
    return payload;
}