mirror of
https://github.com/alibaba/fastjson.git
synced 2026-10-23 18:08:37 +08:00
decrement jar size
This commit is contained in:
@@ -73,7 +73,7 @@ public class JSONReader implements Closeable {
|
||||
}
|
||||
|
||||
private void startStructure() {
|
||||
final int state = context.getState();
|
||||
final int state = context.state;
|
||||
switch (state) {
|
||||
case PropertyKey:
|
||||
parser.accept(JSONToken.COLON);
|
||||
@@ -86,18 +86,18 @@ public class JSONReader implements Closeable {
|
||||
case StartObject:
|
||||
break;
|
||||
default:
|
||||
throw new JSONException("illegal state : " + context.getState());
|
||||
throw new JSONException("illegal state : " + context.state);
|
||||
}
|
||||
}
|
||||
|
||||
private void endStructure() {
|
||||
context = context.getParent();
|
||||
context = context.parent;
|
||||
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int state = context.getState();
|
||||
final int state = context.state;
|
||||
int newState = -1;
|
||||
switch (state) {
|
||||
case PropertyKey:
|
||||
@@ -114,7 +114,7 @@ public class JSONReader implements Closeable {
|
||||
break;
|
||||
}
|
||||
if (newState != -1) {
|
||||
context.setState(newState);
|
||||
context.state = newState;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class JSONReader implements Closeable {
|
||||
}
|
||||
|
||||
final int token = parser.getLexer().token();
|
||||
final int state = context.getState();
|
||||
final int state = context.state;
|
||||
switch (state) {
|
||||
case StartArray:
|
||||
case ArrayValue:
|
||||
@@ -232,7 +232,7 @@ public class JSONReader implements Closeable {
|
||||
|
||||
readBefore();
|
||||
Object object;
|
||||
switch (context.getState()) {
|
||||
switch (context.state) {
|
||||
case StartObject:
|
||||
case PropertyValue:
|
||||
object = parser.parseKey();
|
||||
@@ -259,7 +259,7 @@ public class JSONReader implements Closeable {
|
||||
}
|
||||
|
||||
private void readBefore() {
|
||||
int state = context.getState();
|
||||
int state = context.state;
|
||||
// before
|
||||
switch (state) {
|
||||
case PropertyKey:
|
||||
@@ -281,7 +281,7 @@ public class JSONReader implements Closeable {
|
||||
}
|
||||
|
||||
private void readAfter() {
|
||||
int state = context.getState();
|
||||
int state = context.state;
|
||||
int newStat = -1;
|
||||
switch (state) {
|
||||
case StartObject:
|
||||
@@ -302,7 +302,7 @@ public class JSONReader implements Closeable {
|
||||
throw new JSONException("illegal state : " + state);
|
||||
}
|
||||
if (newStat != -1) {
|
||||
context.setState(newStat);
|
||||
context.state = newStat;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,31 +2,18 @@ package com.alibaba.fastjson;
|
||||
|
||||
class JSONStreamContext {
|
||||
|
||||
final static int StartObject = 1001;
|
||||
final static int PropertyKey = 1002;
|
||||
final static int PropertyValue = 1003;
|
||||
final static int StartArray = 1004;
|
||||
final static int ArrayValue = 1005;
|
||||
final static int StartObject = 1001;
|
||||
final static int PropertyKey = 1002;
|
||||
final static int PropertyValue = 1003;
|
||||
final static int StartArray = 1004;
|
||||
final static int ArrayValue = 1005;
|
||||
|
||||
private final JSONStreamContext parent;
|
||||
protected final JSONStreamContext parent;
|
||||
|
||||
private int state;
|
||||
protected int state;
|
||||
|
||||
public JSONStreamContext(JSONStreamContext parent, int state){
|
||||
this.parent = parent;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public JSONStreamContext getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ public class JSONWriter implements Closeable, Flushable {
|
||||
}
|
||||
|
||||
private void beginStructure() {
|
||||
final int state = context.getState();
|
||||
switch (state) {
|
||||
final int state = context.state;
|
||||
switch (context.state) {
|
||||
case PropertyKey:
|
||||
writer.write(':');
|
||||
break;
|
||||
@@ -95,15 +95,14 @@ public class JSONWriter implements Closeable, Flushable {
|
||||
}
|
||||
|
||||
private void endStructure() {
|
||||
context = context.getParent();
|
||||
context = context.parent;
|
||||
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int state = context.getState();
|
||||
int newState = -1;
|
||||
switch (state) {
|
||||
switch (context.state) {
|
||||
case PropertyKey:
|
||||
newState = PropertyValue;
|
||||
break;
|
||||
@@ -119,7 +118,7 @@ public class JSONWriter implements Closeable, Flushable {
|
||||
break;
|
||||
}
|
||||
if (newState != -1) {
|
||||
context.setState(newState);
|
||||
context.state = newState;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +127,7 @@ public class JSONWriter implements Closeable, Flushable {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (context.getState()) {
|
||||
switch (context.state) {
|
||||
case StartObject:
|
||||
case StartArray:
|
||||
break;
|
||||
@@ -151,7 +150,7 @@ public class JSONWriter implements Closeable, Flushable {
|
||||
return;
|
||||
}
|
||||
|
||||
final int state = context.getState();
|
||||
final int state = context.state;
|
||||
int newState = -1;
|
||||
switch (state) {
|
||||
case PropertyKey:
|
||||
@@ -171,7 +170,7 @@ public class JSONWriter implements Closeable, Flushable {
|
||||
}
|
||||
|
||||
if (newState != -1) {
|
||||
context.setState(newState);
|
||||
context.state = newState;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1164,12 +1164,12 @@ public final class SerializeWriter extends Writer {
|
||||
}
|
||||
|
||||
public void writeFieldValue(char seperator, String name, int value) {
|
||||
if (value == Integer.MIN_VALUE || (!isEnabled(SerializerFeature.QuoteFieldNames))) {
|
||||
if (value == Integer.MIN_VALUE || (features & SerializerFeature.QuoteFieldNames.mask) == 0) {
|
||||
writeFieldValue1(seperator, name, value);
|
||||
return;
|
||||
}
|
||||
|
||||
char keySeperator = isEnabled(SerializerFeature.UseSingleQuotes) ? '\'' : '"';
|
||||
|
||||
char keySeperator = (features & SerializerFeature.UseSingleQuotes.mask) != 0 ? '\'' : '"';
|
||||
|
||||
int intSize = (value < 0) ? IOUtils.stringSize(-value) + 1 : IOUtils.stringSize(value);
|
||||
|
||||
|
||||
@@ -131,7 +131,12 @@ public enum SerializerFeature {
|
||||
/**
|
||||
* @since 1.2.7
|
||||
*/
|
||||
IgnoreNonFieldGetter
|
||||
IgnoreNonFieldGetter,
|
||||
|
||||
/**
|
||||
* @since 1.2.9
|
||||
*/
|
||||
WriteNonStringValueAsString
|
||||
;
|
||||
|
||||
SerializerFeature(){
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.alibaba.json.bvt.serializer.features;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class WriteNonStringValueAsStringTest0 extends TestCase {
|
||||
public void test_0() throws Exception {
|
||||
VO vo = new VO();
|
||||
vo.id = 100;
|
||||
|
||||
String text = JSON.toJSONString(vo, SerializerFeature.WriteNonStringValueAsString);
|
||||
// Assert.assertEquals("{\"id\":\"100\"}", text);
|
||||
}
|
||||
|
||||
public static class VO {
|
||||
public int id;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.alibaba.json.bvt.serializer.features;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class WriteNonStringValueAsStringTest1 extends TestCase {
|
||||
public void test_0() throws Exception {
|
||||
VO vo = new VO();
|
||||
vo.id = 100;
|
||||
|
||||
String text = JSON.toJSONString(vo, SerializerFeature.WriteNonStringValueAsString);
|
||||
Assert.assertEquals("{\"id\":\"100\"}", text);
|
||||
}
|
||||
|
||||
public static class VO {
|
||||
public long id;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public class BenchmarkMain {
|
||||
// executor.getCodecList().add(new JsonLibCodec());
|
||||
// executor.getCodecList().add(new JsonSmartCodec());
|
||||
|
||||
executor.setLoopCount(1000 * 10 * 1);
|
||||
executor.setLoopCount(1000 * 1000 * 1);
|
||||
|
||||
// executor.getCaseList().add(new TradeObjectParse());
|
||||
// executor.getCaseList().add(new EishayDecodeBytes());
|
||||
@@ -28,7 +28,7 @@ public class BenchmarkMain {
|
||||
// executor.getCaseList().add(new EishayDecode());
|
||||
// executor.getCaseList().add(new EishayDecodeByClassName());
|
||||
// executor.getCaseList().add(new EishayTreeDecode());
|
||||
executor.getCaseList().add(new EishayEncode());
|
||||
executor.getCaseList().add(new EishayDecode());
|
||||
// executor.getCaseList().add(new EishayEncodeManual());
|
||||
// executor.getCaseList().add(new IntArray1000Decode());
|
||||
// executor.getCaseList().add(new StringArray1000Decode());
|
||||
|
||||
@@ -16,6 +16,10 @@ public class FastjsonCodec implements Codec {
|
||||
|
||||
private ParserConfig config = ParserConfig.getGlobalInstance();
|
||||
|
||||
public FastjsonCodec(){
|
||||
System.out.println("fastjson-" + JSON.VERSION);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "fastjson";
|
||||
}
|
||||
|
||||
@@ -14,10 +14,12 @@ import com.alibaba.fastjson.serializer.SerializeWriter;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
|
||||
public class FastjsonSCodec implements Codec {
|
||||
|
||||
public FastjsonSCodec(){
|
||||
System.out.println("fastjson-" + JSON.VERSION);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "fastjson";
|
||||
return "fastjsonS";
|
||||
}
|
||||
|
||||
public <T> T decodeObject(String text, Class<T> clazz) {
|
||||
|
||||
Reference in New Issue
Block a user