mirror of
https://github.com/alibaba/fastjson.git
synced 2026-10-26 03:19:37 +08:00
bug fixed & decrement jar size
This commit is contained in:
@@ -104,7 +104,6 @@ import com.alibaba.fastjson.serializer.CollectionCodec;
|
||||
import com.alibaba.fastjson.serializer.CurrencyCodec;
|
||||
import com.alibaba.fastjson.serializer.DateCodec;
|
||||
import com.alibaba.fastjson.serializer.FloatCodec;
|
||||
import com.alibaba.fastjson.serializer.InetSocketAddressCodec;
|
||||
import com.alibaba.fastjson.serializer.IntegerCodec;
|
||||
import com.alibaba.fastjson.serializer.LongCodec;
|
||||
import com.alibaba.fastjson.serializer.MapCodec;
|
||||
@@ -112,7 +111,6 @@ import com.alibaba.fastjson.serializer.MiscCodec;
|
||||
import com.alibaba.fastjson.serializer.ObjectArrayCodec;
|
||||
import com.alibaba.fastjson.serializer.ReferenceCodec;
|
||||
import com.alibaba.fastjson.serializer.StringCodec;
|
||||
import com.alibaba.fastjson.serializer.TimeZoneCodec;
|
||||
import com.alibaba.fastjson.util.ASMUtils;
|
||||
import com.alibaba.fastjson.util.DeserializeBeanInfo;
|
||||
import com.alibaba.fastjson.util.FieldInfo;
|
||||
@@ -271,13 +269,13 @@ public class ParserConfig {
|
||||
derializers.put(SoftReference.class, ReferenceCodec.instance);
|
||||
|
||||
derializers.put(UUID.class, MiscCodec.instance);
|
||||
derializers.put(TimeZone.class, TimeZoneCodec.instance);
|
||||
derializers.put(TimeZone.class, MiscCodec.instance);
|
||||
derializers.put(Locale.class, MiscCodec.instance);
|
||||
derializers.put(Currency.class, CurrencyCodec.instance);
|
||||
derializers.put(InetAddress.class, MiscCodec.instance);
|
||||
derializers.put(Inet4Address.class, MiscCodec.instance);
|
||||
derializers.put(Inet6Address.class, MiscCodec.instance);
|
||||
derializers.put(InetSocketAddress.class, InetSocketAddressCodec.instance);
|
||||
derializers.put(InetSocketAddress.class, MiscCodec.instance);
|
||||
derializers.put(File.class, MiscCodec.instance);
|
||||
derializers.put(URI.class, MiscCodec.instance);
|
||||
derializers.put(URL.class, MiscCodec.instance);
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.alibaba.fastjson.parser.DefaultJSONParser;
|
||||
import com.alibaba.fastjson.parser.JSONLexer;
|
||||
import com.alibaba.fastjson.parser.JSONScanner;
|
||||
import com.alibaba.fastjson.parser.JSONToken;
|
||||
import com.alibaba.fastjson.util.IOUtils;
|
||||
|
||||
public class TimeDeserializer implements ObjectDeserializer {
|
||||
|
||||
@@ -60,6 +61,19 @@ public class TimeDeserializer implements ObjectDeserializer {
|
||||
if (dateLexer.scanISO8601DateIfMatch()) {
|
||||
longVal = dateLexer.getCalendar().getTimeInMillis();
|
||||
} else {
|
||||
boolean isDigit = true;
|
||||
for (int i = 0; i< strVal.length(); ++i) {
|
||||
char ch = strVal.charAt(i);
|
||||
if (ch < '0' || ch > '9') {
|
||||
isDigit = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isDigit) {
|
||||
dateLexer.close();
|
||||
return (T) java.sql.Time.valueOf(strVal);
|
||||
}
|
||||
|
||||
longVal = Long.parseLong(strVal);
|
||||
}
|
||||
dateLexer.close();
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
package com.alibaba.fastjson.serializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import com.alibaba.fastjson.JSONException;
|
||||
import com.alibaba.fastjson.parser.DefaultJSONParser;
|
||||
import com.alibaba.fastjson.parser.JSONLexer;
|
||||
import com.alibaba.fastjson.parser.JSONToken;
|
||||
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
|
||||
|
||||
public class InetSocketAddressCodec implements ObjectSerializer, ObjectDeserializer {
|
||||
|
||||
public static InetSocketAddressCodec instance = new InetSocketAddressCodec();
|
||||
|
||||
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
|
||||
if (object == null) {
|
||||
serializer.writeNull();
|
||||
return;
|
||||
}
|
||||
|
||||
SerializeWriter out = serializer.out;
|
||||
InetSocketAddress address = (InetSocketAddress) object;
|
||||
|
||||
InetAddress inetAddress = address.getAddress();
|
||||
|
||||
out.write('{');
|
||||
if (inetAddress != null) {
|
||||
out.writeFieldName("address");
|
||||
serializer.write(inetAddress);
|
||||
out.write(',');
|
||||
}
|
||||
out.writeFieldName("port");
|
||||
out.writeInt(address.getPort());
|
||||
out.write('}');
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
|
||||
JSONLexer lexer = parser.getLexer();
|
||||
|
||||
if (lexer.token() == JSONToken.NULL) {
|
||||
lexer.nextToken();
|
||||
return null;
|
||||
}
|
||||
|
||||
parser.accept(JSONToken.LBRACE);
|
||||
|
||||
InetAddress address = null;
|
||||
int port = 0;
|
||||
for (;;) {
|
||||
String key = lexer.stringVal();
|
||||
lexer.nextToken(JSONToken.COLON);
|
||||
|
||||
|
||||
if (key.equals("address")) {
|
||||
parser.accept(JSONToken.COLON);
|
||||
address = parser.parseObject(InetAddress.class);
|
||||
} else if (key.equals("port")) {
|
||||
parser.accept(JSONToken.COLON);
|
||||
if (lexer.token() != JSONToken.LITERAL_INT) {
|
||||
throw new JSONException("port is not int");
|
||||
}
|
||||
port = lexer.intValue();
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
parser.accept(JSONToken.COLON);
|
||||
parser.parse();
|
||||
}
|
||||
|
||||
if (lexer.token() == JSONToken.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
parser.accept(JSONToken.RBRACE);
|
||||
|
||||
return (T) new InetSocketAddress(address, port);
|
||||
}
|
||||
|
||||
public int getFastMatchToken() {
|
||||
return JSONToken.LBRACE;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 1999-2101 Alibaba Group.
|
||||
*
|
||||
* Licensed 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 com.alibaba.fastjson.serializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.alibaba.fastjson.JSONStreamAware;
|
||||
|
||||
/**
|
||||
* @author wenshao[szujobs@hotmail.com]
|
||||
*/
|
||||
public class JSONStreamAwareSerializer implements ObjectSerializer {
|
||||
|
||||
public static JSONStreamAwareSerializer instance = new JSONStreamAwareSerializer();
|
||||
|
||||
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
|
||||
SerializeWriter out = serializer.out;
|
||||
|
||||
JSONStreamAware aware = (JSONStreamAware) object;
|
||||
aware.writeJSONString(out);
|
||||
}
|
||||
}
|
||||
@@ -22,17 +22,20 @@ import java.lang.reflect.Type;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONException;
|
||||
import com.alibaba.fastjson.JSONStreamAware;
|
||||
import com.alibaba.fastjson.parser.DefaultJSONParser;
|
||||
import com.alibaba.fastjson.parser.JSONLexer;
|
||||
import com.alibaba.fastjson.parser.JSONToken;
|
||||
@@ -76,10 +79,32 @@ public class MiscCodec implements ObjectSerializer, ObjectDeserializer {
|
||||
} else if (objClass == Class.class) {
|
||||
Class<?> clazz = (Class<?>) object;
|
||||
strVal = clazz.getName();
|
||||
} else if (objClass == InetSocketAddress.class) {
|
||||
InetSocketAddress address = (InetSocketAddress) object;
|
||||
|
||||
InetAddress inetAddress = address.getAddress();
|
||||
|
||||
out.write('{');
|
||||
if (inetAddress != null) {
|
||||
out.writeFieldName("address");
|
||||
serializer.write(inetAddress);
|
||||
out.write(',');
|
||||
}
|
||||
out.writeFieldName("port");
|
||||
out.writeInt(address.getPort());
|
||||
out.write('}');
|
||||
return;
|
||||
} else if (object instanceof File) {
|
||||
strVal = ((File) object).getPath();
|
||||
} else if (object instanceof InetAddress) {
|
||||
strVal = ((InetAddress) object).getHostAddress();
|
||||
} else if (object instanceof TimeZone) {
|
||||
TimeZone timeZone = (TimeZone) object;
|
||||
strVal = timeZone.getID();
|
||||
} else if (object instanceof JSONStreamAware) {
|
||||
JSONStreamAware aware = (JSONStreamAware) object;
|
||||
aware.writeJSONString(out);
|
||||
return;
|
||||
} else {
|
||||
strVal = object.toString();
|
||||
}
|
||||
@@ -89,9 +114,51 @@ public class MiscCodec implements ObjectSerializer, ObjectDeserializer {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
|
||||
|
||||
JSONLexer lexer = parser.lexer;
|
||||
|
||||
if (clazz == InetSocketAddress.class) {
|
||||
if (lexer.token() == JSONToken.NULL) {
|
||||
lexer.nextToken();
|
||||
return null;
|
||||
}
|
||||
|
||||
parser.accept(JSONToken.LBRACE);
|
||||
|
||||
InetAddress address = null;
|
||||
int port = 0;
|
||||
for (;;) {
|
||||
String key = lexer.stringVal();
|
||||
lexer.nextToken(JSONToken.COLON);
|
||||
|
||||
|
||||
if (key.equals("address")) {
|
||||
parser.accept(JSONToken.COLON);
|
||||
address = parser.parseObject(InetAddress.class);
|
||||
} else if (key.equals("port")) {
|
||||
parser.accept(JSONToken.COLON);
|
||||
if (lexer.token() != JSONToken.LITERAL_INT) {
|
||||
throw new JSONException("port is not int");
|
||||
}
|
||||
port = lexer.intValue();
|
||||
lexer.nextToken();
|
||||
} else {
|
||||
parser.accept(JSONToken.COLON);
|
||||
parser.parse();
|
||||
}
|
||||
|
||||
if (lexer.token() == JSONToken.COMMA) {
|
||||
lexer.nextToken();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
parser.accept(JSONToken.RBRACE);
|
||||
|
||||
return (T) new InetSocketAddress(address, port);
|
||||
}
|
||||
|
||||
Object objVal;
|
||||
|
||||
if (parser.resolveStatus == DefaultJSONParser.TypeNameRedirect) {
|
||||
@@ -180,8 +247,13 @@ public class MiscCodec implements ObjectSerializer, ObjectDeserializer {
|
||||
return (T) new File(strVal);
|
||||
}
|
||||
|
||||
if (clazz == TimeZone.class) {
|
||||
return (T) TimeZone.getTimeZone(strVal);
|
||||
}
|
||||
|
||||
if (clazz instanceof ParameterizedType) {
|
||||
clazz = ((ParameterizedType) clazz).getRawType();
|
||||
ParameterizedType parmeterizedType = (ParameterizedType) clazz;
|
||||
clazz = parmeterizedType.getRawType();
|
||||
}
|
||||
|
||||
if (clazz == Class.class) {
|
||||
|
||||
@@ -198,12 +198,12 @@ public class SerializeConfig extends IdentityHashMap<Type, ObjectSerializer> {
|
||||
put(SimpleDateFormat.class, MiscCodec.instance);
|
||||
put(Locale.class, MiscCodec.instance);
|
||||
put(Currency.class, CurrencyCodec.instance);
|
||||
put(TimeZone.class, TimeZoneCodec.instance);
|
||||
put(TimeZone.class, MiscCodec.instance);
|
||||
put(UUID.class, MiscCodec.instance);
|
||||
put(InetAddress.class, MiscCodec.instance);
|
||||
put(Inet4Address.class, MiscCodec.instance);
|
||||
put(Inet6Address.class, MiscCodec.instance);
|
||||
put(InetSocketAddress.class, InetSocketAddressCodec.instance);
|
||||
put(InetSocketAddress.class, MiscCodec.instance);
|
||||
put(File.class, MiscCodec.instance);
|
||||
put(URI.class, MiscCodec.instance);
|
||||
put(URL.class, MiscCodec.instance);
|
||||
@@ -333,7 +333,7 @@ public class SerializeConfig extends IdentityHashMap<Type, ObjectSerializer> {
|
||||
} else if (JSONSerializable.class.isAssignableFrom(clazz)) {
|
||||
put(clazz, JSONSerializableSerializer.instance);
|
||||
} else if (JSONStreamAware.class.isAssignableFrom(clazz)) {
|
||||
put(clazz, JSONStreamAwareSerializer.instance);
|
||||
put(clazz, MiscCodec.instance);
|
||||
} else if (clazz.isEnum() || (clazz.getSuperclass() != null && clazz.getSuperclass().isEnum())) {
|
||||
put(clazz, EnumSerializer.instance);
|
||||
} else if (clazz.isArray()) {
|
||||
@@ -343,7 +343,7 @@ public class SerializeConfig extends IdentityHashMap<Type, ObjectSerializer> {
|
||||
} else if (Throwable.class.isAssignableFrom(clazz)) {
|
||||
put(clazz, new ExceptionSerializer(clazz));
|
||||
} else if (TimeZone.class.isAssignableFrom(clazz)) {
|
||||
put(clazz, TimeZoneCodec.instance);
|
||||
put(clazz, MiscCodec.instance);
|
||||
} else if (Appendable.class.isAssignableFrom(clazz)) {
|
||||
put(clazz, AppendableSerializer.instance);
|
||||
} else if (Charset.class.isAssignableFrom(clazz)) {
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.alibaba.fastjson.serializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import com.alibaba.fastjson.parser.DefaultJSONParser;
|
||||
import com.alibaba.fastjson.parser.JSONToken;
|
||||
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
|
||||
|
||||
public class TimeZoneCodec implements ObjectSerializer, ObjectDeserializer {
|
||||
|
||||
public final static TimeZoneCodec instance = new TimeZoneCodec();
|
||||
|
||||
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
|
||||
if (object == null) {
|
||||
serializer.writeNull();
|
||||
return;
|
||||
}
|
||||
|
||||
TimeZone timeZone = (TimeZone) object;
|
||||
serializer.write(timeZone.getID());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
|
||||
|
||||
String id = (String) parser.parse();
|
||||
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (T) TimeZone.getTimeZone(id);
|
||||
}
|
||||
|
||||
public int getFastMatchToken() {
|
||||
return JSONToken.LITERAL_STRING;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,16 +67,6 @@ public class IdentityHashMap<K, V> {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
int size = 0;
|
||||
for (int i = 0; i < buckets.length; ++i) {
|
||||
for (Entry<K, V> entry = buckets[i]; entry != null; entry = entry.next) {
|
||||
size++;
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
protected static final class Entry<K, V> {
|
||||
|
||||
public final int hashCode;
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.alibaba.fastjson.parser.deserializer.SqlDateDeserializer;
|
||||
import com.alibaba.fastjson.serializer.AtomicCodec;
|
||||
import com.alibaba.fastjson.serializer.CharacterCodec;
|
||||
import com.alibaba.fastjson.serializer.CharsetCodec;
|
||||
import com.alibaba.fastjson.serializer.InetSocketAddressCodec;
|
||||
import com.alibaba.fastjson.serializer.MiscCodec;
|
||||
import com.alibaba.fastjson.serializer.ObjectArrayCodec;
|
||||
|
||||
@@ -22,7 +21,6 @@ public class FastMatchCheckTest extends TestCase {
|
||||
Assert.assertEquals(JSONToken.LITERAL_INT, SqlDateDeserializer.instance.getFastMatchToken());
|
||||
Assert.assertEquals(JSONToken.LITERAL_STRING, CharsetCodec.instance.getFastMatchToken());
|
||||
Assert.assertEquals(JSONToken.LBRACKET, ObjectArrayCodec.instance.getFastMatchToken());
|
||||
Assert.assertEquals(JSONToken.LBRACE, InetSocketAddressCodec.instance.getFastMatchToken());
|
||||
Assert.assertEquals(JSONToken.LITERAL_STRING, CharacterCodec.instance.getFastMatchToken());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.alibaba.json.bvt.parser.deser;
|
||||
|
||||
import java.sql.Time;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TimeDeserializerTest3 extends TestCase {
|
||||
public void test_time() throws Exception {
|
||||
Assert.assertEquals(Time.valueOf("17:00:00"), JSON.parseObject("\"17:00:00\"", Time.class));
|
||||
}
|
||||
|
||||
public void test_time_null() throws Exception {
|
||||
Assert.assertEquals(null, JSON.parseObject("\"\"", Time.class));
|
||||
}
|
||||
|
||||
public static class VO {
|
||||
|
||||
private Time value;
|
||||
|
||||
public Time getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Time value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.alibaba.json.bvt.parser.deser;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.parser.DefaultExtJSONParser;
|
||||
import com.alibaba.fastjson.parser.JSONToken;
|
||||
import com.alibaba.fastjson.parser.ParserConfig;
|
||||
import com.alibaba.fastjson.serializer.TimeZoneCodec;
|
||||
import com.alibaba.fastjson.serializer.MiscCodec;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TimeZoneDeserializerTest extends TestCase {
|
||||
public void test_timezone() throws Exception {
|
||||
DefaultExtJSONParser parser = new DefaultExtJSONParser("null", ParserConfig.getGlobalInstance(), JSON.DEFAULT_PARSER_FEATURE);
|
||||
Assert.assertEquals(null, TimeZoneCodec.instance.deserialze(parser, null, null));
|
||||
Assert.assertEquals(JSONToken.LITERAL_STRING, TimeZoneCodec.instance.getFastMatchToken());
|
||||
Assert.assertEquals(null, MiscCodec.instance.deserialze(parser, null, null));
|
||||
Assert.assertEquals(JSONToken.LITERAL_STRING, MiscCodec.instance.getFastMatchToken());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.alibaba.json.bvt.serializer;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.fastjson.serializer.IntegerCodec;
|
||||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||
import com.alibaba.fastjson.util.IdentityHashMap;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -13,7 +16,7 @@ public class JSONSerializerMapTest extends TestCase {
|
||||
public void test_0() throws Exception {
|
||||
SerializeConfig map = new SerializeConfig();
|
||||
|
||||
Assert.assertFalse(0 == map.size());
|
||||
Assert.assertFalse(0 == size(map));
|
||||
Assert.assertEquals(true, map.get(Integer.class) == IntegerCodec.instance);
|
||||
|
||||
Assert.assertEquals(true, map.put(Integer.class, IntegerCodec.instance));
|
||||
@@ -22,6 +25,22 @@ public class JSONSerializerMapTest extends TestCase {
|
||||
|
||||
Assert.assertEquals(true, map.get(Integer.class) == IntegerCodec.instance);
|
||||
|
||||
Assert.assertFalse(0 == map.size());
|
||||
Assert.assertFalse(0 == size(map));
|
||||
}
|
||||
|
||||
public static int size(IdentityHashMap map) throws Exception {
|
||||
Field bucketsField = IdentityHashMap.class.getDeclaredField("buckets");
|
||||
bucketsField.setAccessible(true);
|
||||
Object[] buckets = (Object[]) bucketsField.get(map);
|
||||
|
||||
Field nextField = Class.forName("com.alibaba.fastjson.util.IdentityHashMap$Entry").getDeclaredField("next");
|
||||
|
||||
int size = 0;
|
||||
for (int i = 0; i < buckets.length; ++i) {
|
||||
for (Object entry = buckets[i]; entry != null; entry = nextField.get(entry)) {
|
||||
size++;
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,23 +4,24 @@ import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
import org.junit.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.JSONSerializer;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class JSONSerializerTest2 extends TestCase {
|
||||
|
||||
public void test_0() throws Exception {
|
||||
JSONSerializer serializer = new JSONSerializer();
|
||||
|
||||
int size = serializer.getMapping().size();
|
||||
int size = JSONSerializerMapTest.size(serializer.getMapping());
|
||||
serializer.config(SerializerFeature.WriteEnumUsingToString, false);
|
||||
serializer.config(SerializerFeature.WriteEnumUsingName, false);
|
||||
serializer.write(Type.A);
|
||||
|
||||
Assert.assertTrue(size < serializer.getMapping().size());
|
||||
Assert.assertTrue(size < JSONSerializerMapTest.size(serializer.getMapping()));
|
||||
|
||||
Assert.assertEquals(Integer.toString(Type.A.ordinal()), serializer.getWriter().toString());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user