Skip to content

Commit

Permalink
Merge pull request apache#776 from chickenlj:json_to_fastjson
Browse files Browse the repository at this point in the history
Deprecate internal JSON impl and change to fastjson
  • Loading branch information
chickenlj authored Oct 28, 2017
1 parent d323724 commit 9fa7b90
Show file tree
Hide file tree
Showing 31 changed files with 53 additions and 43 deletions.
1 change: 0 additions & 1 deletion dubbo-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jvnet.sorcerer</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

@Deprecated
public class GenericJSONConverter implements JSONConverter {
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
private static final Map<Class<?>, Encoder> GlobalEncoderMap = new HashMap<Class<?>, Encoder>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*
* @author qian.lei.
*/

@Deprecated
class J2oVisitor implements JSONVisitor {
public static final boolean[] EMPTY_BOOL_ARRAY = new boolean[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
* @author qian.lei
*/

@Deprecated
public class JSON {
public static final char LBRACE = '{', RBRACE = '}';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @author qian.lei
*/

@Deprecated
public class JSONArray implements JSONNode {
private List<Object> mArray = new ArrayList<Object>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author qianlei
*/

@Deprecated
public interface JSONConverter {
/**
* write object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author qian.lei
*/

@Deprecated
interface JSONNode {
/**
* write json string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @author qian.lei
*/

@Deprecated
public class JSONObject implements JSONNode {
private Map<String, Object> mMap = new HashMap<String, Object>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @author qian.lei
*/

@Deprecated
public class JSONReader {
private static ThreadLocal<Yylex> LOCAL_LEXER = new ThreadLocal<Yylex>() {
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author qian.lei
*/

@Deprecated
public class JSONToken {
// token type
public static final int ANY = 0, IDENT = 0x01, LBRACE = 0x02, LSQUARE = 0x03, RBRACE = 0x04, RSQUARE = 0x05, COMMA = 0x06, COLON = 0x07;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author qian.lei
*/

@Deprecated
public interface JSONVisitor {
public static final String CLASS_PROPERTY = "class";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* @author qian.lei
*/

@Deprecated
public class JSONWriter {
private static final byte UNKNOWN = 0, ARRAY = 1, OBJECT = 2, OBJECT_VALUE = 3;
private static final String[] CONTROL_CHAR_MAP = new String[]{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @author qian.lei
*/

@Deprecated
public class ParseException extends Exception {
private static final long serialVersionUID = 8611884051738966316L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* on 7/3/10 3:12 AM from the specification file
* <tt>/Users/qianlei/dev/proj/dubbo-1.1/dubbo.common/src/main/java/com/alibaba/dubbo/common/json/json.flex</tt>
*/
@Deprecated
public class Yylex {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* @author william.liangf
* @author ding.lid
*/
@Deprecated
public class JsonObjectInput implements ObjectInput {

private final BufferedReader reader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*
* @author william.liangf
*/
@Deprecated
public class JsonObjectOutput implements ObjectOutput {

private final PrintWriter writer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*
* @author william.liangf
*/
@Deprecated
public class JsonSerialization implements Serialization {

public byte getContentTypeId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.io.UnsafeStringWriter;
import com.alibaba.dubbo.common.json.JSON;
import com.alibaba.fastjson.JSON;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -420,8 +419,8 @@ public static String toArgumentString(Object[] args) {
buf.append(arg);
} else {
try {
buf.append(JSON.json(arg));
} catch (IOException e) {
buf.append(JSON.toJSONString(arg));
} catch (Exception e) {
logger.warn(e.getMessage(), e);
buf.append(arg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ dubbo=com.alibaba.dubbo.common.serialize.support.dubbo.DubboSerialization
hessian2=com.alibaba.dubbo.common.serialize.support.hessian.Hessian2Serialization
java=com.alibaba.dubbo.common.serialize.support.java.JavaSerialization
compactedjava=com.alibaba.dubbo.common.serialize.support.java.CompactedJavaSerialization
json=com.alibaba.dubbo.common.serialize.support.json.JsonSerialization
fastjson=com.alibaba.dubbo.common.serialize.support.json.FastJsonSerialization
nativejava=com.alibaba.dubbo.common.serialize.support.nativejava.NativeJavaSerialization
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import static org.junit.Assert.assertEquals;

@Deprecated
public class JSONTest {
static byte[] DEFAULT_BYTES = {3, 12, 14, 41, 12, 2, 3, 12, 4, 67, 23};
static int DEFAULT_$$ = 152;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public static <T> List<T> toArray(T... args) {
@Test
public void testMergeValues() {
List<String> merged = ConfigUtils.mergeValues(Serialization.class, "aaa,bbb,default.cunstom",
toArray("dubbo", "default.hessian2", "json"));
Assert.assertEquals(toArray("dubbo", "json", "aaa", "bbb", "default.cunstom"), merged);
toArray("dubbo", "default.hessian2", "fastjson"));
Assert.assertEquals(toArray("dubbo", "fastjson", "aaa", "bbb", "default.cunstom"), merged);
}

/**
Expand All @@ -58,8 +58,8 @@ public void testMergeValues() {
@Test
public void testMergeValues_addDefault() {
List<String> merged = ConfigUtils.mergeValues(Serialization.class, "aaa,bbb,default,zzz",
toArray("dubbo", "default.hessian2", "json"));
Assert.assertEquals(toArray("aaa", "bbb", "dubbo", "json", "zzz"), merged);
toArray("dubbo", "default.hessian2", "fastjson"));
Assert.assertEquals(toArray("aaa", "bbb", "dubbo", "fastjson", "zzz"), merged);
}

/**
Expand All @@ -85,8 +85,8 @@ public void testMergeValuesDeleteDefault_2() {
*/
@Test
public void testMergeValuesDelete() {
List<String> merged = ConfigUtils.mergeValues(Serialization.class, "-dubbo,aaa", toArray("dubbo", "default.hessian2", "json"));
Assert.assertEquals(toArray("json", "aaa"), merged);
List<String> merged = ConfigUtils.mergeValues(Serialization.class, "-dubbo,aaa", toArray("dubbo", "default.hessian2", "fastjson"));
Assert.assertEquals(toArray("fastjson", "aaa"), merged);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if [ -z "$SERVER_NAME" ]; then
SERVER_NAME=`hostname`
fi

PIDS=`ps -ef | grep java | grep "$CONF_DIR" |awk '{print $2}'`
PIDS=`ps -ef | grep java | grep -v grep | grep "$CONF_DIR" |awk '{print $2}'`
if [ -z "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME does not started!"
exit 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if [ -z "$SERVER_NAME" ]; then
SERVER_NAME=`hostname`
fi

PIDS=`ps -ef | grep java | grep "$CONF_DIR" |awk '{print $2}'`
PIDS=`ps -ef | grep java | grep -v grep | grep "$CONF_DIR" |awk '{print $2}'`
if [ -n "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME already started!"
echo "PID: $PIDS"
Expand Down Expand Up @@ -79,14 +79,14 @@ while [ $COUNT -lt 1 ]; do
COUNT=`netstat -an | grep $SERVER_PORT | wc -l`
fi
else
COUNT=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`
COUNT=`ps -f | grep java | grep -v grep | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`
fi
if [ $COUNT -gt 0 ]; then
break
fi
done

echo "OK!"
PIDS=`ps -f | grep java | grep "$DEPLOY_DIR" | awk '{print $2}'`
PIDS=`ps -f | grep java | grep -v grep | grep "$DEPLOY_DIR" | awk '{print $2}'`
echo "PID: $PIDS"
echo "STDOUT: $STDOUT_FILE"
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if [ -z "$SERVER_NAME" ]; then
SERVER_NAME=`hostname`
fi

PIDS=`ps -ef | grep java | grep "$CONF_DIR" |awk '{print $2}'`
PIDS=`ps -ef | grep java | grep -v grep | grep "$CONF_DIR" |awk '{print $2}'`
if [ -z "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME does not started!"
exit 1
Expand Down
4 changes: 4 additions & 0 deletions dubbo-demo/dubbo-demo-consumer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
Expand Down
4 changes: 4 additions & 0 deletions dubbo-demo/dubbo-demo-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.common.json.JSON;
import com.alibaba.fastjson.JSON;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.common.utils.ConcurrentHashSet;
Expand Down Expand Up @@ -139,7 +139,7 @@ public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException {
sn.append(") ");
Object[] args = inv.getArguments();
if (args != null && args.length > 0) {
sn.append(JSON.json(args));
sn.append(JSON.toJSONString(args));
}
String msg = sn.toString();
if (ConfigUtils.isDefault(accesslog)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
public abstract class AbstractProxyProtocol extends AbstractProtocol {

private final List<Class<?>> rpcExceptions = new CopyOnWriteArrayList<Class<?>>();
;

private ProxyFactory proxyFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.extension.ExtensionLoader;
import com.alibaba.dubbo.common.json.JSON;
import com.alibaba.dubbo.common.utils.ConfigUtils;
import com.alibaba.dubbo.common.utils.PojoUtils;
import com.alibaba.dubbo.common.utils.ReflectUtils;
Expand All @@ -30,6 +29,7 @@
import com.alibaba.dubbo.rpc.RpcException;
import com.alibaba.dubbo.rpc.RpcInvocation;
import com.alibaba.dubbo.rpc.RpcResult;
import com.alibaba.fastjson.JSON;

import java.lang.reflect.Constructor;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -74,9 +74,9 @@ public static Object parseMockValue(String mock, Type[] returnTypes) throws Exce
} else if (StringUtils.isNumeric(mock)) {
value = JSON.parse(mock);
} else if (mock.startsWith("{")) {
value = JSON.parse(mock, Map.class);
value = JSON.parseObject(mock, Map.class);
} else if (mock.startsWith("[")) {
value = JSON.parse(mock, List.class);
value = JSON.parseObject(mock, List.class);
} else {
value = mock;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ public Result invoke(Invocation invocation) throws RpcException {
Invoker<T> invoker = getInvoker(mock);
return invoker.invoke(invocation);
} catch (Throwable t) {
throw new RpcException("Failed to create mock implementation class " + mock, t);
throw new RpcException("Failed to create mock implemention class " + mock, t);
}
}
}
Expand Down Expand Up @@ -166,11 +166,11 @@ private Invoker<T> getInvoker(String mockService) {

Class<?> mockClass = ReflectUtils.forName(mockService);
if (!serviceType.isAssignableFrom(mockClass)) {
throw new IllegalArgumentException("The mock implementation class " + mockClass.getName() + " not implement interface " + serviceType.getName());
throw new IllegalArgumentException("The mock implemention class " + mockClass.getName() + " not implement interface " + serviceType.getName());
}

if (!serviceType.isAssignableFrom(mockClass)) {
throw new IllegalArgumentException("The mock implementation class " + mockClass.getName() + " not implement interface " + serviceType.getName());
throw new IllegalArgumentException("The mock implemention class " + mockClass.getName() + " not implement interface " + serviceType.getName());
}
try {
T mockObject = (T) mockClass.newInstance();
Expand All @@ -180,7 +180,7 @@ private Invoker<T> getInvoker(String mockService) {
}
return invoker;
} catch (InstantiationException e) {
throw new IllegalStateException("No such empty constructor \"public " + mockClass.getSimpleName() + "()\" in mock implementation class " + mockClass.getName(), e);
throw new IllegalStateException("No such empty constructor \"public " + mockClass.getSimpleName() + "()\" in mock implemention class " + mockClass.getName(), e);
} catch (IllegalAccessException e) {
throw new IllegalStateException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.extension.Activate;
import com.alibaba.dubbo.common.json.JSON;
import com.alibaba.fastjson.JSON;
import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.alibaba.dubbo.common.utils.ConcurrentHashSet;
Expand Down Expand Up @@ -105,7 +105,7 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcExcept
channel.send("\r\n" + RpcContext.getContext().getRemoteAddress() + " -> "
+ invoker.getInterface().getName()
+ "." + invocation.getMethodName()
+ "(" + JSON.json(invocation.getArguments()) + ")" + " -> " + JSON.json(result.getValue())
+ "(" + JSON.toJSONString(invocation.getArguments()) + ")" + " -> " + JSON.toJSONString(result.getValue())
+ "\r\nelapsed: " + (end - start) + " ms."
+ "\r\n\r\n" + prompt);
}
Expand Down
Loading

0 comments on commit 9fa7b90

Please sign in to comment.