This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 897cd0f [3.0] Remove Dubbo embedded JSON implementation (#9474)
897cd0f is described below
commit 897cd0f62e2e7531a4c1cbc0da9bf282aed5f4e8
Author: Albumen Kevin <[email protected]>
AuthorDate: Thu Dec 23 14:47:57 2021 +0800
[3.0] Remove Dubbo embedded JSON implementation (#9474)
---
.../dubbo/common/json/GenericJSONConverter.java | 528 -------------
.../org/apache/dubbo/common/json/J2oVisitor.java | 389 ----------
.../java/org/apache/dubbo/common/json/JSON.java | 711 -----------------
.../org/apache/dubbo/common/json/JSONArray.java | 184 -----
.../apache/dubbo/common/json/JSONConverter.java | 44 --
.../org/apache/dubbo/common/json/JSONNode.java | 34 -
.../org/apache/dubbo/common/json/JSONObject.java | 209 -----
.../org/apache/dubbo/common/json/JSONReader.java | 68 --
.../org/apache/dubbo/common/json/JSONToken.java | 72 --
.../org/apache/dubbo/common/json/JSONVisitor.java | 107 ---
.../org/apache/dubbo/common/json/JSONWriter.java | 305 --------
.../apache/dubbo/common/json/ParseException.java | 33 -
.../java/org/apache/dubbo/common/json/Yylex.java | 847 ---------------------
.../apache/dubbo/common/json/JSONReaderTest.java | 44 --
.../org/apache/dubbo/common/json/JSONTest.java | 227 ------
.../apache/dubbo/common/json/JSONWriterTest.java | 50 --
.../org/apache/dubbo/common/json/MyException.java | 41 -
17 files changed, 3893 deletions(-)
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/GenericJSONConverter.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/GenericJSONConverter.java
deleted file mode 100644
index e7e0e6a..0000000
---
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/GenericJSONConverter.java
+++ /dev/null
@@ -1,528 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-import org.apache.dubbo.common.bytecode.Wrapper;
-import org.apache.dubbo.common.io.Bytes;
-
-import java.io.IOException;
-import java.lang.reflect.Array;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-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> GLOBAL_ENCODER_MAP = new
HashMap<Class<?>, Encoder>();
- private static final Map<Class<?>, Decoder> GLOBAL_DECODER_MAP = new
HashMap<Class<?>, Decoder>();
-
- static {
- // init encoder map.
- Encoder e = new Encoder() {
- @Override
- public void encode(Object obj, JSONWriter jb) throws IOException {
- jb.valueBoolean((Boolean) obj);
- }
- };
- GLOBAL_ENCODER_MAP.put(boolean.class, e);
- GLOBAL_ENCODER_MAP.put(Boolean.class, e);
-
- e = new Encoder() {
- @Override
- public void encode(Object obj, JSONWriter jb) throws IOException {
- jb.valueInt(((Number) obj).intValue());
- }
- };
- GLOBAL_ENCODER_MAP.put(int.class, e);
- GLOBAL_ENCODER_MAP.put(Integer.class, e);
- GLOBAL_ENCODER_MAP.put(short.class, e);
- GLOBAL_ENCODER_MAP.put(Short.class, e);
- GLOBAL_ENCODER_MAP.put(byte.class, e);
- GLOBAL_ENCODER_MAP.put(Byte.class, e);
- GLOBAL_ENCODER_MAP.put(AtomicInteger.class, e);
-
- e = new Encoder() {
- @Override
- public void encode(Object obj, JSONWriter jb) throws IOException {
- jb.valueString(Character.toString((Character) obj));
- }
- };
- GLOBAL_ENCODER_MAP.put(char.class, e);
- GLOBAL_ENCODER_MAP.put(Character.class, e);
-
- e = new Encoder() {
- @Override
- public void encode(Object obj, JSONWriter jb) throws IOException {
- jb.valueLong(((Number) obj).longValue());
- }
- };
- GLOBAL_ENCODER_MAP.put(long.class, e);
- GLOBAL_ENCODER_MAP.put(Long.class, e);
- GLOBAL_ENCODER_MAP.put(AtomicLong.class, e);
- GLOBAL_ENCODER_MAP.put(BigInteger.class, e);
-
- e = new Encoder() {
- @Override
- public void encode(Object obj, JSONWriter jb) throws IOException {
- jb.valueFloat(((Number) obj).floatValue());
- }
- };
- GLOBAL_ENCODER_MAP.put(float.class, e);
- GLOBAL_ENCODER_MAP.put(Float.class, e);
-
- e = new Encoder() {
- @Override
- public void encode(Object obj, JSONWriter jb) throws IOException {
- jb.valueDouble(((Number) obj).doubleValue());
- }
- };
- GLOBAL_ENCODER_MAP.put(double.class, e);
- GLOBAL_ENCODER_MAP.put(Double.class, e);
- GLOBAL_ENCODER_MAP.put(BigDecimal.class, e);
-
- e = new Encoder() {
- @Override
- public void encode(Object obj, JSONWriter jb) throws IOException {
- jb.valueString(obj.toString());
- }
- };
- GLOBAL_ENCODER_MAP.put(String.class, e);
- GLOBAL_ENCODER_MAP.put(StringBuilder.class, e);
- GLOBAL_ENCODER_MAP.put(StringBuffer.class, e);
-
- e = new Encoder() {
- @Override
- public void encode(Object obj, JSONWriter jb) throws IOException {
- jb.valueString(Bytes.bytes2base64((byte[]) obj));
- }
- };
- GLOBAL_ENCODER_MAP.put(byte[].class, e);
-
- e = new Encoder() {
- @Override
- public void encode(Object obj, JSONWriter jb) throws IOException {
- jb.valueString(new SimpleDateFormat(DATE_FORMAT).format((Date)
obj));
- }
- };
- GLOBAL_ENCODER_MAP.put(Date.class, e);
-
- // init decoder map.
- Decoder d = Object::toString;
- GLOBAL_DECODER_MAP.put(String.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Boolean) {
- return ((Boolean) jv).booleanValue();
- }
- return false;
- }
- };
- GLOBAL_DECODER_MAP.put(boolean.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Boolean) {
- return (Boolean) jv;
- }
- return (Boolean) null;
- }
- };
- GLOBAL_DECODER_MAP.put(Boolean.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof String && ((String) jv).length() > 0) {
- return ((String) jv).charAt(0);
- }
- return (char) 0;
- }
- };
- GLOBAL_DECODER_MAP.put(char.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof String && ((String) jv).length() > 0) {
- return ((String) jv).charAt(0);
- }
- return (Character) null;
- }
- };
- GLOBAL_DECODER_MAP.put(Character.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Number) {
- return ((Number) jv).intValue();
- }
- return 0;
- }
- };
- GLOBAL_DECODER_MAP.put(int.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Number) {
- return Integer.valueOf(((Number) jv).intValue());
- }
- return (Integer) null;
- }
- };
- GLOBAL_DECODER_MAP.put(Integer.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Number) {
- return ((Number) jv).shortValue();
- }
- return (short) 0;
- }
- };
- GLOBAL_DECODER_MAP.put(short.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Number) {
- return Short.valueOf(((Number) jv).shortValue());
- }
- return (Short) null;
- }
- };
- GLOBAL_DECODER_MAP.put(Short.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Number) {
- return ((Number) jv).longValue();
- }
- return (long) 0;
- }
- };
- GLOBAL_DECODER_MAP.put(long.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Number) {
- return Long.valueOf(((Number) jv).longValue());
- }
- return (Long) null;
- }
- };
- GLOBAL_DECODER_MAP.put(Long.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Number) {
- return ((Number) jv).floatValue();
- }
- return (float) 0;
- }
- };
- GLOBAL_DECODER_MAP.put(float.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Number) {
- return new Float(((Number) jv).floatValue());
- }
- return (Float) null;
- }
- };
- GLOBAL_DECODER_MAP.put(Float.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Number) {
- return ((Number) jv).doubleValue();
- }
- return (double) 0;
- }
- };
- GLOBAL_DECODER_MAP.put(double.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Number) {
- return new Double(((Number) jv).doubleValue());
- }
- return (Double) null;
- }
- };
- GLOBAL_DECODER_MAP.put(Double.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Number) {
- return ((Number) jv).byteValue();
- }
- return (byte) 0;
- }
- };
- GLOBAL_DECODER_MAP.put(byte.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) {
- if (jv instanceof Number) {
- return Byte.valueOf(((Number) jv).byteValue());
- }
- return (Byte) null;
- }
- };
- GLOBAL_DECODER_MAP.put(Byte.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) throws IOException {
- if (jv instanceof String) {
- return Bytes.base642bytes((String) jv);
- }
- return (byte[]) null;
- }
- };
- GLOBAL_DECODER_MAP.put(byte[].class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) throws IOException {
- return new StringBuilder(jv.toString());
- }
- };
- GLOBAL_DECODER_MAP.put(StringBuilder.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) throws IOException {
- return new StringBuffer(jv.toString());
- }
- };
- GLOBAL_DECODER_MAP.put(StringBuffer.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) throws IOException {
- if (jv instanceof Number) {
- return BigInteger.valueOf(((Number) jv).longValue());
- }
- return (BigInteger) null;
- }
- };
- GLOBAL_DECODER_MAP.put(BigInteger.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) throws IOException {
- if (jv instanceof Number) {
- return BigDecimal.valueOf(((Number) jv).doubleValue());
- }
- return (BigDecimal) null;
- }
- };
- GLOBAL_DECODER_MAP.put(BigDecimal.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) throws IOException {
- if (jv instanceof Number) {
- return new AtomicInteger(((Number) jv).intValue());
- }
- return (AtomicInteger) null;
- }
- };
- GLOBAL_DECODER_MAP.put(AtomicInteger.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) throws IOException {
- if (jv instanceof Number) {
- return new AtomicLong(((Number) jv).longValue());
- }
- return (AtomicLong) null;
- }
- };
- GLOBAL_DECODER_MAP.put(AtomicLong.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) throws IOException {
- if (jv instanceof String) {
- try {
- return new
SimpleDateFormat(DATE_FORMAT).parse((String) jv);
- } catch (ParseException e) {
- throw new IllegalArgumentException(e.getMessage(), e);
- }
- }
- if (jv instanceof Number) {
- return new Date(((Number) jv).longValue());
- }
- return (Date) null;
- }
- };
- GLOBAL_DECODER_MAP.put(Date.class, d);
-
- d = new Decoder() {
- @Override
- public Object decode(Object jv) throws IOException {
- if (jv instanceof String) {
- String[] items = ((String)jv).split("_");
- if(items.length == 1){
- return new Locale(items[0]);
- }
- if(items.length == 2){
- return new Locale(items[0], items[1]);
- }
- return new Locale(items[0], items[1], items[2]);
- }
- return (Locale)null;
- }
- };
- GLOBAL_DECODER_MAP.put(Locale.class, d);
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public void writeValue(Object obj, JSONWriter jb, boolean writeClass)
throws IOException {
- if (obj == null) {
- jb.valueNull();
- return;
- }
- Class<?> c = obj.getClass();
- Encoder encoder = GLOBAL_ENCODER_MAP.get(c);
-
- if (encoder != null) {
- encoder.encode(obj, jb);
- } else if (obj instanceof JSONNode) {
- ((JSONNode) obj).writeJSON(this, jb, writeClass);
- } else if (c.isEnum()) {
- jb.valueString(((Enum<?>) obj).name());
- } else if (c.isArray()) {
- int len = Array.getLength(obj);
- jb.arrayBegin();
- for (int i = 0; i < len; i++) {
- writeValue(Array.get(obj, i), jb, writeClass);
- }
- jb.arrayEnd();
- } else if (Map.class.isAssignableFrom(c)) {
- Object key, value;
- jb.objectBegin();
- for (Map.Entry<Object, Object> entry : ((Map<Object, Object>)
obj).entrySet()) {
- key = entry.getKey();
- if (key == null) {
- continue;
- }
- jb.objectItem(key.toString());
-
- value = entry.getValue();
- if (value == null) {
- jb.valueNull();
- } else {
- writeValue(value, jb, writeClass);
- }
- }
- jb.objectEnd();
- } else if (Collection.class.isAssignableFrom(c)) {
- jb.arrayBegin();
- for (Object item : (Collection<Object>) obj) {
- if (item == null) {
- jb.valueNull();
- } else {
- writeValue(item, jb, writeClass);
- }
- }
- jb.arrayEnd();
- } else if(obj instanceof Locale) {
- jb.valueString(obj.toString());
- } else {
- jb.objectBegin();
-
- Wrapper w = Wrapper.getWrapper(c);
- String[] pns = w.getPropertyNames();
-
- for (String pn : pns) {
- if ((obj instanceof Throwable) && (
- "localizedMessage".equals(pn)
- || "cause".equals(pn)
- || "suppressed".equals(pn)
- || "stackTrace".equals(pn))) {
- continue;
- }
-
- jb.objectItem(pn);
-
- Object value = w.getPropertyValue(obj, pn);
- if (value == null || value == obj) {
- jb.valueNull();
- } else {
- writeValue(value, jb, writeClass);
- }
- }
- if (writeClass) {
- jb.objectItem(JSONVisitor.CLASS_PROPERTY);
- writeValue(obj.getClass().getName(), jb, writeClass);
- }
- jb.objectEnd();
- }
- }
-
- @Override
- @SuppressWarnings({"unchecked", "rawtypes"})
- public Object readValue(Class<?> c, Object jv) throws IOException {
- if (jv == null) {
- return null;
- }
- Decoder decoder = GLOBAL_DECODER_MAP.get(c);
- if (decoder != null) {
- return decoder.decode(jv);
- }
- if (c.isEnum()) {
- return Enum.valueOf((Class<Enum>) c, String.valueOf(jv));
- }
- return jv;
- }
-
- protected interface Encoder {
- void encode(Object obj, JSONWriter jb) throws IOException;
- }
-
- protected interface Decoder {
- Object decode(Object jv) throws IOException;
- }
-}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/J2oVisitor.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/J2oVisitor.java
deleted file mode 100644
index 6103f4a..0000000
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/J2oVisitor.java
+++ /dev/null
@@ -1,389 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-import org.apache.dubbo.common.bytecode.Wrapper;
-import org.apache.dubbo.common.utils.Stack;
-import org.apache.dubbo.common.utils.StringUtils;
-
-import java.io.IOException;
-import java.lang.reflect.Array;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- * JSON to Object visitor.
- */
-@Deprecated
-class J2oVisitor implements JSONVisitor {
- public static final boolean[] EMPTY_BOOL_ARRAY = new boolean[0];
-
- public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
-
- public static final char[] EMPTY_CHAR_ARRAY = new char[0];
-
- public static final short[] EMPTY_SHORT_ARRAY = new short[0];
-
- public static final int[] EMPTY_INT_ARRAY = new int[0];
-
- public static final long[] EMPTY_LONG_ARRAY = new long[0];
-
- public static final float[] EMPTY_FLOAT_ARRAY = new float[0];
-
- public static final double[] EMPTY_DOUBLE_ARRAY = new double[0];
-
- public static final String[] EMPTY_STRING_ARRAY = new String[0];
-
- private Class<?>[] mTypes;
-
- private Class<?> mType = Object[].class;
-
- private Object mValue;
-
- private Wrapper mWrapper;
-
- private JSONConverter mConverter;
-
- private Stack<Object> mStack = new Stack<Object>();
-
- J2oVisitor(Class<?> type, JSONConverter jc) {
- mType = type;
- mConverter = jc;
- }
-
- J2oVisitor(Class<?>[] types, JSONConverter jc) {
- mTypes = types;
- mConverter = jc;
- }
-
- private static Object toArray(Class<?> c, Stack<Object> list, int len)
throws ParseException {
- if (c == String.class) {
- if (len == 0) {
- return EMPTY_STRING_ARRAY;
- } else {
- Object o;
- String[] ss = new String[len];
- for (int i = len - 1; i >= 0; i--) {
- o = list.pop();
- ss[i] = (o == null ? null : o.toString());
- }
- return ss;
- }
- }
- if (c == boolean.class) {
- if (len == 0) {
- return EMPTY_BOOL_ARRAY;
- }
- Object o;
- boolean[] ret = new boolean[len];
- for (int i = len - 1; i >= 0; i--) {
- o = list.pop();
- if (o instanceof Boolean) {
- ret[i] = ((Boolean) o).booleanValue();
- }
- }
- return ret;
- }
- if (c == int.class) {
- if (len == 0) {
- return EMPTY_INT_ARRAY;
- }
- Object o;
- int[] ret = new int[len];
- for (int i = len - 1; i >= 0; i--) {
- o = list.pop();
- if (o instanceof Number) {
- ret[i] = ((Number) o).intValue();
- }
- }
- return ret;
- }
- if (c == long.class) {
- if (len == 0) {
- return EMPTY_LONG_ARRAY;
- }
- Object o;
- long[] ret = new long[len];
- for (int i = len - 1; i >= 0; i--) {
- o = list.pop();
- if (o instanceof Number) {
- ret[i] = ((Number) o).longValue();
- }
- }
- return ret;
- }
- if (c == float.class) {
- if (len == 0) {
- return EMPTY_FLOAT_ARRAY;
- }
- Object o;
- float[] ret = new float[len];
- for (int i = len - 1; i >= 0; i--) {
- o = list.pop();
- if (o instanceof Number) {
- ret[i] = ((Number) o).floatValue();
- }
- }
- return ret;
- }
- if (c == double.class) {
- if (len == 0) {
- return EMPTY_DOUBLE_ARRAY;
- }
- Object o;
- double[] ret = new double[len];
- for (int i = len - 1; i >= 0; i--) {
- o = list.pop();
- if (o instanceof Number) {
- ret[i] = ((Number) o).doubleValue();
- }
- }
- return ret;
- }
- if (c == byte.class) {
- if (len == 0) {
- return EMPTY_BYTE_ARRAY;
- }
- Object o;
- byte[] ret = new byte[len];
- for (int i = len - 1; i >= 0; i--) {
- o = list.pop();
- if (o instanceof Number) {
- ret[i] = ((Number) o).byteValue();
- }
- }
- return ret;
- }
- if (c == char.class) {
- if (len == 0) {
- return EMPTY_CHAR_ARRAY;
- }
- Object o;
- char[] ret = new char[len];
- for (int i = len - 1; i >= 0; i--) {
- o = list.pop();
- if (o instanceof Character) {
- ret[i] = ((Character) o).charValue();
- }
- }
- return ret;
- }
- if (c == short.class) {
- if (len == 0) {
- return EMPTY_SHORT_ARRAY;
- }
- Object o;
- short[] ret = new short[len];
- for (int i = len - 1; i >= 0; i--) {
- o = list.pop();
- if (o instanceof Number) {
- ret[i] = ((Number) o).shortValue();
- }
- }
- return ret;
- }
-
- Object ret = Array.newInstance(c, len);
- for (int i = len - 1; i >= 0; i--) {
- Array.set(ret, i, list.pop());
- }
- return ret;
- }
-
- private static String name(Class<?>[] types) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < types.length; i++) {
- if (i > 0) {
- sb.append(", ");
- }
- sb.append(types[i].getName());
- }
- return sb.toString();
- }
-
- @Override
- public void begin() {
- }
-
- @Override
- public Object end(Object obj, boolean isValue) throws ParseException {
- mStack.clear();
- try {
- return mConverter.readValue(mType, obj);
- } catch (IOException e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- }
-
- @Override
- public void objectBegin() throws ParseException {
- mStack.push(mValue);
- mStack.push(mType);
- mStack.push(mWrapper);
-
- if (mType == Object.class || Map.class.isAssignableFrom(mType)) {
- if (!mType.isInterface() && mType != Object.class) {
- try {
- mValue = mType.newInstance();
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- } else if (mType == ConcurrentMap.class) {
- mValue = new ConcurrentHashMap<String, Object>();
- } else {
- mValue = new HashMap<String, Object>();
- }
- mWrapper = null;
- } else {
- try {
- mValue = mType.newInstance();
- mWrapper = Wrapper.getWrapper(mType);
- } catch (IllegalAccessException | InstantiationException e) {
- throw new ParseException(StringUtils.toString(e));
- }
- }
- }
-
- @Override
- public Object objectEnd(int count) {
- Object ret = mValue;
- mWrapper = (Wrapper) mStack.pop();
- mType = (Class<?>) mStack.pop();
- mValue = mStack.pop();
- return ret;
- }
-
- @Override
- public void objectItem(String name) {
- mStack.push(name); // push name.
- mType = (mWrapper == null ? Object.class :
mWrapper.getPropertyType(name));
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public void objectItemValue(Object obj, boolean isValue) throws
ParseException {
- String name = (String) mStack.pop(); // pop name.
- if (mWrapper == null) {
- ((Map<String, Object>) mValue).put(name, obj);
- } else {
- if (mType != null) {
- if (isValue && obj != null) {
- try {
- obj = mConverter.readValue(mType, obj);
- } catch (IOException e) {
- throw new ParseException(StringUtils.toString(e));
- }
- }
- if (mValue instanceof Throwable && "message".equals(name)) {
- try {
- Field field =
Throwable.class.getDeclaredField("detailMessage");
- if (!field.isAccessible()) {
- field.setAccessible(true);
- }
- field.set(mValue, obj);
- } catch (NoSuchFieldException | IllegalAccessException e) {
- throw new ParseException(StringUtils.toString(e));
- }
- } else if (!CLASS_PROPERTY.equals(name)) {
- mWrapper.setPropertyValue(mValue, name, obj);
- }
- }
- }
- }
-
- @Override
- public void arrayBegin() throws ParseException {
- mStack.push(mType);
-
- if (mType.isArray()) {
- mType = mType.getComponentType();
- } else if (mType == Object.class ||
Collection.class.isAssignableFrom(mType)) {
- mType = Object.class;
- } else {
- throw new ParseException("Convert error, can not load json array
data into class [" + mType.getName() + "].");
- }
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public Object arrayEnd(int count) throws ParseException {
- Object ret;
- mType = (Class<?>) mStack.get(-1 - count);
-
- if (mType.isArray()) {
- ret = toArray(mType.getComponentType(), mStack, count);
- } else {
- Collection<Object> items;
- if (mType == Object.class ||
Collection.class.isAssignableFrom(mType)) {
- if (!mType.isInterface() && mType != Object.class) {
- try {
- items = (Collection<Object>) mType.newInstance();
- } catch (Exception e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
- } else if (mType.isAssignableFrom(ArrayList.class)) { // List
- items = new ArrayList<Object>(count);
- } else if (mType.isAssignableFrom(HashSet.class)) { // Set
- items = new HashSet<Object>(count);
- } else if (mType.isAssignableFrom(LinkedList.class)) { // Queue
- items = new LinkedList<Object>();
- } else { // Other
- items = new ArrayList<Object>(count);
- }
- } else {
- throw new ParseException("Convert error, can not load json
array data into class [" + mType.getName() + "].");
- }
- for (int i = 0; i < count; i++) {
- items.add(mStack.remove(i - count));
- }
- ret = items;
- }
- mStack.pop();
- return ret;
- }
-
- @Override
- public void arrayItem(int index) throws ParseException {
- if (mTypes != null && mStack.size() == index + 1) {
- if (index < mTypes.length) {
- mType = mTypes[index];
- } else {
- throw new ParseException("Can not load json array data into ["
+ name(mTypes) + "].");
- }
- }
- }
-
- @Override
- public void arrayItemValue(int index, Object obj, boolean isValue) throws
ParseException {
- if (isValue && obj != null) {
- try {
- obj = mConverter.readValue(mType, obj);
- } catch (IOException e) {
- throw new ParseException(e.getMessage());
- }
- }
-
- mStack.push(obj);
- }
-}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSON.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSON.java
deleted file mode 100644
index 55dea2c..0000000
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSON.java
+++ /dev/null
@@ -1,711 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-import org.apache.dubbo.common.bytecode.Wrapper;
-import org.apache.dubbo.common.utils.Stack;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.io.Writer;
-
-/**
- * JSON.
- */
-@Deprecated
-public class JSON {
- public static final char LBRACE = '{', RBRACE = '}';
-
- public static final char LSQUARE = '[', RSQUARE = ']';
-
- public static final char COMMA = ',', COLON = ':', QUOTE = '"';
-
- public static final String NULL = "null";
- // state.
- public static final byte END = 0, START = 1, OBJECT_ITEM = 2, OBJECT_VALUE
= 3, ARRAY_ITEM = 4;
- static final JSONConverter DEFAULT_CONVERTER = new GenericJSONConverter();
-
- private JSON() {
- }
-
- /**
- * json string.
- *
- * @param obj object.
- * @return json string.
- * @throws IOException
- */
- public static String json(Object obj) throws IOException {
- if (obj == null) {
- return NULL;
- }
- StringWriter sw = new StringWriter();
- try {
- json(obj, sw);
- return sw.getBuffer().toString();
- } finally {
- sw.close();
- }
- }
-
- /**
- * write json.
- *
- * @param obj object.
- * @param writer writer.
- * @throws IOException
- */
- public static void json(Object obj, Writer writer) throws IOException {
- json(obj, writer, false);
- }
-
- public static void json(Object obj, Writer writer, boolean writeClass)
throws IOException {
- if (obj == null) {
- writer.write(NULL);
- } else {
- json(obj, new JSONWriter(writer), writeClass);
- }
- }
-
- /**
- * json string.
- *
- * @param obj object.
- * @param properties property name array.
- * @return json string.
- * @throws IOException
- */
- public static String json(Object obj, String[] properties) throws
IOException {
- if (obj == null) {
- return NULL;
- }
- StringWriter sw = new StringWriter();
- try {
- json(obj, properties, sw);
- return sw.getBuffer().toString();
- } finally {
- sw.close();
- }
- }
-
- public static void json(Object obj, final String[] properties, Writer
writer) throws IOException {
- json(obj, properties, writer, false);
- }
-
- /**
- * write json.
- *
- * @param obj object.
- * @param properties property name array.
- * @param writer writer.
- * @throws IOException
- */
- public static void json(Object obj, final String[] properties, Writer
writer, boolean writeClass) throws IOException {
- if (obj == null) {
- writer.write(NULL);
- } else {
- json(obj, properties, new JSONWriter(writer), writeClass);
- }
- }
-
- private static void json(Object obj, JSONWriter jb, boolean writeClass)
throws IOException {
- if (obj == null) {
- jb.valueNull();
- } else {
- DEFAULT_CONVERTER.writeValue(obj, jb, writeClass);
- }
- }
-
- private static void json(Object obj, String[] properties, JSONWriter jb,
boolean writeClass) throws IOException {
- if (obj == null) {
- jb.valueNull();
- } else {
- Wrapper wrapper = Wrapper.getWrapper(obj.getClass());
-
- Object value;
- jb.objectBegin();
- for (String prop : properties) {
- jb.objectItem(prop);
- value = wrapper.getPropertyValue(obj, prop);
- if (value == null) {
- jb.valueNull();
- } else {
- DEFAULT_CONVERTER.writeValue(value, jb, writeClass);
- }
- }
- jb.objectEnd();
- }
- }
-
- /**
- * parse json.
- *
- * @param json json source.
- * @return JSONObject or JSONArray or Boolean or Long or Double or String
or null
- * @throws ParseException
- */
- public static Object parse(String json) throws ParseException {
- StringReader reader = new StringReader(json);
- try {
- return parse(reader);
- } catch (IOException e) {
- throw new ParseException(e.getMessage());
- } finally {
- reader.close();
- }
- }
-
- /**
- * parse json.
- *
- * @param reader reader.
- * @return JSONObject or JSONArray or Boolean or Long or Double or String
or null
- * @throws IOException
- * @throws ParseException
- */
- public static Object parse(Reader reader) throws IOException,
ParseException {
- return parse(reader, JSONToken.ANY);
- }
-
- /**
- * parse json.
- *
- * @param json json string.
- * @param type target type.
- * @return result.
- * @throws ParseException
- */
- public static <T> T parse(String json, Class<T> type) throws
ParseException {
- StringReader reader = new StringReader(json);
- try {
- return parse(reader, type);
- } catch (IOException e) {
- throw new ParseException(e.getMessage());
- } finally {
- reader.close();
- }
- }
-
- /**
- * parse json
- *
- * @param reader json source.
- * @param type target type.
- * @return result.
- * @throws IOException
- * @throws ParseException
- */
- @SuppressWarnings("unchecked")
- public static <T> T parse(Reader reader, Class<T> type) throws
IOException, ParseException {
- return (T) parse(reader, new J2oVisitor(type, DEFAULT_CONVERTER),
JSONToken.ANY);
- }
-
- /**
- * parse json.
- *
- * @param json json string.
- * @param types target type array.
- * @return result.
- * @throws ParseException
- */
- public static Object[] parse(String json, Class<?>[] types) throws
ParseException {
- StringReader reader = new StringReader(json);
- try {
- return (Object[]) parse(reader, types);
- } catch (IOException e) {
- throw new ParseException(e.getMessage());
- } finally {
- reader.close();
- }
- }
-
- /**
- * parse json.
- *
- * @param reader json source.
- * @param types target type array.
- * @return result.
- * @throws IOException
- * @throws ParseException
- */
- public static Object[] parse(Reader reader, Class<?>[] types) throws
IOException, ParseException {
- return (Object[]) parse(reader, new J2oVisitor(types,
DEFAULT_CONVERTER), JSONToken.LSQUARE);
- }
-
- /**
- * parse json.
- *
- * @param json json string.
- * @param handler handler.
- * @return result.
- * @throws ParseException
- */
- public static Object parse(String json, JSONVisitor handler) throws
ParseException {
- StringReader reader = new StringReader(json);
- try {
- return parse(reader, handler);
- } catch (IOException e) {
- throw new ParseException(e.getMessage());
- } finally {
- reader.close();
- }
- }
-
- /**
- * parse json.
- *
- * @param reader json source.
- * @param handler handler.
- * @return result.
- * @throws IOException
- * @throws ParseException
- */
- public static Object parse(Reader reader, JSONVisitor handler) throws
IOException, ParseException {
- return parse(reader, handler, JSONToken.ANY);
- }
-
- private static Object parse(Reader reader, int expect) throws IOException,
ParseException {
- JSONReader jr = new JSONReader(reader);
- JSONToken token = jr.nextToken(expect);
-
- byte state = START;
- Object value = null, tmp;
- Stack<Entry> stack = new Stack<Entry>();
-
- do {
- switch (state) {
- case END:
- throw new ParseException("JSON source format error.");
- case START: {
- switch (token.type) {
- case JSONToken.NULL:
- case JSONToken.BOOL:
- case JSONToken.INT:
- case JSONToken.FLOAT:
- case JSONToken.STRING: {
- state = END;
- value = token.value;
- break;
- }
- case JSONToken.LSQUARE: {
- state = ARRAY_ITEM;
- value = new JSONArray();
- break;
- }
- case JSONToken.LBRACE: {
- state = OBJECT_ITEM;
- value = new JSONObject();
- break;
- }
- default:
- throw new ParseException("Unexcepted token expect
[ VALUE or '[' or '{' ] get '" + JSONToken.token2string(token.type) + "'");
- }
- break;
- }
- case ARRAY_ITEM: {
- switch (token.type) {
- case JSONToken.COMMA:
- break;
- case JSONToken.NULL:
- case JSONToken.BOOL:
- case JSONToken.INT:
- case JSONToken.FLOAT:
- case JSONToken.STRING: {
- ((JSONArray) value).add(token.value);
- break;
- }
- case JSONToken.RSQUARE: // end of array.
- {
- if (stack.isEmpty()) {
- state = END;
- } else {
- Entry entry = stack.pop();
- state = entry.state;
- value = entry.value;
- }
- break;
- }
- case JSONToken.LSQUARE: // array begin.
- {
- tmp = new JSONArray();
- ((JSONArray) value).add(tmp);
- stack.push(new Entry(state, value));
-
- state = ARRAY_ITEM;
- value = tmp;
- break;
- }
- case JSONToken.LBRACE: // object begin.
- {
- tmp = new JSONObject();
- ((JSONArray) value).add(tmp);
- stack.push(new Entry(state, value));
-
- state = OBJECT_ITEM;
- value = tmp;
- break;
- }
- default:
- throw new ParseException("Unexcepted token expect
[ VALUE or ',' or ']' or '[' or '{' ] get '" +
JSONToken.token2string(token.type) + "'");
- }
- break;
- }
- case OBJECT_ITEM: {
- switch (token.type) {
- case JSONToken.COMMA:
- break;
- case JSONToken.IDENT: // item name.
- {
- stack.push(new Entry(OBJECT_ITEM, (String)
token.value));
- state = OBJECT_VALUE;
- break;
- }
- case JSONToken.NULL: {
- stack.push(new Entry(OBJECT_ITEM, "null"));
- state = OBJECT_VALUE;
- break;
- }
- case JSONToken.BOOL:
- case JSONToken.INT:
- case JSONToken.FLOAT:
- case JSONToken.STRING: {
- stack.push(new Entry(OBJECT_ITEM,
token.value.toString()));
- state = OBJECT_VALUE;
- break;
- }
- case JSONToken.RBRACE: // end of object.
- {
- if (stack.isEmpty()) {
- state = END;
- } else {
- Entry entry = stack.pop();
- state = entry.state;
- value = entry.value;
- }
- break;
- }
- default:
- throw new ParseException("Unexcepted token expect
[ IDENT or VALUE or ',' or '}' ] get '" + JSONToken.token2string(token.type) +
"'");
- }
- break;
- }
- case OBJECT_VALUE: {
- switch (token.type) {
- case JSONToken.COLON:
- break;
- case JSONToken.NULL:
- case JSONToken.BOOL:
- case JSONToken.INT:
- case JSONToken.FLOAT:
- case JSONToken.STRING: {
- ((JSONObject) value).put((String)
stack.pop().value, token.value);
- state = OBJECT_ITEM;
- break;
- }
- case JSONToken.LSQUARE: // array begin.
- {
- tmp = new JSONArray();
- ((JSONObject) value).put((String)
stack.pop().value, tmp);
- stack.push(new Entry(OBJECT_ITEM, value));
-
- state = ARRAY_ITEM;
- value = tmp;
- break;
- }
- case JSONToken.LBRACE: // object begin.
- {
- tmp = new JSONObject();
- ((JSONObject) value).put((String)
stack.pop().value, tmp);
- stack.push(new Entry(OBJECT_ITEM, value));
-
- state = OBJECT_ITEM;
- value = tmp;
- break;
- }
- default:
- throw new ParseException("Unexcepted token expect
[ VALUE or '[' or '{' ] get '" + JSONToken.token2string(token.type) + "'");
- }
- break;
- }
- default:
- throw new ParseException("Unexcepted state.");
- }
- }
- while ((token = jr.nextToken()) != null);
- stack.clear();
- return value;
- }
-
- private static Object parse(Reader reader, JSONVisitor handler, int
expect) throws IOException, ParseException {
- JSONReader jr = new JSONReader(reader);
- JSONToken token = jr.nextToken(expect);
-
- Object value = null;
- int state = START, index = 0;
- Stack<int[]> states = new Stack<int[]>();
- boolean pv = false;
-
- handler.begin();
- do {
- switch (state) {
- case END:
- throw new ParseException("JSON source format error.");
- case START: {
- switch (token.type) {
- case JSONToken.NULL: {
- value = token.value;
- state = END;
- pv = true;
- break;
- }
- case JSONToken.BOOL: {
- value = token.value;
- state = END;
- pv = true;
- break;
- }
- case JSONToken.INT: {
- value = token.value;
- state = END;
- pv = true;
- break;
- }
- case JSONToken.FLOAT: {
- value = token.value;
- state = END;
- pv = true;
- break;
- }
- case JSONToken.STRING: {
- value = token.value;
- state = END;
- pv = true;
- break;
- }
- case JSONToken.LSQUARE: {
- handler.arrayBegin();
- state = ARRAY_ITEM;
- break;
- }
- case JSONToken.LBRACE: {
- handler.objectBegin();
- state = OBJECT_ITEM;
- break;
- }
- default:
- throw new ParseException("Unexcepted token expect
[ VALUE or '[' or '{' ] get '" + JSONToken.token2string(token.type) + "'");
- }
- break;
- }
- case ARRAY_ITEM: {
- switch (token.type) {
- case JSONToken.COMMA:
- break;
- case JSONToken.NULL: {
- handler.arrayItem(index++);
- handler.arrayItemValue(index, token.value, true);
- break;
- }
- case JSONToken.BOOL: {
- handler.arrayItem(index++);
- handler.arrayItemValue(index, token.value, true);
- break;
- }
- case JSONToken.INT: {
- handler.arrayItem(index++);
- handler.arrayItemValue(index, token.value, true);
- break;
- }
- case JSONToken.FLOAT: {
- handler.arrayItem(index++);
- handler.arrayItemValue(index, token.value, true);
- break;
- }
- case JSONToken.STRING: {
- handler.arrayItem(index++);
- handler.arrayItemValue(index, token.value, true);
- break;
- }
- case JSONToken.LSQUARE: {
- handler.arrayItem(index++);
- states.push(new int[]{state, index});
-
- index = 0;
- state = ARRAY_ITEM;
- handler.arrayBegin();
- break;
- }
- case JSONToken.LBRACE: {
- handler.arrayItem(index++);
- states.push(new int[]{state, index});
-
- index = 0;
- state = OBJECT_ITEM;
- handler.objectBegin();
- break;
- }
- case JSONToken.RSQUARE: {
- if (states.isEmpty()) {
- value = handler.arrayEnd(index);
- state = END;
- } else {
- value = handler.arrayEnd(index);
- int[] tmp = states.pop();
- state = tmp[0];
- index = tmp[1];
-
- switch (state) {
- case ARRAY_ITEM: {
- handler.arrayItemValue(index, value,
false);
- break;
- }
- case OBJECT_ITEM: {
- handler.objectItemValue(value, false);
- break;
- }
- default:
- }
- }
- break;
- }
- default:
- throw new ParseException("Unexcepted token expect
[ VALUE or ',' or ']' or '[' or '{' ] get '" +
JSONToken.token2string(token.type) + "'");
- }
- break;
- }
- case OBJECT_ITEM: {
- switch (token.type) {
- case JSONToken.COMMA:
- break;
- case JSONToken.IDENT: {
- handler.objectItem((String) token.value);
- state = OBJECT_VALUE;
- break;
- }
- case JSONToken.NULL: {
- handler.objectItem("null");
- state = OBJECT_VALUE;
- break;
- }
- case JSONToken.BOOL:
- case JSONToken.INT:
- case JSONToken.FLOAT:
- case JSONToken.STRING: {
- handler.objectItem(token.value.toString());
- state = OBJECT_VALUE;
- break;
- }
- case JSONToken.RBRACE: {
- if (states.isEmpty()) {
- value = handler.objectEnd(index);
- state = END;
- } else {
- value = handler.objectEnd(index);
- int[] tmp = states.pop();
- state = tmp[0];
- index = tmp[1];
-
- switch (state) {
- case ARRAY_ITEM: {
- handler.arrayItemValue(index, value,
false);
- break;
- }
- case OBJECT_ITEM: {
- handler.objectItemValue(value, false);
- break;
- }
- default:
- }
- }
- break;
- }
- default:
- throw new ParseException("Unexcepted token expect
[ IDENT or VALUE or ',' or '}' ] get '" + JSONToken.token2string(token.type) +
"'");
- }
- break;
- }
- case OBJECT_VALUE: {
- switch (token.type) {
- case JSONToken.COLON:
- break;
- case JSONToken.NULL: {
- handler.objectItemValue(token.value, true);
- state = OBJECT_ITEM;
- break;
- }
- case JSONToken.BOOL: {
- handler.objectItemValue(token.value, true);
- state = OBJECT_ITEM;
- break;
- }
- case JSONToken.INT: {
- handler.objectItemValue(token.value, true);
- state = OBJECT_ITEM;
- break;
- }
- case JSONToken.FLOAT: {
- handler.objectItemValue(token.value, true);
- state = OBJECT_ITEM;
- break;
- }
- case JSONToken.STRING: {
- handler.objectItemValue(token.value, true);
- state = OBJECT_ITEM;
- break;
- }
- case JSONToken.LSQUARE: {
- states.push(new int[]{OBJECT_ITEM, index});
-
- index = 0;
- state = ARRAY_ITEM;
- handler.arrayBegin();
- break;
- }
- case JSONToken.LBRACE: {
- states.push(new int[]{OBJECT_ITEM, index});
-
- index = 0;
- state = OBJECT_ITEM;
- handler.objectBegin();
- break;
- }
- default:
- throw new ParseException("Unexcepted token expect
[ VALUE or '[' or '{' ] get '" + JSONToken.token2string(token.type) + "'");
- }
- break;
- }
- default:
- throw new ParseException("Unexcepted state.");
- }
- }
- while ((token = jr.nextToken()) != null);
- states.clear();
- return handler.end(value, pv);
- }
-
- private static class Entry {
- byte state;
- Object value;
-
- Entry(byte s, Object v) {
- state = s;
- value = v;
- }
- }
-}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONArray.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONArray.java
deleted file mode 100644
index d1947da..0000000
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONArray.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- * JSONArray.
- */
-@Deprecated
-public class JSONArray implements JSONNode {
- private List<Object> mArray = new ArrayList<Object>();
-
- /**
- * get.
- *
- * @param index index.
- * @return boolean or long or double or String or JSONArray or JSONObject
or null.
- */
- public Object get(int index) {
- return mArray.get(index);
- }
-
- /**
- * get boolean value.
- *
- * @param index index.
- * @param def default value.
- * @return value or default value.
- */
- public boolean getBoolean(int index, boolean def) {
- Object tmp = mArray.get(index);
- return tmp instanceof Boolean ? ((Boolean) tmp).booleanValue() : def;
- }
-
- /**
- * get int value.
- *
- * @param index index.
- * @param def default value.
- * @return value or default value.
- */
- public int getInt(int index, int def) {
- Object tmp = mArray.get(index);
- return tmp instanceof Number ? ((Number) tmp).intValue() : def;
- }
-
- /**
- * get long value.
- *
- * @param index index.
- * @param def default value.
- * @return value or default value.
- */
- public long getLong(int index, long def) {
- Object tmp = mArray.get(index);
- return tmp instanceof Number ? ((Number) tmp).longValue() : def;
- }
-
- /**
- * get float value.
- *
- * @param index index.
- * @param def default value.
- * @return value or default value.
- */
- public float getFloat(int index, float def) {
- Object tmp = mArray.get(index);
- return tmp instanceof Number ? ((Number) tmp).floatValue() : def;
- }
-
- /**
- * get double value.
- *
- * @param index index.
- * @param def default value.
- * @return value or default value.
- */
- public double getDouble(int index, double def) {
- Object tmp = mArray.get(index);
- return tmp instanceof Number ? ((Number) tmp).doubleValue() : def;
- }
-
- /**
- * get string value.
- *
- * @param index index.
- * @return value or default value.
- */
- public String getString(int index) {
- Object tmp = mArray.get(index);
- return tmp == null ? null : tmp.toString();
- }
-
- /**
- * get JSONArray value.
- *
- * @param index index.
- * @return value or default value.
- */
- public JSONArray getArray(int index) {
- Object tmp = mArray.get(index);
- return tmp == null ? null : tmp instanceof JSONArray ? (JSONArray) tmp
: null;
- }
-
- /**
- * get JSONObject value.
- *
- * @param index index.
- * @return value or default value.
- */
- public JSONObject getObject(int index) {
- Object tmp = mArray.get(index);
- return tmp == null ? null : tmp instanceof JSONObject ? (JSONObject)
tmp : null;
- }
-
- /**
- * get array length.
- *
- * @return length.
- */
- public int length() {
- return mArray.size();
- }
-
- /**
- * add item.
- */
- public void add(Object ele) {
- mArray.add(ele);
- }
-
- /**
- * add items.
- */
- public void addAll(Object[] eles) {
- for (Object ele : eles) {
- mArray.add(ele);
- }
- }
-
- /**
- * add items.
- */
- public void addAll(Collection<?> c) {
- mArray.addAll(c);
- }
-
- /**
- * write json.
- *
- * @param jc json converter
- * @param jb json builder.
- */
- @Override
- public void writeJSON(JSONConverter jc, JSONWriter jb, boolean writeClass)
throws IOException {
- jb.arrayBegin();
- for (Object item : mArray) {
- if (item == null) {
- jb.valueNull();
- } else {
- jc.writeValue(item, jb, writeClass);
- }
- }
- jb.arrayEnd();
- }
-}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONConverter.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONConverter.java
deleted file mode 100644
index 2226029..0000000
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONConverter.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-import java.io.IOException;
-
-/**
- * JSON converter.
- */
-@Deprecated
-public interface JSONConverter {
- /**
- * write object.
- *
- * @param obj obj.
- * @param builder builder.
- * @throws IOException
- */
- void writeValue(Object obj, JSONWriter builder, boolean writeClass) throws
IOException;
-
- /**
- * convert json value to target class.
- *
- * @param type target type.
- * @param jv json value.
- * @return target object.
- * @throws IOException
- */
- Object readValue(Class<?> type, Object jv) throws IOException;
-}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONNode.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONNode.java
deleted file mode 100644
index 6d2fa2f..0000000
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONNode.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-import java.io.IOException;
-
-/**
- * JSONSerializable.
- */
-@Deprecated
-interface JSONNode {
- /**
- * write json string.
- *
- * @param jc json converter.
- * @param jb json builder.
- * @throws IOException
- */
- void writeJSON(JSONConverter jc, JSONWriter jb, boolean writeClass) throws
IOException;
-}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONObject.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONObject.java
deleted file mode 100644
index d1634a8..0000000
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONObject.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * JSONObject.
- */
-@Deprecated
-public class JSONObject implements JSONNode {
- private Map<String, Object> mMap = new HashMap<String, Object>();
-
- /**
- * get.
- *
- * @param key key.
- * @return boolean or long or double or String or JSONArray or JSONObject
or null.
- */
- public Object get(String key) {
- return mMap.get(key);
- }
-
- /**
- * get boolean value.
- *
- * @param key key.
- * @param def default value.
- * @return value or default value.
- */
- public boolean getBoolean(String key, boolean def) {
- Object tmp = mMap.get(key);
- return tmp instanceof Boolean ? (Boolean) tmp : def;
- }
-
- /**
- * get int value.
- *
- * @param key key.
- * @param def default value.
- * @return value or default value.
- */
- public int getInt(String key, int def) {
- Object tmp = mMap.get(key);
- return tmp instanceof Number ? ((Number) tmp).intValue() : def;
- }
-
- /**
- * get long value.
- *
- * @param key key.
- * @param def default value.
- * @return value or default value.
- */
- public long getLong(String key, long def) {
- Object tmp = mMap.get(key);
- return tmp instanceof Number ? ((Number) tmp).longValue() : def;
- }
-
- /**
- * get float value.
- *
- * @param key key.
- * @param def default value.
- * @return value or default value.
- */
- public float getFloat(String key, float def) {
- Object tmp = mMap.get(key);
- return tmp instanceof Number ? ((Number) tmp).floatValue() : def;
- }
-
- /**
- * get double value.
- *
- * @param key key.
- * @param def default value.
- * @return value or default value.
- */
- public double getDouble(String key, double def) {
- Object tmp = mMap.get(key);
- return tmp instanceof Number ? ((Number) tmp).doubleValue() : def;
- }
-
- /**
- * get string value.
- *
- * @param key key.
- * @return value or default value.
- */
- public String getString(String key) {
- Object tmp = mMap.get(key);
- return tmp == null ? null : tmp.toString();
- }
-
- /**
- * get JSONArray value.
- *
- * @param key key.
- * @return value or default value.
- */
- public JSONArray getArray(String key) {
- Object tmp = mMap.get(key);
- return tmp == null ? null : tmp instanceof JSONArray ? (JSONArray) tmp
: null;
- }
-
- /**
- * get JSONObject value.
- *
- * @param key key.
- * @return value or default value.
- */
- public JSONObject getObject(String key) {
- Object tmp = mMap.get(key);
- return tmp == null ? null : tmp instanceof JSONObject ? (JSONObject)
tmp : null;
- }
-
- /**
- * get key iterator.
- *
- * @return key iterator.
- */
- public Iterator<String> keys() {
- return mMap.keySet().iterator();
- }
-
- /**
- * contains key.
- *
- * @param key key.
- * @return contains or not.
- */
- public boolean contains(String key) {
- return mMap.containsKey(key);
- }
-
- /**
- * put value.
- *
- * @param name name.
- * @param value value.
- */
- public void put(String name, Object value) {
- mMap.put(name, value);
- }
-
- /**
- * put all.
- *
- * @param names name array.
- * @param values value array.
- */
- public void putAll(String[] names, Object[] values) {
- for (int i = 0, len = Math.min(names.length, values.length); i < len;
i++) {
- mMap.put(names[i], values[i]);
- }
- }
-
- /**
- * put all.
- *
- * @param map map.
- */
- public void putAll(Map<String, Object> map) {
- for (Map.Entry<String, Object> entry : map.entrySet()) {
- mMap.put(entry.getKey(), entry.getValue());
- }
- }
-
- /**
- * write json.
- *
- * @param jc json converter.
- * @param jb json builder.
- */
- @Override
- public void writeJSON(JSONConverter jc, JSONWriter jb, boolean writeClass)
throws IOException {
- String key;
- Object value;
- jb.objectBegin();
- for (Map.Entry<String, Object> entry : mMap.entrySet()) {
- key = entry.getKey();
- jb.objectItem(key);
- value = entry.getValue();
- if (value == null) {
- jb.valueNull();
- } else {
- jc.writeValue(value, jb, writeClass);
- }
- }
- jb.objectEnd();
- }
-}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONReader.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONReader.java
deleted file mode 100644
index 47113fc..0000000
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONReader.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.UnsupportedEncodingException;
-
-/**
- * JSON reader.
- */
-@Deprecated
-public class JSONReader {
- private static ThreadLocal<Yylex> LOCAL_LEXER = new ThreadLocal<Yylex>() {
- };
-
- private Yylex mLex;
-
- public JSONReader(InputStream is, String charset) throws
UnsupportedEncodingException {
- this(new InputStreamReader(is, charset));
- }
-
- public JSONReader(Reader reader) {
- mLex = getLexer(reader);
- }
-
- private static Yylex getLexer(Reader reader) {
- Yylex ret = LOCAL_LEXER.get();
- if (ret == null) {
- ret = new Yylex(reader);
- LOCAL_LEXER.set(ret);
- } else {
- ret.yyreset(reader);
- }
- return ret;
- }
-
- public JSONToken nextToken() throws IOException, ParseException {
- return mLex.yylex();
- }
-
- public JSONToken nextToken(int expect) throws IOException, ParseException {
- JSONToken ret = mLex.yylex();
- if (ret == null) {
- throw new ParseException("EOF error.");
- }
- if (expect != JSONToken.ANY && expect != ret.type) {
- throw new ParseException("Unexpected token.");
- }
- return ret;
- }
-}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONToken.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONToken.java
deleted file mode 100644
index 4620f76..0000000
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONToken.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-/**
- * JSONToken.
- */
-@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;
-
- public static final int NULL = 0x10, BOOL = 0x11, INT = 0x12, FLOAT =
0x13, STRING = 0x14, ARRAY = 0x15, OBJECT = 0x16;
-
- public final int type;
-
- public final Object value;
-
- JSONToken(int t) {
- this(t, null);
- }
-
- JSONToken(int t, Object v) {
- type = t;
- value = v;
- }
-
- static String token2string(int t) {
- switch (t) {
- case LBRACE:
- return "{";
- case RBRACE:
- return "}";
- case LSQUARE:
- return "[";
- case RSQUARE:
- return "]";
- case COMMA:
- return ",";
- case COLON:
- return ":";
- case IDENT:
- return "IDENT";
- case NULL:
- return "NULL";
- case BOOL:
- return "BOOL VALUE";
- case INT:
- return "INT VALUE";
- case FLOAT:
- return "FLOAT VALUE";
- case STRING:
- return "STRING VALUE";
- default:
- return "ANY";
- }
- }
-}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONVisitor.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONVisitor.java
deleted file mode 100644
index c2547ee..0000000
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONVisitor.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-/**
- * JSONVisitor.
- */
-@Deprecated
-public interface JSONVisitor {
- String CLASS_PROPERTY = "class";
-
- /**
- * parse begin .
- */
- void begin();
-
- /**
- * parse end.
- *
- * @param obj root obj.
- * @param isValue is json value.
- * @return parse result.
- * @throws ParseException
- */
- Object end(Object obj, boolean isValue) throws ParseException;
-
- /**
- * object begin.
- *
- * @throws ParseException
- */
- void objectBegin() throws ParseException;
-
- /**
- * object end, return object value.
- *
- * @param count property count.
- * @return object value.
- * @throws ParseException
- */
- Object objectEnd(int count) throws ParseException;
-
- /**
- * object property name.
- *
- * @param name name.
- * @throws ParseException
- */
- void objectItem(String name) throws ParseException;
-
- /**
- * object property value.
- *
- * @param obj obj.
- * @param isValue is json value.
- * @throws ParseException
- */
- void objectItemValue(Object obj, boolean isValue) throws ParseException;
-
- /**
- * array begin.
- *
- * @throws ParseException
- */
- void arrayBegin() throws ParseException;
-
- /**
- * array end, return array value.
- *
- * @param count count.
- * @return array value.
- * @throws ParseException
- */
- Object arrayEnd(int count) throws ParseException;
-
- /**
- * array item.
- *
- * @param index index.
- * @throws ParseException
- */
- void arrayItem(int index) throws ParseException;
-
- /**
- * array item.
- *
- * @param index index.
- * @param obj item.
- * @param isValue is json value.
- * @throws ParseException
- */
- void arrayItemValue(int index, Object obj, boolean isValue) throws
ParseException;
-}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONWriter.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONWriter.java
deleted file mode 100644
index 35d4f5a..0000000
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/JSONWriter.java
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-import org.apache.dubbo.common.utils.Stack;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-
-/**
- * JSON Writer.
- * <p>
- * w.objectBegin().objectItem("name").valueString("qianlei").objectEnd() =
{name:"qianlei"}.
- */
-@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[]{
- "\\u0000", "\\u0001", "\\u0002", "\\u0003", "\\u0004", "\\u0005",
"\\u0006", "\\u0007",
- "\\b", "\\t", "\\n", "\\u000b", "\\f", "\\r", "\\u000e", "\\u000f",
- "\\u0010", "\\u0011", "\\u0012", "\\u0013", "\\u0014", "\\u0015",
"\\u0016", "\\u0017",
- "\\u0018", "\\u0019", "\\u001a", "\\u001b", "\\u001c", "\\u001d",
"\\u001e", "\\u001f"
- };
- private Writer mWriter;
-
- private State mState = new State(UNKNOWN);
-
- private Stack<State> mStack = new Stack<State>();
-
- public JSONWriter(Writer writer) {
- mWriter = writer;
- }
-
- public JSONWriter(OutputStream is, String charset) throws
UnsupportedEncodingException {
- mWriter = new OutputStreamWriter(is, charset);
- }
-
- private static String escape(String str) {
- if (str == null) {
- return str;
- }
- int len = str.length();
- if (len == 0) {
- return str;
- }
-
- char c;
- StringBuilder sb = null;
- for (int i = 0; i < len; i++) {
- c = str.charAt(i);
- if (c < ' ') // control char.
- {
- if (sb == null) {
- sb = new StringBuilder(len << 1);
- sb.append(str, 0, i);
- }
- sb.append(CONTROL_CHAR_MAP[c]);
- } else {
- switch (c) {
- case '\\':
- case '/':
- case '"':
- if (sb == null) {
- sb = new StringBuilder(len << 1);
- sb.append(str, 0, i);
- }
- sb.append('\\').append(c);
- break;
- default:
- if (sb != null) {
- sb.append(c);
- }
- }
- }
- }
- return sb == null ? str : sb.toString();
- }
-
- /**
- * object begin.
- *
- * @return this.
- * @throws IOException
- */
- public JSONWriter objectBegin() throws IOException {
- beforeValue();
-
- mWriter.write(JSON.LBRACE);
- mStack.push(mState);
- mState = new State(OBJECT);
- return this;
- }
-
- /**
- * object end.
- *
- * @return this.
- * @throws IOException
- */
- public JSONWriter objectEnd() throws IOException {
- mWriter.write(JSON.RBRACE);
- mState = mStack.pop();
- return this;
- }
-
- /**
- * object item.
- *
- * @param name name.
- * @return this.
- * @throws IOException
- */
- public JSONWriter objectItem(String name) throws IOException {
- beforeObjectItem();
-
- mWriter.write(JSON.QUOTE);
- mWriter.write(escape(name));
- mWriter.write(JSON.QUOTE);
- mWriter.write(JSON.COLON);
- return this;
- }
-
- /**
- * array begin.
- *
- * @return this.
- * @throws IOException
- */
- public JSONWriter arrayBegin() throws IOException {
- beforeValue();
-
- mWriter.write(JSON.LSQUARE);
- mStack.push(mState);
- mState = new State(ARRAY);
- return this;
- }
-
- /**
- * array end, return array value.
- *
- * @return this.
- * @throws IOException
- */
- public JSONWriter arrayEnd() throws IOException {
- mWriter.write(JSON.RSQUARE);
- mState = mStack.pop();
- return this;
- }
-
- /**
- * value.
- *
- * @return this.
- * @throws IOException
- */
- public JSONWriter valueNull() throws IOException {
- beforeValue();
-
- mWriter.write(JSON.NULL);
- return this;
- }
-
- /**
- * value.
- *
- * @param value value.
- * @return this.
- * @throws IOException
- */
- public JSONWriter valueString(String value) throws IOException {
- beforeValue();
-
- mWriter.write(JSON.QUOTE);
- mWriter.write(escape(value));
- mWriter.write(JSON.QUOTE);
- return this;
- }
-
- /**
- * value.
- *
- * @param value value.
- * @return this.
- * @throws IOException
- */
- public JSONWriter valueBoolean(boolean value) throws IOException {
- beforeValue();
-
- mWriter.write(value ? "true" : "false");
- return this;
- }
-
- /**
- * value.
- *
- * @param value value.
- * @return this.
- * @throws IOException
- */
- public JSONWriter valueInt(int value) throws IOException {
- beforeValue();
-
- mWriter.write(String.valueOf(value));
- return this;
- }
-
- /**
- * value.
- *
- * @param value value.
- * @return this.
- * @throws IOException
- */
- public JSONWriter valueLong(long value) throws IOException {
- beforeValue();
-
- mWriter.write(String.valueOf(value));
- return this;
- }
-
- /**
- * value.
- *
- * @param value value.
- * @return this.
- * @throws IOException
- */
- public JSONWriter valueFloat(float value) throws IOException {
- beforeValue();
-
- mWriter.write(String.valueOf(value));
- return this;
- }
-
- /**
- * value.
- *
- * @param value value.
- * @return this.
- * @throws IOException
- */
- public JSONWriter valueDouble(double value) throws IOException {
- beforeValue();
-
- mWriter.write(String.valueOf(value));
- return this;
- }
-
- private void beforeValue() throws IOException {
- switch (mState.type) {
- case ARRAY:
- if (mState.itemCount++ > 0) {
- mWriter.write(JSON.COMMA);
- }
- return;
- case OBJECT:
- throw new IOException("Must call objectItem first.");
- case OBJECT_VALUE:
- mState.type = OBJECT;
- return;
- default:
- }
- }
-
- private void beforeObjectItem() throws IOException {
- switch (mState.type) {
- case OBJECT_VALUE:
- mWriter.write(JSON.NULL);
- case OBJECT:
- mState.type = OBJECT_VALUE;
- if (mState.itemCount++ > 0) {
- mWriter.write(JSON.COMMA);
- }
- return;
- default:
- throw new IOException("Must call objectBegin first.");
- }
- }
-
- private static class State {
- private byte type;
- private int itemCount = 0;
-
- State(byte t) {
- type = t;
- }
- }
-}
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/ParseException.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/ParseException.java
deleted file mode 100644
index 65c2c27..0000000
---
a/dubbo-common/src/main/java/org/apache/dubbo/common/json/ParseException.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-/**
- * ParseException.
- */
-@Deprecated
-public class ParseException extends Exception {
- private static final long serialVersionUID = 8611884051738966316L;
-
- public ParseException() {
- super();
- }
-
- public ParseException(String message) {
- super(message);
- }
-}
diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/json/Yylex.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/json/Yylex.java
deleted file mode 100644
index ca63280..0000000
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/json/Yylex.java
+++ /dev/null
@@ -1,847 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-/**
- * This class is a scanner generated by
- * <a href="http://www.jflex.de/">JFlex</a> 1.4.3
- * on 7/3/10 3:12 AM from the specification file
- *
<tt>/Users/qianlei/dev/proj/dubbo-1.1/dubbo.common/src/main/java/org.apache.dubbo/common/json/json.flex</tt>
- */
-@Deprecated
-public class Yylex {
-
- /**
- * This character denotes the end of file
- */
- public static final int YYEOF = -1;
- /**
- * lexical states
- */
- public static final int STR2 = 4;
- public static final int STR1 = 2;
- public static final int YYINITIAL = 0;
- /**
- * initial size of the lookahead buffer
- */
- private static final int ZZ_BUFFERSIZE = 16384;
- /**
- * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
- * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
- * at the beginning of a line
- * l is of the form l = 2*k, k a non negative integer
- */
- private static final int[] ZZ_LEXSTATE = {
- 0, 0, 1, 1, 2, 2
- };
-
- /**
- * Translates characters to character classes
- */
- private static final String ZZ_CMAP_PACKED =
- "\11\0\1\13\1\13\2\0\1\13\22\0\1\13\1\0\1\10\1\0" +
- "\1\2\2\0\1\11\3\0\1\7\1\43\1\4\1\5\1\14\12\1" +
- "\1\44\6\0\1\33\3\3\1\6\1\32\5\2\1\34\1\2\1\36" +
- "\3\2\1\25\1\35\1\24\1\26\5\2\1\41\1\12\1\42\1\0" +
- "\1\2\1\0\1\27\1\15\2\3\1\23\1\16\5\2\1\30\1\2" +
- "\1\17\3\2\1\20\1\31\1\21\1\22\5\2\1\37\1\0\1\40" +
- "\uff82\0";
-
- /**
- * Translates characters to character classes
- */
- private static final char[] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
- private static final String ZZ_ACTION_PACKED_0 =
- "\3\0\1\1\1\2\1\3\1\1\1\4\1\5\1\6" +
- "\6\3\1\7\1\10\1\11\1\12\1\13\1\14\1\15" +
- "\1\16\1\0\1\15\3\0\6\3\1\17\1\20\1\21" +
- "\1\22\1\23\1\24\1\25\1\26\1\0\1\27\2\30" +
- "\1\0\6\3\1\0\1\3\1\31\1\32\1\3\1\0" +
- "\1\33\1\0\1\34";
- /**
- * Translates DFA states to action switch labels.
- */
- private static final int[] ZZ_ACTION = zzUnpackAction();
- private static final String ZZ_ROWMAP_PACKED_0 =
- "\0\0\0\45\0\112\0\157\0\224\0\271\0\336\0\157" +
-
"\0\157\0\u0103\0\u0128\0\u014d\0\u0172\0\u0197\0\u01bc\0\u01e1" +
- "\0\157\0\157\0\157\0\157\0\157\0\157\0\u0206\0\157" +
-
"\0\u022b\0\u0250\0\u0275\0\u029a\0\u02bf\0\u02e4\0\u0309\0\u032e" +
- "\0\u0353\0\u0378\0\u039d\0\157\0\157\0\157\0\157\0\157" +
- "\0\157\0\157\0\157\0\u03c2\0\157\0\u03e7\0\u040c\0\u040c"
+
-
"\0\u0431\0\u0456\0\u047b\0\u04a0\0\u04c5\0\u04ea\0\u050f\0\u0534" +
- "\0\271\0\271\0\u0559\0\u057e\0\271\0\u05a3\0\157";
- /**
- * Translates a state to a row index in the transition table
- */
- private static final int[] ZZ_ROWMAP = zzUnpackRowMap();
- /**
- * The transition table of the DFA
- */
- private static final int[] ZZ_TRANS = {
- 3, 4, 5, 5, 6, 3, 5, 3, 7, 8,
- 3, 9, 3, 5, 10, 11, 5, 12, 5, 5,
- 13, 5, 5, 5, 5, 5, 14, 5, 5, 5,
- 15, 16, 17, 18, 19, 20, 21, 22, 22, 22,
- 22, 22, 22, 22, 22, 23, 22, 24, 22, 22,
- 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
- 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
- 22, 22, 22, 22, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 23, 26, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, 4,
- -1, -1, -1, 27, 28, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, 28, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, 5, 5, 5, -1,
- -1, 5, -1, -1, -1, -1, -1, -1, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, -1, -1, -1, -1,
- -1, -1, -1, 4, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 9, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, 5, 5, 5,
- -1, -1, 5, -1, -1, -1, -1, -1, -1, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 29,
- 5, 5, 5, 5, 5, 5, 5, -1, -1, -1,
- -1, -1, -1, -1, 5, 5, 5, -1, -1, 5,
- -1, -1, -1, -1, -1, -1, 5, 5, 5, 5,
- 5, 30, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, -1, -1, -1, -1, -1, -1,
- -1, 5, 5, 5, -1, -1, 5, -1, -1, -1,
- -1, -1, -1, 5, 5, 5, 31, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, -1, -1, -1, -1, -1, -1, -1, 5, 5,
- 5, -1, -1, 5, -1, -1, -1, -1, -1, -1,
- 5, 5, 5, 5, 5, 5, 5, 5, 32, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, -1, -1,
- -1, -1, -1, -1, -1, 5, 5, 5, -1, -1,
- 5, -1, -1, -1, -1, -1, -1, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 33, 5, 5, 5, -1, -1, -1, -1, -1,
- -1, -1, 5, 5, 5, -1, -1, 5, -1, -1,
- -1, -1, -1, -1, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 34, 5, 5, 5, 5, 5, 5,
- 5, 5, -1, -1, -1, -1, -1, -1, 22, 22,
- 22, 22, 22, 22, 22, 22, -1, 22, -1, 22,
- 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
- 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
- 22, 22, 22, 22, 22, -1, -1, -1, -1, -1,
- -1, -1, -1, 35, -1, 36, -1, 37, 38, 39,
- 40, 41, 42, 43, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, -1, -1, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
- 25, 25, 25, 25, 25, 25, 25, 25, 25, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, 44, 36,
- -1, 37, 38, 39, 40, 41, 42, 43, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, 45, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, 46, -1, -1, 47, -1, -1,
- 47, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, 5, 5, 5, -1, -1, 5, -1, -1, -1,
- -1, -1, -1, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 48, 5, 5, 5, 5, 5,
- 5, -1, -1, -1, -1, -1, -1, -1, 5, 5,
- 5, -1, -1, 5, -1, -1, -1, -1, -1, -1,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 49, 5, 5, 5, 5, 5, 5, -1, -1,
- -1, -1, -1, -1, -1, 5, 5, 5, -1, -1,
- 5, -1, -1, -1, -1, -1, -1, 5, 5, 5,
- 5, 5, 50, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, -1, -1, -1, -1, -1,
- -1, -1, 5, 5, 5, -1, -1, 5, -1, -1,
- -1, -1, -1, -1, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 51, 5, 5, 5, 5, 5, 5,
- 5, 5, -1, -1, -1, -1, -1, -1, -1, 5,
- 5, 5, -1, -1, 5, -1, -1, -1, -1, -1,
- -1, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 52, 5, 5, -1,
- -1, -1, -1, -1, -1, -1, 5, 5, 5, -1,
- -1, 5, -1, -1, -1, -1, -1, -1, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 53, 5, 5, -1, -1, -1, -1,
- -1, -1, -1, 54, -1, 54, -1, -1, 54, -1,
- -1, -1, -1, -1, -1, 54, 54, -1, -1, -1,
- -1, 54, -1, -1, -1, 54, -1, -1, 54, 54,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 45, -1, -1, -1, -1, 28, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, 28, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, 46, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, 5, 5, 5, -1, -1, 5,
- -1, -1, -1, -1, -1, -1, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 55, 5,
- 5, 5, 5, 5, -1, -1, -1, -1, -1, -1,
- -1, 5, 5, 5, -1, -1, 5, -1, -1, -1,
- -1, -1, -1, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 56, 5, 5, 5, 5, 5,
- 5, -1, -1, -1, -1, -1, -1, -1, 5, 5,
- 5, -1, -1, 5, -1, -1, -1, -1, -1, -1,
- 5, 5, 5, 5, 5, 5, 57, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, -1, -1,
- -1, -1, -1, -1, -1, 5, 5, 5, -1, -1,
- 57, -1, -1, -1, -1, -1, -1, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, -1, -1, -1, -1, -1,
- -1, -1, 5, 5, 5, -1, -1, 5, -1, -1,
- -1, -1, -1, -1, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 58, 5, -1, -1, -1, -1, -1, -1, -1, 5,
- 5, 5, -1, -1, 5, -1, -1, -1, -1, -1,
- -1, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 56, 5, 5, -1,
- -1, -1, -1, -1, -1, -1, 59, -1, 59, -1,
- -1, 59, -1, -1, -1, -1, -1, -1, 59, 59,
- -1, -1, -1, -1, 59, -1, -1, -1, 59, -1,
- -1, 59, 59, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, 5, 5, 5, -1, -1, 5, -1,
- -1, -1, -1, -1, -1, 5, 5, 5, 5, 5,
- 5, 60, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, -1, -1, -1, -1, -1, -1, -1,
- 5, 5, 5, -1, -1, 60, -1, -1, -1, -1,
- -1, -1, 5, 5, 5, 5, 5, 5, 5, 5,
- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
- -1, -1, -1, -1, -1, -1, -1, 61, -1, 61,
- -1, -1, 61, -1, -1, -1, -1, -1, -1, 61,
- 61, -1, -1, -1, -1, 61, -1, -1, -1, 61,
- -1, -1, 61, 61, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, 62, -1, 62, -1, -1, 62,
- -1, -1, -1, -1, -1, -1, 62, 62, -1, -1,
- -1, -1, 62, -1, -1, -1, 62, -1, -1, 62,
- 62, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- };
- /* error codes */
- private static final int ZZ_UNKNOWN_ERROR = 0;
- private static final int ZZ_NO_MATCH = 1;
- private static final int ZZ_PUSHBACK_2BIG = 2;
- /* error messages for the codes above */
- private static final String[] ZZ_ERROR_MSG = {
- "Unkown internal scanner error",
- "Error: could not match input",
- "Error: pushback value was too large"
- };
- private static final String ZZ_ATTRIBUTE_PACKED_0 =
- "\3\0\1\11\3\1\2\11\7\1\6\11\1\1\1\11" +
- "\1\0\1\1\3\0\6\1\10\11\1\0\1\11\2\1" +
- "\1\0\6\1\1\0\4\1\1\0\1\1\1\0\1\11";
- /**
- * ZZ_ATTRIBUTE[aState] contains the attributes of state
<code>aState</code>
- */
- private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute();
- /**
- * the input device
- */
- private java.io.Reader zzReader;
- /**
- * the current state of the DFA
- */
- private int zzState;
- /**
- * the current lexical state
- */
- private int zzLexicalState = YYINITIAL;
- /**
- * this buffer contains the current text to be matched and is
- * the source of the yytext() string
- */
- private char[] zzBuffer = new char[ZZ_BUFFERSIZE];
- /**
- * the textposition at the last accepting state
- */
- private int zzMarkedPos;
- /**
- * the current text position in the buffer
- */
- private int zzCurrentPos;
- /**
- * startRead marks the beginning of the yytext() string in the buffer
- */
- private int zzStartRead;
- /**
- * endRead marks the last character in the buffer, that has been read
- * from input
- */
- private int zzEndRead;
- /**
- * zzAtEOF == true <=> the scanner is at the EOF
- */
- private boolean zzAtEOF;
- /**
- * denotes if the user-EOF-code has already been executed
- */
- //private boolean zzEOFDone;
-
- /* user code: */
- private StringBuffer sb;
-
- /**
- * Creates a new scanner
- * There is also a java.io.InputStream version of this constructor.
- *
- * @param in the java.io.Reader to read input from.
- */
- Yylex(java.io.Reader in) {
- this.zzReader = in;
- }
-
- /**
- * Creates a new scanner.
- * There is also java.io.Reader version of this constructor.
- *
- * @param in the java.io.Inputstream to read input from.
- */
- Yylex(java.io.InputStream in) {
- this(new java.io.InputStreamReader(in));
- }
-
- private static int[] zzUnpackAction() {
- int[] result = new int[63];
- int offset = 0;
- offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
- return result;
- }
-
- private static int zzUnpackAction(String packed, int offset, int[] result)
{
- int i = 0; /* index in packed string */
- int j = offset; /* index in unpacked array */
- int l = packed.length();
- while (i < l) {
- int count = packed.charAt(i++);
- int value = packed.charAt(i++);
- do {
- result[j++] = value;
- } while (--count > 0);
- }
- return j;
- }
-
- /** number of newlines encountered up to the start of the matched text */
- //private int yyline;
-
- /** the number of characters up to the start of the matched text */
- //private int yychar;
-
- /**
- * the number of characters from the last newline up to the start of the
- * matched text
- */
- //private int yycolumn;
-
- /**
- * zzAtBOL == true <=> the scanner is currently at the beginning of a line
- */
- //private boolean zzAtBOL = true;
- private static int[] zzUnpackRowMap() {
- int[] result = new int[63];
- int offset = 0;
- offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
- return result;
- }
-
- private static int zzUnpackRowMap(String packed, int offset, int[] result)
{
- int i = 0; /* index in packed string */
- int j = offset; /* index in unpacked array */
- int l = packed.length();
- while (i < l) {
- int high = packed.charAt(i++) << 16;
- result[j++] = high | packed.charAt(i++);
- }
- return j;
- }
-
- private static int[] zzUnpackAttribute() {
- int[] result = new int[63];
- int offset = 0;
- offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
- return result;
- }
-
- private static int zzUnpackAttribute(String packed, int offset, int[]
result) {
- int i = 0; /* index in packed string */
- int j = offset; /* index in unpacked array */
- int l = packed.length();
- while (i < l) {
- int count = packed.charAt(i++);
- int value = packed.charAt(i++);
- do {
- result[j++] = value;
- } while (--count > 0);
- }
- return j;
- }
-
- /**
- * Unpacks the compressed character translation table.
- *
- * @param packed the packed character translation table
- * @return the unpacked character translation table
- */
- private static char[] zzUnpackCMap(String packed) {
- char[] map = new char[0x10000];
- int i = 0; /* index in packed string */
- int j = 0; /* index in unpacked array */
- while (i < 122) {
- int count = packed.charAt(i++);
- char value = packed.charAt(i++);
- do {
- map[j++] = value;
- } while (--count > 0);
- }
- return map;
- }
-
-
- /**
- * Refills the input buffer.
- *
- * @return <code>false</code>, iff there was new input.
- * @throws java.io.IOException if any I/O-Error occurs
- */
- private boolean zzRefill() throws java.io.IOException {
-
- /* first: make room (if you can) */
- if (zzStartRead > 0) {
- System.arraycopy(zzBuffer, zzStartRead,
- zzBuffer, 0,
- zzEndRead - zzStartRead);
-
- /* translate stored positions */
- zzEndRead -= zzStartRead;
- zzCurrentPos -= zzStartRead;
- zzMarkedPos -= zzStartRead;
- zzStartRead = 0;
- }
-
- /* is the buffer big enough? */
- if (zzCurrentPos >= zzBuffer.length) {
- /* if not: blow it up */
- char[] newBuffer = new char[zzCurrentPos * 2];
- System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
- zzBuffer = newBuffer;
- }
-
- /* finally: fill the buffer with new input */
- int numRead = zzReader.read(zzBuffer, zzEndRead,
- zzBuffer.length - zzEndRead);
-
- if (numRead > 0) {
- zzEndRead += numRead;
- return false;
- }
- // unlikely but not impossible: read 0 characters, but not at end of
stream
- if (numRead == 0) {
- int c = zzReader.read();
- if (c == -1) {
- return true;
- } else {
- zzBuffer[zzEndRead++] = (char) c;
- return false;
- }
- }
-
- // numRead < 0
- return true;
- }
-
-
- /**
- * Closes the input stream.
- */
- public final void yyclose() throws java.io.IOException {
- zzAtEOF = true; /* indicate end of file */
- zzEndRead = zzStartRead; /* invalidate buffer */
-
- if (zzReader != null) {
- zzReader.close();
- }
- }
-
-
- /**
- * Resets the scanner to read from a new input stream.
- * Does not close the old reader.
- * <p>
- * All internal variables are reset, the old input stream
- * <b>cannot</b> be reused (internal buffer is discarded and lost).
- * Lexical state is set to <tt>ZZ_INITIAL</tt>.
- *
- * @param reader the new input stream
- */
- public final void yyreset(java.io.Reader reader) {
- zzReader = reader;
- //zzAtBOL = true;
- zzAtEOF = false;
- //zzEOFDone = false;
- zzEndRead = zzStartRead = 0;
- zzCurrentPos = zzMarkedPos = 0;
- //yyline = yychar = yycolumn = 0;
- zzLexicalState = YYINITIAL;
- }
-
-
- /**
- * Returns the current lexical state.
- */
- public final int yystate() {
- return zzLexicalState;
- }
-
-
- /**
- * Enters a new lexical state
- *
- * @param newState the new lexical state
- */
- public final void yybegin(int newState) {
- zzLexicalState = newState;
- }
-
-
- /**
- * Returns the text matched by the current regular expression.
- */
- public final String yytext() {
- return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead);
- }
-
-
- /**
- * Returns the character at position <tt>pos</tt> from the
- * matched text.
- * <p>
- * It is equivalent to yytext().charAt(pos), but faster
- *
- * @param pos the position of the character to fetch.
- * A value from 0 to yylength()-1.
- * @return the character at position pos
- */
- public final char yycharat(int pos) {
- return zzBuffer[zzStartRead + pos];
- }
-
-
- /**
- * Returns the length of the matched text region.
- */
- public final int yylength() {
- return zzMarkedPos - zzStartRead;
- }
-
-
- /**
- * Reports an error that occured while scanning.
- * <p>
- * In a wellformed scanner (no or only correct usage of
- * yypushback(int) and a match-all fallback rule) this method
- * will only be called with things that "Can't Possibly Happen".
- * If this method is called, something is seriously wrong
- * (e.g. a JFlex bug producing a faulty scanner etc.).
- * <p>
- * Usual syntax/scanner level error handling should be done
- * in error fallback rules.
- *
- * @param errorCode the code of the errormessage to display
- */
- private void zzScanError(int errorCode) {
- String message;
- try {
- message = ZZ_ERROR_MSG[errorCode];
- } catch (ArrayIndexOutOfBoundsException e) {
- message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
- }
-
- throw new Error(message);
- }
-
-
- /**
- * Pushes the specified amount of characters back into the input stream.
- * <p>
- * They will be read again by then next call of the scanning method
- *
- * @param number the number of characters to be read again.
- * This number must not be greater than yylength()!
- */
- public void yypushback(int number) {
- if (number > yylength()) {
- zzScanError(ZZ_PUSHBACK_2BIG);
- }
-
- zzMarkedPos -= number;
- }
-
-
- /**
- * Resumes scanning until the next regular expression is matched,
- * the end of input is encountered or an I/O-Error occurs.
- *
- * @return the next token
- * @throws java.io.IOException if any I/O-Error occurs
- */
- public JSONToken yylex() throws java.io.IOException, ParseException {
- int zzInput;
- int zzAction;
-
- // cached fields:
- int zzCurrentPosL;
- int zzMarkedPosL;
- int zzEndReadL = zzEndRead;
- char[] zzBufferL = zzBuffer;
- char[] zzCMapL = ZZ_CMAP;
-
- int[] zzTransL = ZZ_TRANS;
- int[] zzRowMapL = ZZ_ROWMAP;
- int[] zzAttrL = ZZ_ATTRIBUTE;
-
- while (true) {
- zzMarkedPosL = zzMarkedPos;
-
- zzAction = -1;
-
- zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
-
- zzState = ZZ_LEXSTATE[zzLexicalState];
-
-
- zzForAction:
- {
- while (true) {
-
- if (zzCurrentPosL < zzEndReadL) {
- zzInput = zzBufferL[zzCurrentPosL++];
- } else if (zzAtEOF) {
- zzInput = YYEOF;
- break zzForAction;
- } else {
- // store back cached positions
- zzCurrentPos = zzCurrentPosL;
- zzMarkedPos = zzMarkedPosL;
- boolean eof = zzRefill();
- // get translated positions and possibly new buffer
- zzCurrentPosL = zzCurrentPos;
- zzMarkedPosL = zzMarkedPos;
- zzBufferL = zzBuffer;
- zzEndReadL = zzEndRead;
- if (eof) {
- zzInput = YYEOF;
- break zzForAction;
- } else {
- zzInput = zzBufferL[zzCurrentPosL++];
- }
- }
- int zzNext = zzTransL[zzRowMapL[zzState] +
zzCMapL[zzInput]];
- if (zzNext == -1) {
- break zzForAction;
- }
- zzState = zzNext;
-
- int zzAttributes = zzAttrL[zzState];
- if ((zzAttributes & 1) == 1) {
- zzAction = zzState;
- zzMarkedPosL = zzCurrentPosL;
- if ((zzAttributes & 8) == 8) {
- break zzForAction;
- }
- }
-
- }
- }
-
- // store back cached position
- zzMarkedPos = zzMarkedPosL;
-
- switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
- case 25: {
- return new JSONToken(JSONToken.NULL, null);
- }
- case 29:
- break;
- case 13: {
- sb.append(yytext());
- }
- case 30:
- break;
- case 18: {
- sb.append('\b');
- }
- case 31:
- break;
- case 9: {
- return new JSONToken(JSONToken.LSQUARE);
- }
- case 32:
- break;
- case 2: {
- Long val = Long.valueOf(yytext());
- return new JSONToken(JSONToken.INT, val);
- }
- case 33:
- break;
- case 16: {
- sb.append('\\');
- }
- case 34:
- break;
- case 8: {
- return new JSONToken(JSONToken.RBRACE);
- }
- case 35:
- break;
- case 26: {
- return new JSONToken(JSONToken.BOOL, Boolean.TRUE);
- }
- case 36:
- break;
- case 23: {
- sb.append('\'');
- }
- case 37:
- break;
- case 5: {
- sb = new StringBuffer();
- yybegin(STR2);
- }
- case 38:
- break;
- case 27: {
- return new JSONToken(JSONToken.BOOL, Boolean.FALSE);
- }
- case 39:
- break;
- case 12: {
- return new JSONToken(JSONToken.COLON);
- }
- case 40:
- break;
- case 21: {
- sb.append('\r');
- }
- case 41:
- break;
- case 3: {
- return new JSONToken(JSONToken.IDENT, yytext());
- }
- case 42:
- break;
- case 28: {
- try {
- sb.append((char)
Integer.parseInt(yytext().substring(2), 16));
- } catch (Exception e) {
- throw new ParseException(e.getMessage());
- }
- }
- case 43:
- break;
- case 10: {
- return new JSONToken(JSONToken.RSQUARE);
- }
- case 44:
- break;
- case 17: {
- sb.append('/');
- }
- case 45:
- break;
- case 11: {
- return new JSONToken(JSONToken.COMMA);
- }
- case 46:
- break;
- case 15: {
- sb.append('"');
- }
- case 47:
- break;
- case 24: {
- Double val = Double.valueOf(yytext());
- return new JSONToken(JSONToken.FLOAT, val);
- }
- case 48:
- break;
- case 1: {
- throw new ParseException("Unexpected char [" + yytext() +
"]");
- }
- case 49:
- break;
- case 19: {
- sb.append('\f');
- }
- case 50:
- break;
- case 7: {
- return new JSONToken(JSONToken.LBRACE);
- }
- case 51:
- break;
- case 14: {
- yybegin(YYINITIAL);
- return new JSONToken(JSONToken.STRING, sb.toString());
- }
- case 52:
- break;
- case 22: {
- sb.append('\t');
- }
- case 53:
- break;
- case 4: {
- sb = new StringBuffer();
- yybegin(STR1);
- }
- case 54:
- break;
- case 20: {
- sb.append('\n');
- }
- case 55:
- break;
- case 6: {
- }
- case 56:
- break;
- default:
- if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
- zzAtEOF = true;
- return null;
- } else {
- zzScanError(ZZ_NO_MATCH);
- break;
- }
- }
- }
- }
-
-
-}
diff --git
a/dubbo-common/src/test/java/org/apache/dubbo/common/json/JSONReaderTest.java
b/dubbo-common/src/test/java/org/apache/dubbo/common/json/JSONReaderTest.java
deleted file mode 100644
index 03200ac..0000000
---
a/dubbo-common/src/test/java/org/apache/dubbo/common/json/JSONReaderTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-import org.apache.dubbo.common.io.UnsafeStringReader;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-public class JSONReaderTest {
- public void testMain() throws Exception {
- String json = "{ name: 'name', friends: [ 1, null, 3.2, ] }";
- JSONReader reader = new JSONReader(new UnsafeStringReader(json));
- assertEquals(reader.nextToken().type, JSONToken.LBRACE);
- assertEquals(reader.nextToken().type, JSONToken.IDENT);
- assertEquals(reader.nextToken().type, JSONToken.COLON);
- assertEquals(reader.nextToken().type, JSONToken.STRING);
- assertEquals(reader.nextToken().type, JSONToken.COMMA);
- assertEquals(reader.nextToken().type, JSONToken.IDENT);
- assertEquals(reader.nextToken().type, JSONToken.COLON);
- assertEquals(reader.nextToken().type, JSONToken.LSQUARE);
- assertEquals(reader.nextToken().type, JSONToken.INT);
- assertEquals(reader.nextToken().type, JSONToken.COMMA);
- assertEquals(reader.nextToken().type, JSONToken.NULL);
- assertEquals(reader.nextToken().type, JSONToken.COMMA);
- assertEquals(reader.nextToken().type, JSONToken.FLOAT);
- assertEquals(reader.nextToken().type, JSONToken.COMMA);
- assertEquals(reader.nextToken().type, JSONToken.RSQUARE);
- assertEquals(reader.nextToken().type, JSONToken.RBRACE);
- }
-}
diff --git
a/dubbo-common/src/test/java/org/apache/dubbo/common/json/JSONTest.java
b/dubbo-common/src/test/java/org/apache/dubbo/common/json/JSONTest.java
deleted file mode 100644
index 810aca2..0000000
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/json/JSONTest.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-@Deprecated
-public class JSONTest {
- static byte[] DEFAULT_BYTES = {3, 12, 14, 41, 12, 2, 3, 12, 4, 67, 23};
- static int DEFAULT_$$ = 152;
-
- @Test
- public void testException() throws Exception {
- MyException e = new MyException("001", "AAAAAAAA");
-
- StringWriter writer = new StringWriter();
- JSON.json(e, writer);
- String json = writer.getBuffer().toString();
- System.out.println(json);
- //
Assertions.assertEquals("{\"code\":\"001\",\"message\":\"AAAAAAAA\"}", json);
-
- StringReader reader = new StringReader(json);
- MyException result = JSON.parse(reader, MyException.class);
- Assertions.assertEquals("001", result.getCode());
- Assertions.assertEquals("AAAAAAAA", result.getMessage());
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testMap() throws Exception {
- Map<String, String> map = new HashMap<String, String>();
- map.put("aaa", "bbb");
-
- StringWriter writer = new StringWriter();
- JSON.json(map, writer);
- String json = writer.getBuffer().toString();
- Assertions.assertEquals("{\"aaa\":\"bbb\"}", json);
-
- StringReader reader = new StringReader(json);
- Map<String, String> result = JSON.parse(reader, Map.class);
- Assertions.assertEquals("bbb", result.get("aaa"));
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testMapArray() throws Exception {
- Map<String, String> map = new HashMap<String, String>();
- map.put("aaa", "bbb");
-
- StringWriter writer = new StringWriter();
- JSON.json(new Object[]{map}, writer); // args
- String json = writer.getBuffer().toString();
- Assertions.assertEquals("[{\"aaa\":\"bbb\"}]", json);
-
- StringReader reader = new StringReader(json);
- Object[] result = JSON.parse(reader, new Class<?>[]{Map.class});
- Assertions.assertEquals(1, result.length);
- Assertions.assertEquals("bbb", ((Map<String, String>)
result[0]).get("aaa"));
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testLinkedMap() throws Exception {
- LinkedHashMap<String, String> map = new LinkedHashMap<String,
String>();
- map.put("aaa", "bbb");
-
- StringWriter writer = new StringWriter();
- JSON.json(map, writer);
- String json = writer.getBuffer().toString();
- Assertions.assertEquals("{\"aaa\":\"bbb\"}", json);
-
- StringReader reader = new StringReader(json);
- LinkedHashMap<String, String> result = JSON.parse(reader,
LinkedHashMap.class);
- Assertions.assertEquals("bbb", result.get("aaa"));
- }
-
- @Test
- public void testObject2Json() throws Exception {
- Bean bean = new Bean();
- bean.array = new int[]{1, 3, 4};
- bean.setName("ql");
-
- String json = JSON.json(bean);
- bean = JSON.parse(json, Bean.class);
- assertEquals(bean.getName(), "ql");
- assertEquals(bean.getDisplayName(), "钱磊");
- assertEquals(bean.bytes.length, DEFAULT_BYTES.length);
- assertEquals(bean.$$, DEFAULT_$$);
-
- assertEquals("{\"name\":\"ql\",\"array\":[1,3,4]}", JSON.json(bean,
new String[]{"name", "array"}));
- }
-
- @Test
- public void testParse2JSONObject() throws Exception {
- JSONObject jo = (JSONObject)
JSON.parse("{name:'qianlei',array:[1,2,3,4,98.123],b1:TRUE,$1:NULL,$2:FALSE,__3:NULL}");
- assertEquals(jo.getString("name"), "qianlei");
- assertEquals(jo.getArray("array").length(), 5);
- assertEquals(jo.get("$2"), Boolean.FALSE);
- assertNull(jo.get("__3"));
-
- for (int i = 0; i < 10000; i++)
-
JSON.parse("{\"name\":\"qianlei\",\"array\":[1,2,3,4,98.123],\"displayName\":\"钱磊\"}");
-
- long now = System.currentTimeMillis();
- for (int i = 0; i < 10000; i++)
-
JSON.parse("{\"name\":\"qianlei\",\"array\":[1,2,3,4,98.123],\"displayName\":\"钱磊\"}");
- System.out.println("parse to JSONObject 10000 times in: " +
(System.currentTimeMillis() - now));
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testParse2Class() throws Exception {
- int[] o1 = {1, 2, 3, 4, 5}, o2 = JSON.parse("[1.2,2,3,4,5]",
int[].class);
- assertEquals(o2.length, 5);
- for (int i = 0; i < 5; i++)
- assertEquals(o1[i], o2[i]);
-
- List l1 = (List) JSON.parse("[1.2,2,3,4,5]", List.class);
- assertEquals(l1.size(), 5);
- for (int i = 0; i < 5; i++)
- assertEquals(o1[i], ((Number) l1.get(i)).intValue());
-
- Bean bean =
JSON.parse("{name:'qianlei',array:[1,2,3,4,98.123],displayName:'钱磊',$$:214726,$b:TRUE}",
Bean.class);
- assertEquals(bean.getName(), "qianlei");
- assertEquals(bean.getDisplayName(), "钱磊");
- assertEquals(bean.array.length, 5);
- assertEquals(bean.$$, 214726);
- assertTrue(bean.$b);
-
- for (int i = 0; i < 10000; i++)
-
JSON.parse("{name:'qianlei',array:[1,2,3,4,98.123],displayName:'钱磊'}",
Bean1.class);
-
- long now = System.currentTimeMillis();
- for (int i = 0; i < 10000; i++)
-
JSON.parse("{name:'qianlei',array:[1,2,3,4,98.123],displayName:'钱磊'}",
Bean1.class);
- System.out.println("parse to Class 10000 times in: " +
(System.currentTimeMillis() - now));
- }
-
- @Test
- public void testParse2Arguments() throws Exception {
- Object[] test = JSON.parse("[1.2, 2,
{name:'qianlei',array:[1,2,3,4,98.123]} ]", new Class<?>[]{int.class,
int.class, Bean.class});
- assertEquals(test[1], 2);
- assertEquals(test[2].getClass(), Bean.class);
- test = JSON.parse("[1.2, 2]", new Class<?>[]{int.class, int.class});
- assertEquals(test[0], 1);
- }
-
- @Test
- public void testLocale() throws Exception {
- Locale obj = Locale.US;
- String str = JSON.json(obj);
- assertEquals("\"en_US\"", str);
- assertEquals(obj, JSON.parse(str, Locale.class));
- }
-
- public static class Bean1 {
- public int[] array;
- private String name, displayName;
-
- public String getDisplayName() {
- return displayName;
- }
-
- public void setDisplayName(String displayName) {
- this.displayName = displayName;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
- }
-
- public static class Bean {
- public int[] array;
- public boolean $b;
- public int $$ = DEFAULT_$$;
- public byte[] bytes = DEFAULT_BYTES;
- private String name, displayName = "钱磊";
-
- public String getDisplayName() {
- return displayName;
- }
-
- public void setDisplayName(String displayName) {
- this.displayName = displayName;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
- }
-}
diff --git
a/dubbo-common/src/test/java/org/apache/dubbo/common/json/JSONWriterTest.java
b/dubbo-common/src/test/java/org/apache/dubbo/common/json/JSONWriterTest.java
deleted file mode 100644
index 8fccacf..0000000
---
a/dubbo-common/src/test/java/org/apache/dubbo/common/json/JSONWriterTest.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-
-import java.io.StringWriter;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-public class JSONWriterTest {
- public void testWriteJson() throws Exception {
- StringWriter w = new StringWriter();
- JSONWriter writer = new JSONWriter(w);
-
- writer.valueNull();
- assertEquals(w.getBuffer().toString(), "null");
-
- // write array.
- w.getBuffer().setLength(0);
-
writer.arrayBegin().valueNull().valueBoolean(false).valueInt(16).arrayEnd();
- assertEquals(w.getBuffer().toString(), "[null,false,16]");
-
- // write object.
- w.getBuffer().setLength(0);
-
writer.objectBegin().objectItem("type").valueString("org.apache.dubbo.TestService").objectItem("version").valueString("1.1.0").objectEnd();
- assertEquals(w.getBuffer().toString(),
"{\"type\":\"org.apache.dubbo.TestService\",\"version\":\"1.1.0\"}");
-
- w.getBuffer().setLength(0);
- writer.objectBegin();
- writer.objectItem("name").objectItem("displayName");
- writer.objectItem("emptyList").arrayBegin().arrayEnd();
-
writer.objectItem("list").arrayBegin().valueNull().valueBoolean(false).valueInt(16).valueString("stri'''ng").arrayEnd();
-
writer.objectItem("service").objectBegin().objectItem("type").valueString("org.apache.dubbo.TestService").objectItem("version").valueString("1.1.0").objectEnd();
- writer.objectEnd();
- }
-}
diff --git
a/dubbo-common/src/test/java/org/apache/dubbo/common/json/MyException.java
b/dubbo-common/src/test/java/org/apache/dubbo/common/json/MyException.java
deleted file mode 100644
index 768d109..0000000
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/json/MyException.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.common.json;
-
-public class MyException extends Exception {
-
- private static final long serialVersionUID = 2905707783883694687L;
-
- private String code;
-
- public MyException() {
- }
-
- public MyException(String code, String message) {
- super(message);
- this.code = code;
- }
-
- public String getCode() {
- return code;
- }
-
- public void setCode(String code) {
- this.code = code;
- }
-
-}