<commit_before>package com.ikamobile.ikasoa.rpc.handler.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ikamobile.ikasoa.core.utils.StringUtil;
import com.ikamobile.ikasoa.rpc.handler.ProtocolHandler;
import com.ikamobile.ikasoa.rpc.handler.ReturnData;

/**
 * 转换协议处理器JSON实现
 * 
 * @author <a href="mailto:<EMAIL>">Larry</a>
 * @version 0.1
 */
public class JsonProtocolHandlerImpl<T1, T2> implements ProtocolHandler<T1, T2> {

	private ReturnData resultData;

	// 类型分隔符
	private final static String CT = "&&&";

	// 异常标识符
	private final static String E = "E__";

	// 空标识符
	private final static String VOID = "_VOID_";

	public JsonProtocolHandlerImpl(ReturnData resultData) {
		this.resultData = resultData;
	}

	@Override
	@SuppressWarnings("unchecked")
	public T1 strToArg(String str) {
		if (StringUtil.isEmpty(str)) {
			throw new RuntimeException("parameters string can't null !");
		}
		if ("[]".equals(str)) {
			return null;
		}
		String[] strs = str.split(CT);
		if (strs.length != 2) {
			throw new RuntimeException("arg json string error : " + str);
		}
		String argClassStr = strs[0];
		Class<?>[] argClasses = JSON.parseObject(argClassStr, Class[].class);
		String argStr = strs[1];
		String[] argStrs = JSON.parseObject(argStr, String[].class);
		if (argStrs.length != argClasses.length) {
			throw new RuntimeException("parameters length is error !");
		}
		Object[] objs = new Object[argClasses.length];
		for (int i = 0; i < argClasses.length; i++) {
			String s = argStrs[i];
			Class<?> c = argClasses[i];
			if (isAppendQuotes(s)) {
				objs[i] = JSON.parseObject(new StringBuilder("\"").append(s).append("\"").toString(), c);
			} else {
				objs[i] = JSON.parseObject(s, c);
			}
		}
		return (T1) objs;
	}

	@Override
	public String argToStr(T1 arg) {
		if (arg == null) {
			return "[]";
		}
		Object[] args = (Object[]) arg;<commit_msg>bugfix<commit_after>package com.ikamobile.ikasoa.rpc.handler.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ikamobile.ikasoa.core.utils.StringUtil;
import com.ikamobile.ikasoa.rpc.handler.ProtocolHandler;
import com.ikamobile.ikasoa.rpc.handler.ReturnData;

/**
 * 转换协议处理器JSON实现
 * 
 * @author <a href="mailto:<EMAIL>">Larry</a>
 * @version 0.1
 */
public class JsonProtocolHandlerImpl<T1, T2> implements ProtocolHandler<T1, T2> {

	private ReturnData resultData;

	// 类型分隔符
	private final static String CT = "&&&";

	// 异常标识符
	private final static String E = "E__";

	// 空标识符
	private final static String VOID = "_VOID_";

	public JsonProtocolHandlerImpl(ReturnData resultData) {
		this.resultData = resultData;
	}

	@Override
	@SuppressWarnings("unchecked")
	public T1 strToArg(String str) {
		if (StringUtil.isEmpty(str)) {
			throw new RuntimeException("parameters string can't null !");
		}
		if ("[]".equals(str)) {
			return null;
		}
		String[] strs = str.split(CT);
		if (strs.length != 2) {
			throw new RuntimeException("arg json string error : " + str);
		}
		String argClassStr = strs[0];
		Class<?>[] argClasses = JSON.parseObject(argClassStr, Class[].class);
		String argStr = strs[1];
		String[] argStrs = JSON.parseObject(argStr, String[].class);
		if (argStrs.length != argClasses.length) {
			throw new RuntimeException("parameters length is error !");
		}
		Object[] objs = new Object[argClasses.length];
		for (int i = 0; i < argClasses.length; i++) {
			String s = argStrs[i];
			Class<?> c = argClasses[i];
			if (StringUtil.isEmpty(s) || c == null) {
				objs[i] = null;
				continue;
			}
			if (isAppendQuotes(s)) {
				objs[i] = JSON.parseObject(new StringBuilder("\"").append(s).append("\"").toString(), c);
			} else {
				objs[i] = JSON.parseObject(s, c);
			}
		}
		return (T1) objs;
	}

	@Override
	public String argToStr(T1 arg) {
		if (arg == null) {
			return "[]";
		}
		Object[] args = (Object[]) arg;
{'fraction_non_alphanumeric': 0.1550159430954133, 'fraction_numerical': 0.006377238165317636, 'mean_word_length': 4.047029702970297, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '422452', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1496, 'n_words': 322}