Compare commits

..

5 Commits

Author SHA1 Message Date
wenshao
aa2cbee62e refactor(ObjectWriterCreatorASM): Update method descriptor for writeListValueJSONB
This commit updates the method descriptor for `writeListValueJSONB` to use a constant (`METHOD_DESC_WRITE_LIST_VALUE_JSONB`) instead of defining it inline. This refactors the code for better readability and maintainability.
2025-02-21 06:03:24 +08:00
wenshao
619c06b3fa update benchmark 2025-02-21 05:56:04 +08:00
wenshao
808b428197 bug fix for codegen 2025-02-21 05:51:36 +08:00
wenshao
765b00fcb2 Merge branch 'main' into optim_jsonb_write_array_mapping
# Conflicts:
#	core/src/main/java/com/alibaba/fastjson2/JSONB.java
2025-02-21 05:31:56 +08:00
wenshao
53480d4985 optimize jsonb write array_mapping 2025-02-20 12:16:54 +08:00
97 changed files with 1483 additions and 6353 deletions

BIN
.gitignore vendored

Binary file not shown.

View File

@ -41,7 +41,7 @@
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId> <artifactId>fastjson2</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -49,7 +49,7 @@
```groovy ```groovy
dependencies { dependencies {
implementation 'com.alibaba.fastjson2:fastjson2:2.0.56' implementation 'com.alibaba.fastjson2:fastjson2:2.0.55'
} }
``` ```
@ -67,7 +67,7 @@ dependencies {
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -75,7 +75,7 @@ dependencies {
```groovy ```groovy
dependencies { dependencies {
implementation 'com.alibaba:fastjson:2.0.56' implementation 'com.alibaba:fastjson:2.0.55'
} }
``` ```
@ -89,7 +89,7 @@ dependencies {
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-kotlin</artifactId> <artifactId>fastjson2-kotlin</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -114,7 +114,7 @@ dependencies {
```kotlin ```kotlin
dependencies { dependencies {
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.56") implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.55")
} }
``` ```
@ -135,7 +135,7 @@ dependencies {
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension-spring5</artifactId> <artifactId>fastjson2-extension-spring5</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -143,7 +143,7 @@ dependencies {
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension-spring6</artifactId> <artifactId>fastjson2-extension-spring6</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -151,14 +151,14 @@ dependencies {
```groovy ```groovy
dependencies { dependencies {
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring5:2.0.56' implementation 'com.alibaba.fastjson2:fastjson2-extension-spring5:2.0.55'
} }
``` ```
```groovy ```groovy
dependencies { dependencies {
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring6:2.0.56' implementation 'com.alibaba.fastjson2:fastjson2-extension-spring6:2.0.55'
} }
``` ```

View File

@ -47,7 +47,7 @@ Related Documents:
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId> <artifactId>fastjson2</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -55,7 +55,7 @@ Related Documents:
```groovy ```groovy
dependencies { dependencies {
implementation 'com.alibaba.fastjson2:fastjson2:2.0.56' implementation 'com.alibaba.fastjson2:fastjson2:2.0.55'
} }
``` ```
@ -73,7 +73,7 @@ If you are using `fastjson 1.2.x`, you can use the compatibility package. The co
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -81,7 +81,7 @@ If you are using `fastjson 1.2.x`, you can use the compatibility package. The co
```groovy ```groovy
dependencies { dependencies {
implementation 'com.alibaba:fastjson:2.0.56' implementation 'com.alibaba:fastjson:2.0.55'
} }
``` ```
@ -95,7 +95,7 @@ If your project uses `kotlin`, you can use the `Fastjson-Kotlin` module, and use
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-kotlin</artifactId> <artifactId>fastjson2-kotlin</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -120,7 +120,7 @@ If the data class is used or the parameters are passed in through constructor, t
```kotlin ```kotlin
dependencies { dependencies {
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.56") implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.55")
} }
``` ```
@ -141,7 +141,7 @@ If your project uses a framework such as `SpringFramework`, you can use the `fas
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension</artifactId> <artifactId>fastjson2-extension</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -149,7 +149,7 @@ If your project uses a framework such as `SpringFramework`, you can use the `fas
```groovy ```groovy
dependencies { dependencies {
implementation 'com.alibaba.fastjson2:fastjson2-extension:2.0.56' implementation 'com.alibaba.fastjson2:fastjson2-extension:2.0.55'
} }
``` ```

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
@ -89,7 +89,7 @@
<dependency> <dependency>
<groupId>io.github.wycst</groupId> <groupId>io.github.wycst</groupId>
<artifactId>wast</artifactId> <artifactId>wast</artifactId>
<version>0.0.25</version> <version>0.0.23</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.annotation</groupId> <groupId>javax.annotation</groupId>

View File

@ -65,7 +65,7 @@ public class BytesAsciiCheck {
); );
} }
@Benchmark // @Benchmark
public void direct(Blackhole bh) throws Throwable { public void direct(Blackhole bh) throws Throwable {
bh.consume(hasNegatives(bytes, 0, bytes.length)); bh.consume(hasNegatives(bytes, 0, bytes.length));
} }
@ -95,17 +95,17 @@ public class BytesAsciiCheck {
bh.consume(com.alibaba.fastjson2.util.IOUtils.indexOfSlash(bytes, 0, bytes.length)); bh.consume(com.alibaba.fastjson2.util.IOUtils.indexOfSlash(bytes, 0, bytes.length));
} }
@Benchmark // @Benchmark
public void indexOfSlashV(Blackhole bh) throws Throwable { public void indexOfSlashV(Blackhole bh) throws Throwable {
bh.consume(com.alibaba.fastjson2.util.IOUtils.indexOfSlashV(bytes, 0, bytes.length)); bh.consume(com.alibaba.fastjson2.util.IOUtils.indexOfSlashV(bytes, 0, bytes.length));
} }
@Benchmark // @Benchmark
public void indexOfChar(Blackhole bh) throws Throwable { public void indexOfChar(Blackhole bh) throws Throwable {
bh.consume(indexOfChar(bytes, '\'', 0, bytes.length)); bh.consume(indexOfChar(bytes, '\'', 0, bytes.length));
} }
@Benchmark // @Benchmark
public void indexOfString(Blackhole bh) throws Throwable { public void indexOfString(Blackhole bh) throws Throwable {
bh.consume(str.indexOf('\\')); bh.consume(str.indexOf('\\'));
} }
@ -133,7 +133,7 @@ public class BytesAsciiCheck {
.mode(Mode.Throughput) .mode(Mode.Throughput)
.timeUnit(TimeUnit.MILLISECONDS) .timeUnit(TimeUnit.MILLISECONDS)
.warmupIterations(3) .warmupIterations(3)
.threads(16) .threads(1)
.forks(1) .forks(1)
.build(); .build();
new Runner(options).run(); new Runner(options).run();

View File

@ -7,17 +7,14 @@ import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.infra.Blackhole; import org.openjdk.jmh.infra.Blackhole;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets;
public class Issue2407 { public class Issue2407 {
static String str; static String str;
static byte[] utf8;
static { static {
try { try {
InputStream is = Issue2407.class.getClassLoader().getResourceAsStream("issue/issue2407.json"); InputStream is = Issue2407.class.getClassLoader().getResourceAsStream("issue/issue2407.json");
str = IOUtils.toString(is, "UTF-8"); str = IOUtils.toString(is, "UTF-8");
utf8 = str.getBytes(StandardCharsets.UTF_8);
} catch (Throwable ex) { } catch (Throwable ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@ -37,13 +34,6 @@ public class Issue2407 {
); );
} }
// @Benchmark
public void parseArray1_utf8(Blackhole bh) {
bh.consume(
JSON.parseArray(utf8, Bean.class)
);
}
public class Bean { public class Bean {
public String content; public String content;
public String hostName; public String hostName;

View File

@ -22,17 +22,13 @@ import java.util.concurrent.TimeUnit;
public class UsersParseUTF8Bytes { public class UsersParseUTF8Bytes {
static byte[] utf8Bytes; static byte[] utf8Bytes;
static char[] chars;
static String str;
static final ObjectMapper mapper = new ObjectMapper(); static final ObjectMapper mapper = new ObjectMapper();
static final Gson gson = new Gson(); static final Gson gson = new Gson();
static final DslJson<Object> dslJson = new DslJson<>(Settings.withRuntime().includeServiceLoader()); static final DslJson<Object> dslJson = new DslJson<>(Settings.withRuntime().includeServiceLoader());
static { static {
try { try {
InputStream is = UsersParseUTF8Bytes.class.getClassLoader().getResourceAsStream("data/jjb/user.json"); InputStream is = UsersParseUTF8Bytes.class.getClassLoader().getResourceAsStream("data/jjb/user.json");
str = IOUtils.toString(is, "UTF-8"); utf8Bytes = IOUtils.toString(is, "UTF-8").getBytes(StandardCharsets.UTF_8);
utf8Bytes = str.getBytes(StandardCharsets.UTF_8);
chars = str.toCharArray();
} catch (Throwable ex) { } catch (Throwable ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
@ -45,16 +41,6 @@ public class UsersParseUTF8Bytes {
// zulu17.40.19_vec : 338 // zulu17.40.19_vec : 338
} }
// @Benchmark
public void fastjson2_str(Blackhole bh) {
bh.consume(JSON.parseObject(str, Users.class));
}
// @Benchmark
public void fastjson2_chars(Blackhole bh) {
bh.consume(JSON.parseObject(chars, Users.class));
}
@Benchmark @Benchmark
public void wast(Blackhole bh) { public void wast(Blackhole bh) {
// zulu17.40.19 : 3221 // zulu17.40.19 : 3221

View File

@ -1,26 +0,0 @@
package com.alibaba.fastjson2.benchmark.simdjson;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.benchmark.eishay.EishayParseBinary;
import org.apache.commons.io.IOUtils;
import org.openjdk.jmh.infra.Blackhole;
import java.io.IOException;
import java.io.InputStream;
public class GithubEvents {
static final String file = "data/simd-json/github_events.json";
static byte[] bytes;
static {
try (InputStream is = EishayParseBinary.class.getClassLoader().getResourceAsStream(file)) {
String str = IOUtils.toString(is, "UTF-8");
bytes = str.getBytes();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void fastjson2_parse(Blackhole bh) {
bh.consume(JSON.parseArray(bytes));
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -14,9 +14,9 @@ public class TaobaoH5ApiTreeTest {
long millis = System.currentTimeMillis() - start; long millis = System.currentTimeMillis() - start;
System.out.println("TaobaoH5ApiTree-fastjson2 : " + millis); System.out.println("TaobaoH5ApiTree-fastjson2 : " + millis);
// zulu8.62.0.19 : 1940 1592 1423 1168 // zulu8.62.0.19 : 1940 1592 1423
// zulu11.52.13 : 2836 1701 2257 1194 // zulu11.52.13 : 2836 1701 2257
// zulu17.32.13 : 1516 1240 // zulu17.32.13 : 1516
// zulu18.28.13 : 1527 // zulu18.28.13 : 1527
// zulu19.0.47 : // zulu19.0.47 :
// corretto-8 : // corretto-8 :

View File

@ -16,8 +16,6 @@ public class EishayParseUTF8BytesTest {
// zulu8.62.0.19 : 703 746 710 706 700 682 717 698 526 500 474 445 425 // zulu8.62.0.19 : 703 746 710 706 700 682 717 698 526 500 474 445 425
// zulu11.52.13 : 579 565 552 541 554 553 554 538 420 424 434 370 // zulu11.52.13 : 579 565 552 541 554 553 554 538 420 424 434 370
// zulu17.40.19 : 600 604 597 593 578 567 447 420 380 379 // zulu17.40.19 : 600 604 597 593 578 567 447 420 380 379
// zulu21.37.17 : 364
// graalvm 21+35.1 : 403
} }
} }

View File

@ -14,7 +14,7 @@ public class Issue2407Test {
} }
long millis = System.currentTimeMillis() - start; long millis = System.currentTimeMillis() - start;
System.out.println("Issue2407-parseArray millis : " + millis); System.out.println("Issue2407-parseArray millis : " + millis);
// zulu17.40.19 : 2639 2557 // zulu17.40.19 : 2639 2343
} }
} }
@ -26,25 +26,11 @@ public class Issue2407Test {
} }
long millis = System.currentTimeMillis() - start; long millis = System.currentTimeMillis() - start;
System.out.println("Issue2407-parseArray1 millis : " + millis); System.out.println("Issue2407-parseArray1 millis : " + millis);
// zulu17.40.19 : 2461 2312 // zulu17.40.19 : 2461
}
}
public static void parseArray1_utf8() throws Exception {
for (int j = 0; j < 5; j++) {
long start = System.currentTimeMillis();
for (int i = 0; i < COUNT; ++i) {
benchmark.parseArray1_utf8(BH);
}
long millis = System.currentTimeMillis() - start;
System.out.println("Issue2407-parseArray1_utf8 millis : " + millis);
// zulu17.40.19 : 2422 2245
} }
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// parseArray(); parseArray1();
// parseArray1();
parseArray1_utf8();
} }
} }

View File

@ -13,7 +13,7 @@ public class ClientsParseUTF8BytesTest {
} }
long millis = System.currentTimeMillis() - start; long millis = System.currentTimeMillis() - start;
System.out.println("fastjson2 millis : " + millis); System.out.println("fastjson2 millis : " + millis);
// zulu17.40.19 : 2417 2236 2139 1985 2174 2065 1974 // zulu17.40.19 : 2417 2236 2139 1985 2174 2065
// oracle-jdk-17.0.6 : // oracle-jdk-17.0.6 :
// oracle-jdk-17.0.6_vec : // oracle-jdk-17.0.6_vec :
// oracle-jdk-17.0.6_reflect : 3566 3513 3476 // oracle-jdk-17.0.6_reflect : 3566 3513 3476

View File

@ -13,7 +13,7 @@ public class ClientsWriteUTF8BytesTest {
} }
long millis = System.currentTimeMillis() - start; long millis = System.currentTimeMillis() - start;
System.out.println("ClientsWriteUTF8Bytes-jsonb millis : " + millis); System.out.println("ClientsWriteUTF8Bytes-jsonb millis : " + millis);
// zulu17.40.19 : 609 413 // zulu17.40.19 : 609
// zulu17.40.19_vec : // zulu17.40.19_vec :
} }
} }
@ -54,8 +54,8 @@ public class ClientsWriteUTF8BytesTest {
} }
long millis = System.currentTimeMillis() - start; long millis = System.currentTimeMillis() - start;
System.out.println("ClientsWriteUTF8Bytes-wast millis : " + millis); System.out.println("ClientsWriteUTF8Bytes-wast millis : " + millis);
// zulu8.70.0.23 : 1420 // zulu8.70.0.23 :
// zulu17.40.19 : 1364 1055 // zulu17.40.19 : 1364
// zulu17.40.19_vec : // zulu17.40.19_vec :
// zulu17.40.19_reflect : // zulu17.40.19_reflect :
} }
@ -68,8 +68,9 @@ public class ClientsWriteUTF8BytesTest {
benchmark.fastjson2_str(BH); benchmark.fastjson2_str(BH);
} }
long millis = System.currentTimeMillis() - start; long millis = System.currentTimeMillis() - start;
System.out.println("ClientsWriteUTF8Bytes-fastjson2_str millis : " + millis); System.out.println("ClientsWriteUTF8Bytes-fastjson2 millis : " + millis);
// zulu17.40.19 : 1158 1192 // zulu17.40.19 :
// zulu17.40.19_vec : 1139 1313 1307 1206
} }
} }

View File

@ -13,31 +13,9 @@ public class UsersParseUTF8BytesTest {
} }
long millis = System.currentTimeMillis() - start; long millis = System.currentTimeMillis() - start;
System.out.println("fastjson2 millis : " + millis); System.out.println("fastjson2 millis : " + millis);
// zulu17.40.19 : 2198 2189 1633 1576 1496 // zulu17.40.19 : 2198 2189 1633 1576
} // oracle-jdk-17.0.6 :
} // oracle-jdk-17.0.6_vec :
public static void fastjson2_str() {
for (int j = 0; j < 5; j++) {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000 * 1000; ++i) {
benchmark.fastjson2_str(BH);
}
long millis = System.currentTimeMillis() - start;
System.out.println("fastjson2 millis : " + millis);
// zulu17.40.19 : 1479
}
}
public static void fastjson2_chars() {
for (int j = 0; j < 5; j++) {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000 * 1000; ++i) {
benchmark.fastjson2_chars(BH);
}
long millis = System.currentTimeMillis() - start;
System.out.println("fastjson2 millis : " + millis);
// zulu17.40.19 :
} }
} }
@ -77,9 +55,6 @@ public class UsersParseUTF8BytesTest {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// fastjson2();
// fastjson2_str();
// fastjson2_chars();
wast(); wast();
// dsljson(); // dsljson();
// jackson(); // jackson();

View File

@ -1,22 +0,0 @@
package com.alibaba.fastjson2.benchmark.simdjson;
import static com.alibaba.fastjson2.benchmark.JMH.BH;
public class GithubEventsTest {
private static final GithubEvents benchmark = new GithubEvents();
public static void fastjson2_parse() {
for (int j = 0; j < 5; j++) {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000 * 10; ++i) {
benchmark.fastjson2_parse(BH);
}
long millis = System.currentTimeMillis() - start;
System.out.println("GithubEvents-fastjson2_parse : " + millis);
}
}
public static void main(String[] args) throws Exception {
fastjson2_parse();
}
}

View File

@ -14,9 +14,9 @@ public class TwitterParseStringTest {
} }
long millis = System.currentTimeMillis() - start; long millis = System.currentTimeMillis() - start;
System.out.println("fastjson2 millis : " + millis); System.out.println("fastjson2 millis : " + millis);
// zulu8.70.0.23 : 4128 3465 // zulu8.70.0.23 : 4128
// zulu11.64.19 : // zulu11.64.19 :
// zulu17.42.19 : 3465 3415 3383 // zulu17.42.19 :
} }
} }
@ -35,8 +35,8 @@ public class TwitterParseStringTest {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
fastjson2(); // fastjson2();
// jackson(); jackson();
// fastjson1(); // fastjson1();
// gson(); // gson();
// wastjson(); // wastjson();

View File

@ -1,215 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>fastjson2-benchmark_21</artifactId>
<name>fastjson2-benchmark_21</name>
<description>JMH Benchmark 21 for Fastjson2</description>
<packaging>jar</packaging>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
<maven.test.skip>true</maven.test.skip>
<uberjar.name>fastjson2-benchmarks</uberjar.name>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson1x.version}</version>
</dependency>
<!--
<dependency>
<groupId>com.cainiao.ai</groupId>
<artifactId>seq-csv</artifactId>
<version>0.1.3</version>
</dependency>
-->
<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
</dependency>
<dependency>
<groupId>com.dslplatform</groupId>
<artifactId>dsl-json</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
<version>5.6.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.github.erosb</groupId>
<artifactId>everit-json-schema</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
</dependency>
<dependency>
<groupId>com.networknt</groupId>
<artifactId>json-schema-validator</artifactId>
</dependency>
<dependency>
<groupId>com.univocity</groupId>
<artifactId>univocity-parsers</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>io.github.wycst</groupId>
<artifactId>wast</artifactId>
<version>0.0.25</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>net.sourceforge.javacsv</groupId>
<artifactId>javacsv</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-vector</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>org.apache.fury</groupId>
<artifactId>fury-core</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.msgpack</groupId>
<artifactId>jackson-dataformat-msgpack</artifactId>
<version>0.9.9</version>
</dependency>
<dependency>
<groupId>org.msgpack</groupId>
<artifactId>msgpack-core</artifactId>
<version>0.9.8</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.7.1</version>
</dependency>
<dependency>
<groupId>org.simdjson</groupId>
<artifactId>simdjson-java</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${uberjar.name}</finalName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
</transformers>
<filters>
<filter>
<!--
Shading signed JARs will fail without this.
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
-->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,79 +0,0 @@
package com.alibaba.fastjson2.benchmark.simdjson;
import com.alibaba.fastjson2.JSON;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.simdjson.JsonValue;
import org.simdjson.SimdJsonParser;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import static com.alibaba.fastjson2.benchmark.simdjson.SimdJsonPaddingUtil.padded;
@State(Scope.Benchmark)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
public class ParseBenchmark {
@Param({"/data/simd-json/twitter.json", "/data/simd-json/gsoc-2018.json", "/data/simd-json/github_events.json"})
String fileName;
private final SimdJsonParser simdJsonParser = new SimdJsonParser();
private byte[] buffer;
private byte[] bufferPadded;
@Setup(Level.Trial)
public void setup() throws IOException {
try (InputStream is = ParseBenchmark.class.getResourceAsStream(fileName)) {
byte[] buf = new byte[1024 * 1024 * 64];
int count = is.read(buf);
buffer = Arrays.copyOf(buf, count);
bufferPadded = padded(buffer);
}
}
@Benchmark
public JsonValue simdjson() {
return simdJsonParser.parse(buffer, buffer.length);
}
@Benchmark
public Object fastjson() {
return JSON.parse(buffer);
}
@Benchmark
public Object wast() {
return io.github.wycst.wast.json.JSON.parse(buffer);
}
@Benchmark
public JsonValue simdjsonPadded() {
return simdJsonParser.parse(bufferPadded, buffer.length);
}
public static void main(String[] args) throws RunnerException {
Options options = new OptionsBuilder()
.include(ParseBenchmark.class.getName())
.jvmArgsAppend("--add-opens=java.base/java.time=ALL-UNNAMED", "--add-modules=jdk.incubator.vector")
.mode(Mode.Throughput)
.timeUnit(TimeUnit.MILLISECONDS)
.forks(1)
.build();
new Runner(options).run();
}
}

View File

@ -1,142 +0,0 @@
package com.alibaba.fastjson2.benchmark.simdjson;
import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.simdjson.SimdJsonParser;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static com.alibaba.fastjson2.benchmark.simdjson.SimdJsonPaddingUtil.padded;
@State(Scope.Benchmark)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
public class SchemaBasedParseAndSelectBenchmark {
private final SimdJsonParser simdJsonParser;
private final ObjectMapper objectMapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
public SchemaBasedParseAndSelectBenchmark() {
SimdJsonParser p = null;
try {
p = new SimdJsonParser();
} catch (Throwable e) {
e.printStackTrace();
}
simdJsonParser = p;
}
private byte[] buffer;
private byte[] bufferPadded;
@Setup(Level.Trial)
public void setup() throws IOException {
try (InputStream is = ParseBenchmark.class.getResourceAsStream("/data/simd-json/twitter.json")) {
buffer = is.readAllBytes();
bufferPadded = padded(buffer);
}
}
@Benchmark
public int countUniqueUsersWithDefaultProfile_simdjson() {
Set<String> defaultUsers = new HashSet<>();
SimdJsonTwitter twitter = simdJsonParser.parse(buffer, buffer.length, SimdJsonTwitter.class);
for (SimdJsonStatus status : twitter.statuses()) {
SimdJsonUser user = status.user();
if (user.default_profile()) {
defaultUsers.add(user.screen_name());
}
}
return defaultUsers.size();
}
@Benchmark
public int countUniqueUsersWithDefaultProfile_simdjsonPadded() {
Set<String> defaultUsers = new HashSet<>();
SimdJsonTwitter twitter = simdJsonParser.parse(bufferPadded, buffer.length, SimdJsonTwitter.class);
for (SimdJsonStatus status : twitter.statuses()) {
SimdJsonUser user = status.user();
if (user.default_profile()) {
defaultUsers.add(user.screen_name());
}
}
return defaultUsers.size();
}
@Benchmark
public int countUniqueUsersWithDefaultProfile_jackson() throws IOException {
Set<String> defaultUsers = new HashSet<>();
SimdJsonTwitter twitter = objectMapper.readValue(buffer, SimdJsonTwitter.class);
for (SimdJsonStatus status : twitter.statuses()) {
SimdJsonUser user = status.user();
if (user.default_profile()) {
defaultUsers.add(user.screen_name());
}
}
return defaultUsers.size();
}
@Benchmark
public int countUniqueUsersWithDefaultProfile_fastjson() {
Set<String> defaultUsers = new HashSet<>();
SimdJsonTwitter twitter = JSON.parseObject(buffer, SimdJsonTwitter.class);
for (SimdJsonStatus status : twitter.statuses()) {
SimdJsonUser user = status.user();
if (user.default_profile()) {
defaultUsers.add(user.screen_name());
}
}
return defaultUsers.size();
}
@Benchmark
public int countUniqueUsersWithDefaultProfile_wast() {
Set<String> defaultUsers = new HashSet<>();
SimdJsonTwitter twitter = io.github.wycst.wast.json.JSON.parseObject(buffer, SimdJsonTwitter.class);
for (SimdJsonStatus status : twitter.statuses()) {
SimdJsonUser user = status.user();
if (user.default_profile()) {
defaultUsers.add(user.screen_name());
}
}
return defaultUsers.size();
}
public record SimdJsonUser(boolean default_profile, String screen_name) {
}
public record SimdJsonStatus(SimdJsonUser user) {
}
public record SimdJsonTwitter(List<SimdJsonStatus> statuses) {
}
public static void main(String[] args) throws RunnerException {
Options options = new OptionsBuilder()
.include(SchemaBasedParseAndSelectBenchmark.class.getName())
.jvmArgsAppend("--add-opens=java.base/java.time=ALL-UNNAMED", "--add-modules=jdk.incubator.vector")
.mode(Mode.Throughput)
.timeUnit(TimeUnit.MILLISECONDS)
.forks(1)
.build();
new Runner(options).run();
}
}

View File

@ -1,21 +0,0 @@
package com.alibaba.fastjson2.benchmark.simdjson;
import java.util.Arrays;
import static java.nio.charset.StandardCharsets.UTF_8;
class SimdJsonPaddingUtil {
static byte[] padded(byte[] src) {
byte[] bufferPadded = new byte[src.length + 64];
System.arraycopy(src, 0, bufferPadded, 0, src.length);
return bufferPadded;
}
static byte[] padWithSpaces(String str) {
byte[] strBytes = str.getBytes(UTF_8);
byte[] padded = new byte[strBytes.length + 64];
Arrays.fill(padded, (byte) ' ');
System.arraycopy(strBytes, 0, padded, 0, strBytes.length);
return padded;
}
}

View File

@ -1,39 +0,0 @@
package com.alibaba.fastjson2.benchmark.simdjson;
import com.alibaba.fastjson2.JSON;
import org.apache.commons.io.IOUtils;
import org.openjdk.jmh.infra.Blackhole;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
public class Twitter {
static final String file = "data/simd-json/twitter.json";
static byte[] bytes;
static {
try (InputStream is = Twitter.class.getClassLoader().getResourceAsStream(file)) {
String str = IOUtils.toString(is, "UTF-8");
bytes = str.getBytes();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void fastjson2_parse(Blackhole bh) {
bh.consume(JSON.parseObject(bytes, SimdJsonTwitter.class));
}
public void wast_parse(Blackhole bh) {
bh.consume(io.github.wycst.wast.json.JSON.parseObject(bytes, SimdJsonTwitter.class));
}
public record SimdJsonUser(boolean default_profile, String screen_name) {
}
public record SimdJsonStatus(SimdJsonUser user) {
}
public record SimdJsonTwitter(List<SimdJsonStatus> statuses) {
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,23 +0,0 @@
package com.alibaba.fastjson2.benchmark;
import com.alibaba.fastjson2.JSON;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.net.URL;
public class Gsoc2018Test {
@Test
public void test() throws Exception {
String[] paths = new String[] {
"data/simd-json/twitter.json", "data/simd-json/gsoc-2018.json", "data/simd-json/github_events.json"
};
for (String path : paths) {
URL resource = Thread.currentThread().getContextClassLoader().getResource(path);
File file = new File(resource.getFile());
byte[] str = FileUtils.readFileToByteArray(file);
JSON.parse(str);
}
}
}

View File

@ -1,7 +0,0 @@
package com.alibaba.fastjson2.benchmark;
import org.openjdk.jmh.infra.Blackhole;
public class JMH {
public static final Blackhole BH = new Blackhole("Today's password is swordfish. I understand instantiating Blackholes directly is dangerous.");
}

View File

@ -1,38 +0,0 @@
package com.alibaba.fastjson2.benchmark;
import com.alibaba.fastjson2.benchmark.simdjson.Twitter;
import static com.alibaba.fastjson2.benchmark.JMH.BH;
public class TwitterTest {
private static final Twitter benchmark = new Twitter();
public static void fastjson2_parse() {
for (int j = 0; j < 5; j++) {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000; ++i) {
benchmark.fastjson2_parse(BH);
}
long millis = System.currentTimeMillis() - start;
System.out.println("Twitter-fastjson2_parse : " + millis);
// zulu21.32.17 247 234
}
}
public static void wast_parse() {
for (int j = 0; j < 5; j++) {
long start = System.currentTimeMillis();
for (int i = 0; i < 1000; ++i) {
benchmark.wast_parse(BH);
}
long millis = System.currentTimeMillis() - start;
System.out.println("Twitter-wast_parse : " + millis);
// zulu21.32.17 211
}
}
public static void main(String[] args) throws Exception {
fastjson2_parse();
// wast_parse();
}
}

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -37,7 +37,7 @@ public interface JSON {
/** /**
* fastjson2 version name * fastjson2 version name
*/ */
String VERSION = "2.0.57"; String VERSION = "2.0.56";
/** /**
* Parses the json string as a {@link JSONArray} or {@link JSONObject}. * Parses the json string as a {@link JSONArray} or {@link JSONObject}.

View File

@ -132,9 +132,9 @@ public abstract class JSONReader
} }
public final void errorOnNoneSerializable(Class objectClass) { public final void errorOnNoneSerializable(Class objectClass) {
if ((context.features & MASK_ERROR_ON_NONE_SERIALIZABLE) != 0 if ((context.features & Feature.ErrorOnNoneSerializable.mask) != 0
&& !Serializable.class.isAssignableFrom(objectClass)) { && !Serializable.class.isAssignableFrom(objectClass)) {
throw new JSONException("not support none-Serializable, class ".concat(objectClass.getName())); throw new JSONException("not support none-Serializable, class " + objectClass.getName());
} }
} }
@ -407,35 +407,36 @@ public abstract class JSONReader
} }
public final ObjectReader getObjectReader(Type type) { public final ObjectReader getObjectReader(Type type) {
return context.provider.getObjectReader(type, (context.features & MASK_FIELD_BASED) != 0); boolean fieldBased = (context.features & Feature.FieldBased.mask) != 0;
return context.provider.getObjectReader(type, fieldBased);
} }
public final boolean isSupportSmartMatch() { public final boolean isSupportSmartMatch() {
return (context.features & MASK_SUPPORT_SMART_MATCH) != 0; return (context.features & Feature.SupportSmartMatch.mask) != 0;
} }
public final boolean isInitStringFieldAsEmpty() { public final boolean isInitStringFieldAsEmpty() {
return (context.features & MASK_INIT_STRING_FIELD_AS_EMPTY) != 0; return (context.features & Feature.InitStringFieldAsEmpty.mask) != 0;
} }
public final boolean isSupportSmartMatch(long features) { public final boolean isSupportSmartMatch(long features) {
return ((context.features | features) & MASK_SUPPORT_SMART_MATCH) != 0; return ((context.features | features) & Feature.SupportSmartMatch.mask) != 0;
} }
public final boolean isSupportBeanArray() { public final boolean isSupportBeanArray() {
return (context.features & MASK_SUPPORT_ARRAY_TO_BEAN) != 0; return (context.features & Feature.SupportArrayToBean.mask) != 0;
} }
public final boolean isSupportBeanArray(long features) { public final boolean isSupportBeanArray(long features) {
return ((context.features | features) & MASK_SUPPORT_ARRAY_TO_BEAN) != 0; return ((context.features | features) & Feature.SupportArrayToBean.mask) != 0;
} }
public final boolean isSupportAutoType(long features) { public final boolean isSupportAutoType(long features) {
return ((context.features | features) & MASK_SUPPORT_AUTO_TYPE) != 0; return ((context.features | features) & Feature.SupportAutoType.mask) != 0;
} }
public final boolean isSupportAutoTypeOrHandler(long features) { public final boolean isSupportAutoTypeOrHandler(long features) {
return ((context.features | features) & MASK_SUPPORT_AUTO_TYPE) != 0 || context.autoTypeBeforeHandler != null; return ((context.features | features) & Feature.SupportAutoType.mask) != 0 || context.autoTypeBeforeHandler != null;
} }
public final boolean isJSONB() { public final boolean isJSONB() {
@ -443,11 +444,7 @@ public abstract class JSONReader
} }
public final boolean isIgnoreNoneSerializable() { public final boolean isIgnoreNoneSerializable() {
return (context.features & MASK_IGNORE_NONE_SERIALIZABLE) != 0; return (context.features & Feature.IgnoreNoneSerializable.mask) != 0;
}
public boolean hasAutoTypeBeforeHandler() {
return context.autoTypeBeforeHandler != null;
} }
public ObjectReader checkAutoType(Class expectClass, long expectClassHash, long features) { public ObjectReader checkAutoType(Class expectClass, long expectClassHash, long features) {
@ -1073,7 +1070,15 @@ public abstract class JSONReader
values[size++] = readInt64Value(); values[size++] = readInt64Value();
} }
return size == values.length ? values : Arrays.copyOf(values, size); nextIfComma();
long[] array;
if (size == values.length) {
array = values;
} else {
array = Arrays.copyOf(values, size);
}
return array;
} }
if (isString()) { if (isString()) {
@ -1082,7 +1087,7 @@ public abstract class JSONReader
return null; return null;
} }
throw error("not support input ".concat(str)); throw new JSONException(info("not support input " + str));
} }
throw new JSONException(info("TODO")); throw new JSONException(info("TODO"));
@ -1907,6 +1912,7 @@ public abstract class JSONReader
values[size++] = readString(); values[size++] = readString();
} }
nextIfComma();
if (values.length == size) { if (values.length == size) {
return values; return values;
@ -3359,7 +3365,7 @@ public abstract class JSONReader
} }
if (charset == StandardCharsets.US_ASCII || charset == StandardCharsets.ISO_8859_1) { if (charset == StandardCharsets.US_ASCII || charset == StandardCharsets.ISO_8859_1) {
return JSONReaderASCII.of(context, null, bytes, offset, length); return new JSONReaderASCII(context, null, bytes, offset, length);
} }
throw new JSONException("not support charset " + charset); throw new JSONException("not support charset " + charset);
@ -3383,7 +3389,7 @@ public abstract class JSONReader
} }
if (charset == StandardCharsets.US_ASCII || charset == StandardCharsets.ISO_8859_1) { if (charset == StandardCharsets.US_ASCII || charset == StandardCharsets.ISO_8859_1) {
return JSONReaderASCII.of(context, null, bytes, offset, length); return new JSONReaderASCII(context, null, bytes, offset, length);
} }
throw new JSONException("not support charset " + charset); throw new JSONException("not support charset " + charset);
@ -3430,7 +3436,7 @@ public abstract class JSONReader
} }
if (charset == StandardCharsets.US_ASCII) { if (charset == StandardCharsets.US_ASCII) {
return JSONReaderASCII.of(context, is); return new JSONReaderASCII(context, is);
} }
return JSONReader.of(new InputStreamReader(is, charset), context); return JSONReader.of(new InputStreamReader(is, charset), context);
@ -3488,7 +3494,7 @@ public abstract class JSONReader
int coder = STRING_CODER.applyAsInt(str); int coder = STRING_CODER.applyAsInt(str);
if (coder == LATIN1) { if (coder == LATIN1) {
byte[] bytes = STRING_VALUE.apply(str); byte[] bytes = STRING_VALUE.apply(str);
return JSONReaderASCII.of(context, str, bytes, 0, bytes.length); return new JSONReaderASCII(context, str, bytes, 0, bytes.length);
} }
} catch (Exception e) { } catch (Exception e) {
throw new JSONException("unsafe get String.coder error"); throw new JSONException("unsafe get String.coder error");
@ -3521,7 +3527,7 @@ public abstract class JSONReader
int coder = STRING_CODER.applyAsInt(str); int coder = STRING_CODER.applyAsInt(str);
if (coder == LATIN1) { if (coder == LATIN1) {
byte[] bytes = STRING_VALUE.apply(str); byte[] bytes = STRING_VALUE.apply(str);
return JSONReaderASCII.of(context, str, bytes, offset, length); return new JSONReaderASCII(context, str, bytes, offset, length);
} }
} catch (Exception e) { } catch (Exception e) {
throw new JSONException("unsafe get String.coder error"); throw new JSONException("unsafe get String.coder error");
@ -4320,34 +4326,24 @@ public abstract class JSONReader
} }
} }
protected static final long MASK_FIELD_BASED = 1L;
protected static final long MASK_IGNORE_NONE_SERIALIZABLE = 1L << 1;
protected static final long MASK_ERROR_ON_NONE_SERIALIZABLE = 1L << 2;
protected static final long MASK_SUPPORT_ARRAY_TO_BEAN = 1L << 3;
protected static final long MASK_INIT_STRING_FIELD_AS_EMPTY = 1L << 4;
protected static final long MASK_SUPPORT_AUTO_TYPE = 1L << 5;
protected static final long MASK_SUPPORT_SMART_MATCH = 1L << 6;
protected static final long MASK_TRIM_STRING = 1L << 14; protected static final long MASK_TRIM_STRING = 1L << 14;
protected static final long MASK_ALLOW_UN_QUOTED_FIELD_NAMES = 1L << 17;
protected static final long MASK_EMPTY_STRING_AS_NULL = 1L << 27; protected static final long MASK_EMPTY_STRING_AS_NULL = 1L << 27;
protected static final long MASK_DISABLE_SINGLE_QUOTE = 1L << 31L;
protected static final long MASK_DISABLE_REFERENCE_DETECT = 1L << 33;
public enum Feature { public enum Feature {
FieldBased(MASK_FIELD_BASED), FieldBased(1),
IgnoreNoneSerializable(MASK_IGNORE_NONE_SERIALIZABLE), IgnoreNoneSerializable(1 << 1),
/** /**
* @since 2.0.14 * @since 2.0.14
*/ */
ErrorOnNoneSerializable(MASK_ERROR_ON_NONE_SERIALIZABLE), ErrorOnNoneSerializable(1 << 2),
SupportArrayToBean(MASK_SUPPORT_ARRAY_TO_BEAN), SupportArrayToBean(1 << 3),
InitStringFieldAsEmpty(MASK_INIT_STRING_FIELD_AS_EMPTY), InitStringFieldAsEmpty(1 << 4),
/** /**
* It is not safe to explicitly turn on autoType, it is recommended to use AutoTypeBeforeHandler * It is not safe to explicitly turn on autoType, it is recommended to use AutoTypeBeforeHandler
*/ */
@Deprecated @Deprecated
SupportAutoType(MASK_SUPPORT_AUTO_TYPE), SupportAutoType(1 << 5),
SupportSmartMatch(MASK_SUPPORT_SMART_MATCH), SupportSmartMatch(1 << 6),
UseNativeObject(1 << 7), UseNativeObject(1 << 7),
SupportClassForName(1 << 8), SupportClassForName(1 << 8),
IgnoreSetNullValue(1 << 9), IgnoreSetNullValue(1 << 9),
@ -4358,7 +4354,7 @@ public abstract class JSONReader
TrimString(MASK_TRIM_STRING), TrimString(MASK_TRIM_STRING),
ErrorOnNotSupportAutoType(1 << 15), ErrorOnNotSupportAutoType(1 << 15),
DuplicateKeyValueAsArray(1 << 16), DuplicateKeyValueAsArray(1 << 16),
AllowUnQuotedFieldNames(MASK_ALLOW_UN_QUOTED_FIELD_NAMES), AllowUnQuotedFieldNames(1 << 17),
NonStringKeyAsString(1 << 18), NonStringKeyAsString(1 << 18),
/** /**
* @since 2.0.13 * @since 2.0.13
@ -4455,17 +4451,12 @@ public abstract class JSONReader
* Feature that disables the support for single quote. * Feature that disables the support for single quote.
* @since 2.0.53 * @since 2.0.53
*/ */
DisableSingleQuote(MASK_DISABLE_SINGLE_QUOTE), DisableSingleQuote(1L << 31L),
/** /**
* @since 2.0.53 * @since 2.0.53
*/ */
UseDoubleForDecimals(1L << 32L), UseDoubleForDecimals(1L << 32L);
/**
* @since 2.0.56
*/
DisableReferenceDetect(MASK_DISABLE_REFERENCE_DETECT);
public final long mask; public final long mask;
@ -4496,7 +4487,7 @@ public abstract class JSONReader
} }
} }
static final class ResolveTask { static class ResolveTask {
final FieldReader fieldReader; final FieldReader fieldReader;
final Object object; final Object object;
final Object name; final Object name;
@ -4524,21 +4515,6 @@ public abstract class JSONReader
this.ch = (char) savePoint.current; this.ch = (char) savePoint.current;
} }
final boolean checkNameBegin(int quote) {
long features = context.features;
if (quote == '\'' && ((features & MASK_DISABLE_SINGLE_QUOTE) != 0)) {
throw notSupportName();
}
if (quote != '"' && quote != '\'') {
if ((features & MASK_ALLOW_UN_QUOTED_FIELD_NAMES) != 0) {
readFieldNameHashCodeUnquote();
return true;
}
throw notSupportName();
}
return false;
}
final JSONException notSupportName() { final JSONException notSupportName() {
return new JSONException(info("not support unquoted name")); return new JSONException(info("not support unquoted name"));
} }
@ -4551,14 +4527,6 @@ public abstract class JSONReader
return new JSONException(info(message)); return new JSONException(info(message));
} }
final JSONException error(String message, Exception cause) {
return new JSONException(info(message), cause);
}
final JSONException error() {
throw new JSONValidException("error, offset " + offset + ", char " + (char) ch);
}
final JSONException error(int offset, int ch) { final JSONException error(int offset, int ch) {
throw new JSONValidException("error, offset " + offset + ", char " + (char) ch); throw new JSONValidException("error, offset " + offset + ", char " + (char) ch);
} }
@ -4764,9 +4732,14 @@ public abstract class JSONReader
if ((features & MASK_TRIM_STRING) != 0) { if ((features & MASK_TRIM_STRING) != 0) {
str = str.trim(); str = str.trim();
} }
if ((features & MASK_EMPTY_STRING_AS_NULL) != 0 && str.isEmpty()) { return (features & MASK_EMPTY_STRING_AS_NULL) != 0 && str.isEmpty() ? null : str;
return null;
} }
return str;
protected static int firstIntValue(int ch) {
return ch >= '0' && ch <= '9'
? '0' - ch
: ch == '-' || ch == '+'
? 0
: 1; // or any value > 0
} }
} }

View File

@ -17,6 +17,8 @@ import static com.alibaba.fastjson2.util.JDKUtils.*;
final class JSONReaderASCII final class JSONReaderASCII
extends JSONReaderUTF8 { extends JSONReaderUTF8 {
final String str; final String str;
static final int ESCAPE_INDEX_NOT_SET = -2;
protected int nextEscapeIndex = ESCAPE_INDEX_NOT_SET;
JSONReaderASCII(Context ctx, String str, byte[] bytes, int offset, int length) { JSONReaderASCII(Context ctx, String str, byte[] bytes, int offset, int length) {
super(ctx, bytes, offset, length); super(ctx, bytes, offset, length);
@ -1334,70 +1336,6 @@ final class JSONReaderASCII
return getFieldName(); return getFieldName();
} }
@Override
public final String readString() {
int ch = this.ch;
if (ch == '"' || ch == '\'') {
final byte[] bytes = this.bytes;
int offset = this.offset;
final int start = offset, end = this.end;
int index;
if (INDEX_OF_CHAR_LATIN1 == null) {
index = IOUtils.indexOfQuoteV(bytes, ch, offset, end);
} else {
try {
index = (int) INDEX_OF_CHAR_LATIN1.invokeExact(bytes, ch, offset, end);
}
catch (Throwable e) {
throw new JSONException(e.getMessage());
}
}
if (index == -1) {
throw error("invalid escape character EOI");
}
int slashIndex = indexOfSlash(this, bytes, offset, end);
if (slashIndex == -1 || slashIndex > index) {
offset = index + 1;
} else {
return readEscaped(bytes, slashIndex, start, end, slashIndex - offset, ch);
}
String str = STRING_CREATOR_JDK11 != null
? STRING_CREATOR_JDK11.apply(Arrays.copyOfRange(bytes, start, index), LATIN1)
: new String(bytes, start, index - start, StandardCharsets.ISO_8859_1);
long features = context.features;
if ((features & MASK_TRIM_STRING) != 0) {
str = str.trim();
}
if ((features & MASK_EMPTY_STRING_AS_NULL) != 0 && str.isEmpty()) {
str = null;
}
ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && (1L << ch & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
if (comma = ch == ',') {
ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && (1L << ch & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
}
this.ch = (char) (ch & 0xFF);
this.offset = offset;
return str;
} else if (ch == 'n') {
readNull();
return null;
}
return readStringNotMatch();
}
@Override @Override
protected final void readString0() { protected final void readString0() {
final byte[] bytes = this.bytes; final byte[] bytes = this.bytes;
@ -1481,7 +1419,64 @@ final class JSONReaderASCII
stringValue = str; stringValue = str;
} }
final String readEscaped(byte[] bytes, int offset, int start, int end, int valueLength, int quote) { @Override
public final String readString() {
int ch = this.ch;
if (ch == '"' || ch == '\'') {
final byte[] bytes = this.bytes;
int offset = this.offset;
final int start = offset, end = this.end;
int index = IOUtils.indexOfQuote(bytes, ch, offset, end);
if (index == -1) {
throw error("invalid escape character EOI");
}
int slashIndex = indexOfSlash(bytes, offset, end);
if (slashIndex == -1 || slashIndex > index) {
offset = index + 1;
} else {
return readEscaped(bytes, slashIndex, start, end, slashIndex - offset, ch);
}
String str = stringValue(
subString(bytes, start, index), context.features);
ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && (1L << ch & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
if (comma = ch == ',') {
ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && (1L << ch & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
}
this.ch = (char) (ch & 0xFF);
this.offset = offset;
return str;
}
return readStringNotMatch();
}
private int indexOfSlash(byte[] bytes, int offset, int end) {
int slashIndex = nextEscapeIndex;
if (slashIndex == ESCAPE_INDEX_NOT_SET || (slashIndex != -1 && slashIndex < offset)) {
nextEscapeIndex = slashIndex = IOUtils.indexOfSlash(bytes, offset, end);
}
return slashIndex;
}
private static String subString(byte[] bytes, int start, int offset) {
return STRING_CREATOR_JDK11 != null
? STRING_CREATOR_JDK11.apply(Arrays.copyOfRange(bytes, start, offset), LATIN1)
: new String(bytes, start, offset - start, StandardCharsets.ISO_8859_1);
}
private String readEscaped(byte[] bytes, int offset, int start, int end, int valueLength, int quote) {
for (;;) { for (;;) {
if (offset >= end) { if (offset >= end) {
throw error("invalid escape character EOI"); throw error("invalid escape character EOI");
@ -1574,12 +1569,4 @@ final class JSONReaderASCII
} }
return offset; return offset;
} }
static JSONReaderASCII of(Context ctx, String str, byte[] bytes, int offset, int length) {
return new JSONReaderASCII(ctx, str, bytes, offset, length);
}
static JSONReaderASCII of(Context ctx, InputStream is) {
return new JSONReaderASCII(ctx, is);
}
} }

View File

@ -387,9 +387,6 @@ final class JSONReaderUTF16
} }
public final boolean isReference() { public final boolean isReference() {
if ((context.features & MASK_DISABLE_REFERENCE_DETECT) != 0) {
return false;
}
// should be codeSize <= FreqInlineSize 325, current is 276 // should be codeSize <= FreqInlineSize 325, current is 276
final char[] chars = this.chars; final char[] chars = this.chars;
char ch = this.ch; char ch = this.ch;
@ -422,10 +419,10 @@ final class JSONReaderUTF16
return false; return false;
} }
return isReference0(chars, offset, end, quote); return readReference0(chars, offset, end, quote);
} }
private boolean isReference0(char[] chars, int offset, int end, char quote) { private boolean readReference0(char[] chars, int offset, int end, char quote) {
char ch; char ch;
offset += 6; offset += 6;
ch = chars[offset]; ch = chars[offset];
@ -450,9 +447,7 @@ final class JSONReaderUTF16
ch = chars[offset]; ch = chars[offset];
} }
if (ch != quote if (ch != quote || (offset + 1 < end && chars[offset + 1] == '#')) {
|| (offset + 1 < end && (ch = chars[offset + 1]) != '$' && ch != '.' && ch != '@')
) {
return false; return false;
} }
@ -2353,6 +2348,56 @@ final class JSONReaderUTF16
return getFieldName(); return getFieldName();
} }
@Override
public final boolean skipName() {
char quote = ch;
if (quote == '\'' && ((context.features & Feature.DisableSingleQuote.mask) != 0)) {
throw notSupportName();
}
if (quote != '"' && quote != '\'') {
if ((context.features & Feature.AllowUnQuotedFieldNames.mask) != 0) {
readFieldNameHashCodeUnquote();
return true;
}
throw notSupportName();
}
int offset = this.offset;
final char[] chars = this.chars;
for (; ; ) {
char ch = chars[offset++];
if (ch == '\\') {
ch = chars[offset];
offset += (ch == 'u' ? 5 : (ch == 'x' ? 3 : 1));
continue;
}
if (ch == quote) {
ch = offset == end ? EOI : chars[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : chars[offset++];
}
if (ch != ':') {
throw syntaxError(ch);
}
ch = offset == end ? EOI : chars[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : chars[offset++];
}
this.offset = offset;
this.ch = ch;
break;
}
}
return true;
}
@Override @Override
public final int readInt32Value() { public final int readInt32Value() {
char ch = this.ch; char ch = this.ch;
@ -2973,8 +3018,8 @@ final class JSONReaderUTF16
@Override @Override
public String readString() { public String readString() {
final char[] chars = this.chars; final char[] chars = this.chars;
if (ch == '"' || ch == '\'') {
final char quote = ch; final char quote = ch;
if (quote == '"' || quote == '\'') {
final long byteVectorQuote = quote == '\'' ? 0x2727_2727_2727_2727L : 0x2222_2222_2222_2222L; final long byteVectorQuote = quote == '\'' ? 0x2727_2727_2727_2727L : 0x2222_2222_2222_2222L;
int offset = this.offset; int offset = this.offset;
@ -3000,7 +3045,7 @@ final class JSONReaderUTF16
for (; ; ++i) { for (; ; ++i) {
if (offset >= end) { if (offset >= end) {
throw error("invalid escape character EOI"); throw new JSONException(info("invalid escape character EOI"));
} }
char c = chars[offset]; char c = chars[offset];
if (c == '\\') { if (c == '\\') {
@ -3104,87 +3149,63 @@ final class JSONReaderUTF16
this.ch = (char) ch; this.ch = (char) ch;
this.offset = offset; this.offset = offset;
return str; return str;
} else if (quote == 'n') {
readNull();
return null;
} }
return readStringNotMatch(); return readStringNotMatch();
} }
@Override @Override
public final boolean skipName() { public final void skipValue() {
this.offset = skipName(this, chars, offset, end); final char[] chars = this.chars;
return true; char ch = this.ch;
} int offset = this.offset, end = this.end;
comma = false;
private static int skipName(JSONReaderUTF16 jsonReader, char[] chars, int offset, int end) { switch_:
char quote = jsonReader.ch; switch (ch) {
if (jsonReader.checkNameBegin(quote)) { case '-':
return jsonReader.offset; case '+':
} case '0':
case '1':
for (; ; ) { case '2':
char ch = chars[offset++]; case '3':
if (ch == '\\') { case '4':
ch = chars[offset]; case '5':
offset += (ch == 'u' ? 5 : (ch == 'x' ? 3 : 1)); case '6':
continue; case '7':
} case '8':
case '9':
if (ch == quote) { case '.':
ch = offset == end ? EOI : chars[offset++]; boolean sign = ch == '-' || ch == '+';
if (sign) {
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : chars[offset++];
}
if (ch != ':') {
throw syntaxError(ch);
}
ch = offset == end ? EOI : chars[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : chars[offset++];
}
jsonReader.ch = ch;
return offset;
}
}
}
private static int skipNumber(JSONReaderUTF16 jsonReader, char[] bytes, int offset, int end) {
int ch = jsonReader.ch;
if (ch == '-' || ch == '+') {
if (offset < end) { if (offset < end) {
ch = bytes[offset++]; ch = chars[offset++];
} else { } else {
throw jsonReader.error(); throw numberError(offset, ch);
} }
} }
boolean dot = ch == '.'; boolean dot = ch == '.';
boolean num = false; boolean num = false;
if (!dot && (ch >= '0' && ch <= '9')) { if (!dot && (ch >= '0' && ch <= '9')) {
num = true; num = true;
while (IOUtils.isDigit2(bytes, offset)) {
offset += 2;
}
do { do {
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : chars[offset++];
} while (ch >= '0' && ch <= '9'); } while (ch >= '0' && ch <= '9');
} }
if (num && (ch == 'L' | ch == 'F' | ch == 'D' | ch == 'B' | ch == 'S')) { if (num && (ch == 'L' || ch == 'F' || ch == 'D' || ch == 'B' || ch == 'S')) {
ch = bytes[offset++]; ch = chars[offset++];
} else { }
boolean small = false; boolean small = false;
if (ch == '.') { if (ch == '.') {
small = true; small = true;
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : chars[offset++];
while (ch >= '0' && ch <= '9') { if (ch >= '0' && ch <= '9') {
ch = offset == end ? EOI : bytes[offset++]; do {
ch = offset == end ? EOI : chars[offset++];
} while (ch >= '0' && ch <= '9');
} }
} }
@ -3193,13 +3214,13 @@ final class JSONReaderUTF16
} }
if (ch == 'e' || ch == 'E') { if (ch == 'e' || ch == 'E') {
ch = bytes[offset++]; ch = chars[offset++];
boolean eSign = false; boolean eSign = false;
if (ch == '+' || ch == '-') { if (ch == '+' || ch == '-') {
eSign = true; eSign = true;
if (offset < end) { if (offset < end) {
ch = bytes[offset++]; ch = chars[offset++];
} else { } else {
throw numberError(offset, ch); throw numberError(offset, ch);
} }
@ -3207,45 +3228,51 @@ final class JSONReaderUTF16
if (ch >= '0' && ch <= '9') { if (ch >= '0' && ch <= '9') {
do { do {
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : chars[offset++];
} while (ch >= '0' && ch <= '9'); } while (ch >= '0' && ch <= '9');
} else if (eSign) { } else if (eSign) {
throw numberError(offset, ch); throw numberError(offset, ch);
} }
} }
if (ch == 'F' || ch == 'D') { if (ch == 'L' || ch == 'F' || ch == 'D' || ch == 'B' || ch == 'S') {
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : chars[offset++];
} }
break;
case 't':
if (offset + 3 > end) {
throw error(offset, ch);
} }
if (chars[offset] != 'r' || chars[offset + 1] != 'u' || chars[offset + 2] != 'e') {
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) { throw error(offset, ch);
ch = offset == end ? EOI : bytes[offset++];
} }
offset += 3;
boolean comma = false; ch = offset == end ? EOI : chars[offset++];
if (ch == ',') { break;
comma = true; case 'f':
ch = offset == end ? EOI : bytes[offset++]; if (offset + 4 > end) {
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) { throw error(offset, ch);
ch = offset == end ? EOI : bytes[offset++];
} }
if (chars[offset] != 'a' || chars[offset + 1] != 'l' || chars[offset + 2] != 's' || chars[offset + 3] != 'e') {
if ((ch == '}' || ch == ']' || ch == EOI)) { throw error(offset, ch);
throw jsonReader.error(offset, ch);
} }
} else if (ch != '}' && ch != ']' && ch != EOI) { offset += 4;
throw jsonReader.error(offset, ch); ch = offset == end ? EOI : chars[offset++];
break;
case 'n':
if (offset + 3 > end) {
throw error(offset, ch);
} }
if (chars[offset] != 'u' || chars[offset + 1] != 'l' || chars[offset + 2] != 'l') {
jsonReader.comma = comma; throw error(offset, ch);
jsonReader.ch = (char) ch;
return offset;
} }
offset += 3;
private static int skipString(JSONReaderUTF16 jsonReader, char[] chars, int offset, int end) { ch = offset == end ? EOI : chars[offset++];
char quote = jsonReader.ch; break;
char ch = offset == end ? EOI : chars[offset++]; case '"':
case '\'': {
char quote = ch;
ch = chars[offset++];
for (; ; ) { for (; ; ) {
if (ch == '\\') { if (ch == '\\') {
ch = chars[offset++]; ch = chars[offset++];
@ -3254,7 +3281,7 @@ final class JSONReaderUTF16
} else if (ch == 'x') { } else if (ch == 'x') {
offset += 2; offset += 2;
} else if (ch != '\\' && ch != '"') { } else if (ch != '\\' && ch != '"') {
jsonReader.char1(ch); char1(ch);
} }
ch = chars[offset++]; ch = chars[offset++];
continue; continue;
@ -3267,289 +3294,68 @@ final class JSONReaderUTF16
ch = chars[offset++]; ch = chars[offset++];
} }
break;
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : chars[offset++];
} }
default:
boolean comma = false; if (ch == '[') {
if (ch == ',') { next();
comma = true;
ch = offset == end ? EOI : chars[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : chars[offset++];
}
if ((ch == '}' || ch == ']' || ch == EOI)) {
throw jsonReader.error(offset, ch);
}
} else if (ch != '}' && ch != ']' && ch != EOI) {
throw jsonReader.error(offset, ch);
}
jsonReader.comma = comma;
jsonReader.ch = (char) ch;
return offset;
}
private static int skipStringEscaped(JSONReaderUTF16 jsonReader, char[] bytes, int offset, int quote) {
int ch = bytes[offset++];
for (; ; ) {
if (ch == '\\') {
ch = bytes[offset++];
if (ch == 'u') {
offset += 4;
} else if (ch == 'x') {
offset += 2;
} else if (ch != '\\' && ch != '"') {
jsonReader.char1(ch);
}
ch = bytes[offset++];
continue;
}
if (ch == quote) {
return offset;
}
ch = bytes[offset++];
}
}
private static int skipObject(JSONReaderUTF16 jsonReader, char[] bytes, int offset, int end) {
offset = next(jsonReader, bytes, offset, end);
for (int i = 0; ; ++i) { for (int i = 0; ; ++i) {
if (jsonReader.ch == '}') { if (this.ch == ']') {
break; comma = false;
offset = this.offset;
ch = offset == end ? EOI : chars[offset++];
break switch_;
} }
if (i != 0 && !jsonReader.comma) { if (i != 0 && !comma) {
throw jsonReader.valueError(); throw valueError();
} }
offset = skipName(jsonReader, bytes, offset, end); comma = false;
offset = skipValue(jsonReader, bytes, offset, end); skipValue();
} }
} else if (ch == '{') {
int ch = offset == end ? EOI : bytes[offset++]; next();
for (; ; ) {
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) { if (this.ch == '}') {
ch = offset == end ? EOI : bytes[offset++]; comma = false;
offset = this.offset;
ch = offset == end ? EOI : chars[offset++];
break switch_;
} }
skipName();
boolean comma = false; skipValue();
if (ch == ',') {
comma = true;
ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
} }
} else if (ch == 'S' && nextIfSet()) {
if ((ch == '}' || ch == ']' || ch == EOI)) { skipValue();
throw jsonReader.error(offset, ch);
}
} else if (ch != '}' && ch != ']' && ch != EOI) {
throw jsonReader.error(offset, ch);
}
jsonReader.comma = comma;
jsonReader.ch = (char) ch;
return offset;
}
public static int next(JSONReaderUTF16 jsonReader, char[] bytes, int offset, int end) {
int ch = offset == end ? EOI : bytes[offset++];
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
ch = offset == end ? EOI : bytes[offset++];
}
jsonReader.ch = (char) ch;
if (ch == '/') {
jsonReader.offset = offset;
jsonReader.skipComment();
return jsonReader.offset;
} else { } else {
return offset; throw error(offset, ch);
} }
} ch = this.ch;
offset = this.offset;
private static int skipArray(JSONReaderUTF16 jsonReader, char[] bytes, int offset, int end) {
offset = next(jsonReader, bytes, offset, end);
for (int i = 0; ; ++i) {
if (jsonReader.ch == ']') {
break; break;
} }
if (i != 0 && !jsonReader.comma) {
throw jsonReader.valueError();
}
offset = skipValue(jsonReader, bytes, offset, end);
}
int ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) { while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : chars[offset++];
} }
boolean comma = false;
if (ch == ',') { if (ch == ',') {
comma = true; comma = true;
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : chars[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) { while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : chars[offset++];
} }
} }
if (!comma && ch != '}' && ch != ']' && ch != EOI) { if (!comma && ch != '}' && ch != ']' && ch != EOI) {
throw jsonReader.error(offset, ch); throw error(offset, ch);
} }
if (comma && (ch == '}' || ch == ']' || ch == EOI)) { if (comma && (ch == '}' || ch == ']' || ch == EOI)) {
throw jsonReader.error(offset, ch); throw error(offset, ch);
} }
jsonReader.comma = comma; this.ch = ch;
jsonReader.ch = (char) ch; this.offset = offset;
return offset;
}
private static int skipFalse(JSONReaderUTF16 jsonReader, char[] bytes, int offset, int end) {
if (offset + 4 > end || IOUtils.notALSE(bytes, offset)) {
throw jsonReader.error();
}
offset += 4;
int ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
boolean comma = false;
if (ch == ',') {
comma = true;
ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
if ((ch == '}' || ch == ']' || ch == EOI)) {
throw jsonReader.error(offset, ch);
}
} else if (ch != '}' && ch != ']' && ch != EOI) {
throw jsonReader.error(offset, ch);
}
jsonReader.comma = comma;
jsonReader.ch = (char) ch;
return offset;
}
private static int skipTrue(JSONReaderUTF16 jsonReader, char[] bytes, int offset, int end) {
if (offset + 3 > end || IOUtils.notTRUE(bytes, offset - 1)) {
throw jsonReader.error();
}
offset += 3;
int ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
boolean comma = false;
if (ch == ',') {
comma = true;
ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
if ((ch == '}' || ch == ']' || ch == EOI)) {
throw jsonReader.error(offset, ch);
}
} else if (ch != '}' && ch != ']' && ch != EOI) {
throw jsonReader.error(offset, ch);
}
jsonReader.comma = comma;
jsonReader.ch = (char) ch;
return offset;
}
private static int skipNull(JSONReaderUTF16 jsonReader, char[] bytes, int offset, int end) {
if (offset + 3 > end || IOUtils.notNULL(bytes, offset - 1)) {
throw jsonReader.error();
}
offset += 3;
int ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
boolean comma = false;
if (ch == ',') {
comma = true;
ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
if ((ch == '}' || ch == ']' || ch == EOI)) {
throw jsonReader.error(offset, ch);
}
} else if (ch != '}' && ch != ']' && ch != EOI) {
throw jsonReader.error(offset, ch);
}
jsonReader.comma = comma;
jsonReader.ch = (char) ch;
return offset;
}
private static int skipSet(JSONReaderUTF16 jsonReader, char[] bytes, int offset, int end) {
if (nextIfSet(jsonReader, bytes, offset, end)) {
return skipArray(jsonReader, bytes, jsonReader.offset, end);
} else {
throw jsonReader.error();
}
}
private static boolean nextIfSet(JSONReaderUTF16 jsonReader, char[] chars, int offset, int end) {
if (offset + 1 < end && chars[offset] == 'e' && chars[offset + 1] == 't') {
offset += 2;
char ch = offset == end ? EOI : chars[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : chars[offset++];
}
jsonReader.offset = offset;
jsonReader.ch = ch;
return true;
}
return false;
}
private static int skipValue(JSONReaderUTF16 jsonReader, char[] bytes, int offset, int end) {
switch (jsonReader.ch) {
case 't':
return skipTrue(jsonReader, bytes, offset, end);
case 'f':
return skipFalse(jsonReader, bytes, offset, end);
case 'n':
return skipNull(jsonReader, bytes, offset, end);
case '"':
case '\'':
return skipString(jsonReader, bytes, offset, end);
case '{':
return skipObject(jsonReader, bytes, offset, end);
case '[':
return skipArray(jsonReader, bytes, offset, end);
case 'S':
return skipSet(jsonReader, bytes, offset, end);
default:
return skipNumber(jsonReader, bytes, offset, end);
}
}
@Override
public final void skipValue() {
this.offset = skipValue(this, chars, offset, end);
} }
@Override @Override
@ -4687,7 +4493,7 @@ final class JSONReaderUTF16
LocalDate ldt; LocalDate ldt;
try { try {
ldt = (year | month | dom) == 0 ldt = year == 0 && month == 0 && dom == 0
? null ? null
: LocalDate.of(year, month, dom); : LocalDate.of(year, month, dom);
} catch (DateTimeException ex) { } catch (DateTimeException ex) {
@ -4702,16 +4508,6 @@ final class JSONReaderUTF16
return ldt; return ldt;
} }
LocalDate localDate = readLocalDate0(offset, chars, quote);
if (localDate != null) {
return localDate;
}
}
}
return super.readLocalDate();
}
private LocalDate readLocalDate0(int offset, char[] chars, char quote) {
int nextQuoteOffset = -1; int nextQuoteOffset = -1;
for (int i = offset, end = Math.min(i + 17, this.end); i < end; ++i) { for (int i = offset, end = Math.min(i + 17, this.end); i < end; ++i) {
if (chars[i] == quote) { if (chars[i] == quote) {
@ -4734,15 +4530,17 @@ final class JSONReaderUTF16
} }
return localDate; return localDate;
} }
return null; }
}
return super.readLocalDate();
} }
public final OffsetDateTime readOffsetDateTime() { public final OffsetDateTime readOffsetDateTime() {
final char[] chars = this.chars; final char[] chars = this.chars;
int offset = this.offset, end = this.end; final int offset = this.offset;
char quote = this.ch; if (this.ch == '"' || this.ch == '\'') {
if (quote == '"' || quote == '\'') {
if (!context.formatComplex) { if (!context.formatComplex) {
char quote = this.ch;
char c10; char c10;
int off21 = offset + 19; int off21 = offset + 19;
if (off21 < chars.length if (off21 < chars.length
@ -4764,49 +4562,35 @@ final class JSONReaderUTF16
return zdt == null ? null : zdt.toOffsetDateTime(); return zdt == null ? null : zdt.toOffsetDateTime();
} }
int nanos = 0, nanoSize = 0; LocalDate localDate;
offset += 19; try {
char ch = chars[offset++]; localDate = year == 0 && month == 0 && dom == 0
if (ch == '.') { ? null
ch = chars[offset++]; : LocalDate.of(year, month, dom);
} catch (DateTimeException ex) {
throw new JSONException(info("read date error"), ex);
} }
while (ch >= '0' && ch <= '9') {
nanos = nanos * 10 + (ch - '0'); int nanoSize = -1;
nanoSize++; int len = 0;
if (offset < end) { for (int start = offset + 19, i = start, end = offset + 31; i < end && i < this.end && i < chars.length; ++i) {
ch = chars[offset++]; if (chars[i] == quote && chars[i - 1] == 'Z') {
} else { nanoSize = i - start - 2;
len = i - offset + 1;
break; break;
} }
} }
if (nanoSize != 0) { if (nanoSize != -1 || len == 21) {
nanos = DateUtils.nanos(nanos, nanoSize); int nano = nanoSize <= 0 ? 0 : DateUtils.readNanos(chars, nanoSize, offset + 20);
LocalTime localTime = LocalTime.of(hour, minute, second, nano);
LocalDateTime ldt = LocalDateTime.of(localDate, localTime);
OffsetDateTime oft = OffsetDateTime.of(ldt, ZoneOffset.UTC);
this.offset += len;
next();
if (comma = (this.ch == ',')) {
next();
} }
ZoneOffset zoneOffset = ZoneOffset.UTC; return oft;
if (ch == 'Z') {
ch = chars[offset++];
} else if (ch != quote) {
int quoteIndex = IOUtils.indexOfChar(chars, '"', offset, end);
if (quoteIndex != -1) {
zoneOffset = DateUtils.zoneOffset(chars, offset - 1, quoteIndex - offset + 1);
offset = quoteIndex + 1;
ch = quote;
}
}
if (ch == quote) {
ch = offset >= end ? EOI : chars[offset++];
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
ch = offset == end ? EOI : chars[offset++];
}
if (comma = (ch == ',')) {
ch = offset == end ? EOI : chars[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : chars[offset++];
}
}
this.offset = offset;
this.ch = ch;
return OffsetDateTime.of(year, month, dom, hour, minute, second, nanos, zoneOffset);
} }
} }
} }

View File

@ -22,8 +22,6 @@ import static java.nio.charset.StandardCharsets.UTF_8;
class JSONReaderUTF8 class JSONReaderUTF8
extends JSONReader { extends JSONReader {
static final int REF = BIG_ENDIAN ? 0x24726566 : 0x66657224; static final int REF = BIG_ENDIAN ? 0x24726566 : 0x66657224;
static final int ESCAPE_INDEX_NOT_SET = -2;
protected int nextEscapeIndex = ESCAPE_INDEX_NOT_SET;
protected final byte[] bytes; protected final byte[] bytes;
protected final int length; protected final int length;
@ -121,14 +119,6 @@ class JSONReaderUTF8
next(); next();
} }
static int indexOfSlash(JSONReaderUTF8 jsonReader, byte[] bytes, int offset, int end) {
int slashIndex = jsonReader.nextEscapeIndex;
if (slashIndex == ESCAPE_INDEX_NOT_SET || (slashIndex != -1 && slashIndex < offset)) {
jsonReader.nextEscapeIndex = slashIndex = IOUtils.indexOfSlash(bytes, offset, end);
}
return slashIndex;
}
private void char_utf8(int ch, int offset) { private void char_utf8(int ch, int offset) {
final byte[] bytes = this.bytes; final byte[] bytes = this.bytes;
switch ((ch & 0xFF) >> 4) { switch ((ch & 0xFF) >> 4) {
@ -4256,30 +4246,30 @@ class JSONReaderUTF8
@Override @Override
public final boolean skipName() { public final boolean skipName() {
this.offset = skipName(this, bytes, offset, end); char quote = ch;
if (quote == '\'' && ((context.features & Feature.DisableSingleQuote.mask) != 0)) {
throw notSupportName();
}
if (quote != '"' && quote != '\'') {
if ((context.features & Feature.AllowUnQuotedFieldNames.mask) != 0) {
readFieldNameHashCodeUnquote();
return true; return true;
} }
throw notSupportName();
private static int skipName(JSONReaderUTF8 jsonReader, byte[] bytes, int offset, int end) {
int quote = jsonReader.ch;
if (jsonReader.checkNameBegin(quote)) {
return jsonReader.offset;
} }
int index = IOUtils.indexOfQuote(bytes, quote, offset, end); int offset = this.offset;
if (index == -1) { final byte[] bytes = this.bytes;
throw jsonReader.error("invalid escape character EOI"); for (; ; ) {
int ch = bytes[offset++];
if (ch == '\\') {
ch = bytes[offset];
offset += (ch == 'u' ? 5 : (ch == 'x' ? 3 : 1));
continue;
} }
int ch; if (ch == quote) {
int slashIndex = indexOfSlash(jsonReader, bytes, offset, end);
if (slashIndex == -1 || slashIndex > index) {
offset = index + 1;
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
} else {
offset = skipStringEscaped(jsonReader, bytes, slashIndex, quote);
ch = offset == end ? EOI : bytes[offset++];
}
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) { while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
@ -4294,41 +4284,67 @@ class JSONReaderUTF8
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
} }
jsonReader.ch = (char) ch; this.offset = offset;
return offset; this.ch = (char) ch;
break;
}
} }
private static int skipNumber(JSONReaderUTF8 jsonReader, byte[] bytes, int offset, int end) { return true;
int ch = jsonReader.ch; }
if (ch == '-' || ch == '+') {
@Override
public final void skipValue() {
final byte[] bytes = this.bytes;
int ch = this.ch;
int offset = this.offset, end = this.end;
comma = false;
switch_:
switch (ch) {
case '-':
case '+':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '.':
boolean sign = ch == '-' || ch == '+';
if (sign) {
if (offset < end) { if (offset < end) {
ch = bytes[offset++]; ch = bytes[offset++];
} else { } else {
throw jsonReader.error(); throw numberError(offset, ch);
} }
} }
boolean dot = ch == '.'; boolean dot = ch == '.';
boolean num = false; boolean num = false;
if (!dot && (ch >= '0' && ch <= '9')) { if (!dot && (ch >= '0' && ch <= '9')) {
num = true; num = true;
while (IOUtils.isDigit2(bytes, offset)) {
offset += 2;
}
do { do {
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
} while (ch >= '0' && ch <= '9'); } while (ch >= '0' && ch <= '9');
} }
if (num && (ch == 'L' | ch == 'F' | ch == 'D' | ch == 'B' | ch == 'S')) { if (num && (ch == 'L' || ch == 'F' || ch == 'D' || ch == 'B' || ch == 'S')) {
ch = bytes[offset++]; ch = bytes[offset++];
} else { }
boolean small = false; boolean small = false;
if (ch == '.') { if (ch == '.') {
small = true; small = true;
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
while (ch >= '0' && ch <= '9') { if (ch >= '0' && ch <= '9') {
do {
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
} while (ch >= '0' && ch <= '9');
} }
} }
@ -4358,77 +4374,44 @@ class JSONReaderUTF8
} }
} }
if (ch == 'F' || ch == 'D') { if (ch == 'L' || ch == 'F' || ch == 'D' || ch == 'B' || ch == 'S') {
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
} }
break;
case 't':
if (offset + 3 > end) {
throw error(offset, ch);
} }
if (bytes[offset] != 'r' || bytes[offset + 1] != 'u' || bytes[offset + 2] != 'e') {
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) { throw error(offset, ch);
}
offset += 3;
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
break;
case 'f':
if (offset + 4 > end) {
throw error(offset, ch);
} }
if (bytes[offset] != 'a' || bytes[offset + 1] != 'l' || bytes[offset + 2] != 's' || bytes[offset + 3] != 'e') {
boolean comma = false; throw error(offset, ch);
if (ch == ',') { }
comma = true; offset += 4;
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) { break;
case 'n':
if (offset + 3 > end) {
throw error(offset, ch);
}
if (bytes[offset] != 'u' || bytes[offset + 1] != 'l' || bytes[offset + 2] != 'l') {
throw error(offset, ch);
}
offset += 3;
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
} break;
case '"':
if ((ch == '}' || ch == ']' || ch == EOI)) { case '\'': {
throw jsonReader.error(offset, ch);
}
} else if (ch != '}' && ch != ']' && ch != EOI) {
throw jsonReader.error(offset, ch);
}
jsonReader.comma = comma;
jsonReader.ch = (char) ch;
return offset;
}
private static int skipString(JSONReaderUTF8 jsonReader, byte[] bytes, int offset, int end) {
int ch = jsonReader.ch;
int quote = ch; int quote = ch;
int index = IOUtils.indexOfQuote(bytes, quote, offset, end); ch = bytes[offset++];
if (index == -1) {
throw jsonReader.error("invalid escape character EOI");
}
int slashIndex = indexOfSlash(jsonReader, bytes, offset, end);
if (slashIndex == -1 || slashIndex > index) {
offset = index + 1;
ch = offset == end ? EOI : bytes[offset++];
} else {
offset = skipStringEscaped(jsonReader, bytes, slashIndex, quote);
ch = offset == end ? EOI : bytes[offset++];
}
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
boolean comma = false;
if (ch == ',') {
comma = true;
ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
if ((ch == '}' || ch == ']' || ch == EOI)) {
throw jsonReader.error(offset, ch);
}
} else if (ch != '}' && ch != ']' && ch != EOI) {
throw jsonReader.error(offset, ch);
}
jsonReader.comma = comma;
jsonReader.ch = (char) ch;
return offset;
}
private static int skipStringEscaped(JSONReaderUTF8 jsonReader, byte[] bytes, int offset, int quote) {
int ch = bytes[offset++];
for (; ; ) { for (; ; ) {
if (ch == '\\') { if (ch == '\\') {
ch = bytes[offset++]; ch = bytes[offset++];
@ -4437,98 +4420,62 @@ class JSONReaderUTF8
} else if (ch == 'x') { } else if (ch == 'x') {
offset += 2; offset += 2;
} else if (ch != '\\' && ch != '"') { } else if (ch != '\\' && ch != '"') {
jsonReader.char1(ch); char1(ch);
} }
ch = bytes[offset++]; ch = bytes[offset++];
continue; continue;
} }
if (ch == quote) { if (ch == quote) {
return offset; ch = offset == end ? EOI : bytes[offset++];
break;
} }
ch = bytes[offset++]; ch = bytes[offset++];
} }
}
private static int skipObject(JSONReaderUTF8 jsonReader, byte[] bytes, int offset, int end) {
offset = next(jsonReader, bytes, offset, end);
for (int i = 0; ; ++i) {
if (jsonReader.ch == '}') {
break; break;
} }
if (i != 0 && !jsonReader.comma) { default:
throw jsonReader.valueError(); if (ch == '[') {
} next();
offset = skipName(jsonReader, bytes, offset, end); for (int i = 0; ; ++i) {
offset = skipValue(jsonReader, bytes, offset, end); if (this.ch == ']') {
} comma = false;
offset = this.offset;
int ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
break switch_;
} }
if (i != 0 && !comma) {
boolean comma = false; throw valueError();
if (ch == ',') { }
comma = true; comma = false;
ch = offset == end ? EOI : bytes[offset++]; skipValue();
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) { }
} else if (ch == '{') {
next();
for (; ; ) {
if (this.ch == '}') {
comma = false;
offset = this.offset;
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
break switch_;
} }
skipName();
if ((ch == '}' || ch == ']' || ch == EOI)) { skipValue();
throw jsonReader.error(offset, ch);
} }
} else if (ch != '}' && ch != ']' && ch != EOI) { } else if (ch == 'S' && nextIfSet()) {
throw jsonReader.error(offset, ch); skipValue();
}
jsonReader.comma = comma;
jsonReader.ch = (char) ch;
return offset;
}
public static int next(JSONReaderUTF8 jsonReader, byte[] bytes, int offset, int end) {
int ch = offset == end ? EOI : bytes[offset++];
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
ch = offset == end ? EOI : bytes[offset++];
}
if (ch < 0) {
jsonReader.char_utf8(ch, offset);
return jsonReader.offset;
}
jsonReader.ch = (char) ch;
if (ch == '/') {
jsonReader.offset = offset;
jsonReader.skipComment();
return jsonReader.offset;
} else { } else {
return offset; throw error(offset, ch);
} }
} ch = this.ch;
offset = this.offset;
private static int skipArray(JSONReaderUTF8 jsonReader, byte[] bytes, int offset, int end) {
offset = next(jsonReader, bytes, offset, end);
for (int i = 0; ; ++i) {
if (jsonReader.ch == ']') {
break; break;
} }
if (i != 0 && !jsonReader.comma) {
throw jsonReader.valueError();
}
offset = skipValue(jsonReader, bytes, offset, end);
}
int ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) { while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
} }
boolean comma = false;
if (ch == ',') { if (ch == ',') {
comma = true; comma = true;
ch = offset == end ? EOI : bytes[offset++]; ch = offset == end ? EOI : bytes[offset++];
@ -4538,158 +4485,15 @@ class JSONReaderUTF8
} }
if (!comma && ch != '}' && ch != ']' && ch != EOI) { if (!comma && ch != '}' && ch != ']' && ch != EOI) {
throw jsonReader.error(offset, ch); throw error(offset, ch);
} }
if (comma && (ch == '}' || ch == ']' || ch == EOI)) { if (comma && (ch == '}' || ch == ']' || ch == EOI)) {
throw jsonReader.error(offset, ch); throw error(offset, ch);
} }
jsonReader.comma = comma; this.ch = (char) ch;
jsonReader.ch = (char) ch; this.offset = offset;
return offset;
}
private static int skipFalse(JSONReaderUTF8 jsonReader, byte[] bytes, int offset, int end) {
if (offset + 4 > end || IOUtils.notALSE(bytes, offset)) {
throw jsonReader.error();
}
offset += 4;
int ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
boolean comma = false;
if (ch == ',') {
comma = true;
ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
if ((ch == '}' || ch == ']' || ch == EOI)) {
throw jsonReader.error(offset, ch);
}
} else if (ch != '}' && ch != ']' && ch != EOI) {
throw jsonReader.error(offset, ch);
}
jsonReader.comma = comma;
jsonReader.ch = (char) ch;
return offset;
}
private static int skipTrue(JSONReaderUTF8 jsonReader, byte[] bytes, int offset, int end) {
if (offset + 3 > end || IOUtils.notTRUE(bytes, offset - 1)) {
throw jsonReader.error();
}
offset += 3;
int ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
boolean comma = false;
if (ch == ',') {
comma = true;
ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
if ((ch == '}' || ch == ']' || ch == EOI)) {
throw jsonReader.error(offset, ch);
}
} else if (ch != '}' && ch != ']' && ch != EOI) {
throw jsonReader.error(offset, ch);
}
jsonReader.comma = comma;
jsonReader.ch = (char) ch;
return offset;
}
private static int skipNull(JSONReaderUTF8 jsonReader, byte[] bytes, int offset, int end) {
if (offset + 3 > end || IOUtils.notNULL(bytes, offset - 1)) {
throw jsonReader.error();
}
offset += 3;
int ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
boolean comma = false;
if (ch == ',') {
comma = true;
ch = offset == end ? EOI : bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
if ((ch == '}' || ch == ']' || ch == EOI)) {
throw jsonReader.error(offset, ch);
}
} else if (ch != '}' && ch != ']' && ch != EOI) {
throw jsonReader.error(offset, ch);
}
jsonReader.comma = comma;
jsonReader.ch = (char) ch;
return offset;
}
private static int skipSet(JSONReaderUTF8 jsonReader, byte[] bytes, int offset, int end) {
if (nextIfSet(jsonReader, bytes, offset, end)) {
return skipArray(jsonReader, bytes, jsonReader.offset, end);
} else {
throw jsonReader.error();
}
}
private static boolean nextIfSet(JSONReaderUTF8 jsonReader, byte[] chars, int offset, int end) {
if (offset + 1 < end && chars[offset] == 'e' && chars[offset + 1] == 't') {
offset += 2;
int ch = offset == end ? EOI : chars[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : chars[offset++];
}
jsonReader.offset = offset;
jsonReader.ch = (char) ch;
return true;
}
return false;
}
private static int skipValue(JSONReaderUTF8 jsonReader, byte[] bytes, int offset, int end) {
switch (jsonReader.ch) {
case 't':
return skipTrue(jsonReader, bytes, offset, end);
case 'f':
return skipFalse(jsonReader, bytes, offset, end);
case 'n':
return skipNull(jsonReader, bytes, offset, end);
case '"':
case '\'':
return skipString(jsonReader, bytes, offset, end);
case '{':
return skipObject(jsonReader, bytes, offset, end);
case '[':
return skipArray(jsonReader, bytes, offset, end);
case 'S':
return skipSet(jsonReader, bytes, offset, end);
default:
return skipNumber(jsonReader, bytes, offset, end);
}
}
@Override
public final void skipValue() {
this.offset = skipValue(this, bytes, offset, end);
} }
@Override @Override
@ -4893,9 +4697,9 @@ class JSONReaderUTF8
@Override @Override
public String readString() { public String readString() {
char quote = this.ch; if (ch == '"' || ch == '\'') {
if (quote == '"' || quote == '\'') {
final byte[] bytes = this.bytes; final byte[] bytes = this.bytes;
char quote = this.ch;
int valueLength; int valueLength;
int offset = this.offset; int offset = this.offset;
final int start = offset, end = this.end; final int start = offset, end = this.end;
@ -4908,7 +4712,7 @@ class JSONReaderUTF8
int upperBound = offset + ((end - offset) & ~7); int upperBound = offset + ((end - offset) & ~7);
while (offset < upperBound) { while (offset < upperBound) {
long v = getLongLE(bytes, offset); long v = getLongLE(bytes, offset);
if ((v & 0x8080808080808080L) != 0 || JSONReaderUTF8.containsSlashOrQuote(v, byteVectorQuote)) { if ((v & 0xFF00FF00FF00FF00L) != 0 || JSONReaderUTF8.containsSlashOrQuote(v, byteVectorQuote)) {
break; break;
} }
@ -4927,9 +4731,6 @@ class JSONReaderUTF8
valueEscape = true; valueEscape = true;
c = bytes[offset + 1]; c = bytes[offset + 1];
offset += (c == 'u' ? 6 : (c == 'x' ? 4 : 2)); offset += (c == 'u' ? 6 : (c == 'x' ? 4 : 2));
if (ascii && (c == 'u' || c == 'x')) {
ascii = false;
}
continue; continue;
} }
@ -4969,46 +4770,6 @@ class JSONReaderUTF8
String str; String str;
if (valueEscape) { if (valueEscape) {
if (ascii && STRING_CREATOR_JDK11 != null) {
byte[] chars = new byte[valueLength];
offset = start;
for (int i = 0; ; ++i) {
byte ch = bytes[offset];
if (ch == '\\') {
ch = bytes[++offset];
switch (ch) {
case '\\':
case '"':
break;
case 'b':
ch = '\b';
break;
case 't':
ch = '\t';
break;
case 'n':
ch = '\n';
break;
case 'f':
ch = '\f';
break;
case 'r':
ch = '\r';
break;
default:
ch = (byte) char1(ch);
break;
}
}
else if (ch == quote) {
break;
}
chars[i] = ch;
offset++;
}
str = STRING_CREATOR_JDK11.apply(chars, LATIN1);
} else {
char[] chars = new char[valueLength]; char[] chars = new char[valueLength];
offset = start; offset = start;
for (int i = 0; ; ++i) { for (int i = 0; ; ++i) {
@ -5050,16 +4811,13 @@ class JSONReaderUTF8
} }
chars[i] = (char) ch; chars[i] = (char) ch;
offset++; offset++;
} } else if (ch == quote) {
else if (ch == quote) {
break; break;
} } else {
else {
if (ch >= 0) { if (ch >= 0) {
chars[i] = (char) ch; chars[i] = (char) ch;
offset++; offset++;
} } else {
else {
switch ((ch & 0xFF) >> 4) { switch ((ch & 0xFF) >> 4) {
case 12: case 12:
case 13: { case 13: {
@ -5088,7 +4846,6 @@ class JSONReaderUTF8
} }
str = new String(chars); str = new String(chars);
}
} else if (ascii) { } else if (ascii) {
int strlen = offset - start; int strlen = offset - start;
if (strlen == 1) { if (strlen == 1) {
@ -5129,9 +4886,6 @@ class JSONReaderUTF8
this.ch = (char) ch; this.ch = (char) ch;
this.offset = offset; this.offset = offset;
return str; return str;
} else if (quote == 'n') {
readNull();
return null;
} }
return readStringNotMatch(); return readStringNotMatch();
@ -5827,11 +5581,11 @@ class JSONReaderUTF8
LocalDate ldt; LocalDate ldt;
try { try {
ldt = (year | month | dom) == 0 ldt = year == 0 && month == 0 && dom == 0
? null ? null
: LocalDate.of(year, month, dom); : LocalDate.of(year, month, dom);
} catch (DateTimeException ex) { } catch (DateTimeException ex) {
throw error("read date error", ex); throw new JSONException(info("read date error"), ex);
} }
this.offset = offset + 11; this.offset = offset + 11;
@ -5842,16 +5596,6 @@ class JSONReaderUTF8
return ldt; return ldt;
} }
LocalDate localDate = readLocalDate0(offset, bytes, quote);
if (localDate != null) {
return localDate;
}
}
}
return super.readLocalDate();
}
private LocalDate readLocalDate0(int offset, byte[] bytes, char quote) {
int nextQuoteOffset = -1; int nextQuoteOffset = -1;
for (int i = offset, end = Math.min(i + 17, this.end); i < end; ++i) { for (int i = offset, end = Math.min(i + 17, this.end); i < end; ++i) {
if (bytes[i] == quote) { if (bytes[i] == quote) {
@ -5874,12 +5618,14 @@ class JSONReaderUTF8
} }
return localDate; return localDate;
} }
return null; }
}
return super.readLocalDate();
} }
public final OffsetDateTime readOffsetDateTime() { public final OffsetDateTime readOffsetDateTime() {
final byte[] bytes = this.bytes; final byte[] bytes = this.bytes;
int offset = this.offset, end = this.end; final int offset = this.offset;
char quote = this.ch; char quote = this.ch;
if (quote == '"' || quote == '\'') { if (quote == '"' || quote == '\'') {
if (!this.context.formatComplex) { if (!this.context.formatComplex) {
@ -5894,61 +5640,42 @@ class JSONReaderUTF8
&& ((c10 = bytes[offset + 10]) == ' ' || c10 == 'T') && ((c10 = bytes[offset + 10]) == ' ' || c10 == 'T')
&& ((hms = hms(bytes, offset + 11))) != -1L && ((hms = hms(bytes, offset + 11))) != -1L
) { ) {
int nanos = 0, nanoSize = 0; int year = yy + ((int) ymd & 0xFF);
offset += 19; int month = (int) (ymd >> 24) & 0xFF;
int ch = bytes[offset++]; int dom = (int) (ymd >> 48) & 0xFF;
if (ch == '.') { int hour = (int) hms & 0xFF;
ch = bytes[offset++]; int minute = (int) (hms >> 24) & 0xFF;
int second = (int) (hms >> 48) & 0xFF;
LocalDate localDate;
try {
localDate = year == 0 && month == 0 && dom == 0
? null
: LocalDate.of(year, month, dom);
} catch (DateTimeException ex) {
throw new JSONException(info("read date error"), ex);
} }
while (ch >= '0' && ch <= '9') {
nanos = nanos * 10 + (ch - '0'); int nanoSize = -1;
nanoSize++; int len = 0;
if (offset < end) { for (int start = offset + 19, i = start, end = offset + 31; i < end && i < this.end && i < bytes.length; ++i) {
ch = bytes[offset++]; if (bytes[i] == quote && bytes[i - 1] == 'Z') {
} else { nanoSize = i - start - 2;
len = i - offset + 1;
break; break;
} }
} }
if (nanoSize != 0) { if (nanoSize != -1 || len == 21) {
nanos = DateUtils.nanos(nanos, nanoSize); int nano = nanoSize <= 0 ? 0 : DateUtils.readNanos(bytes, nanoSize, offset + 20);
LocalTime localTime = LocalTime.of(hour, minute, second, nano);
LocalDateTime ldt = LocalDateTime.of(localDate, localTime);
OffsetDateTime oft = OffsetDateTime.of(ldt, ZoneOffset.UTC);
this.offset += len;
next();
if (comma = (this.ch == ',')) {
next();
} }
ZoneOffset zoneOffset = ZoneOffset.UTC; return oft;
if (ch == 'Z') {
ch = bytes[offset++];
} else if (ch != quote) {
int quoteIndex = IOUtils.indexOfChar(bytes, '"', offset, end);
if (quoteIndex != -1) {
zoneOffset = DateUtils.zoneOffset(bytes, offset - 1, quoteIndex - offset + 1);
offset = quoteIndex + 1;
ch = quote;
}
}
if (ch == quote) {
ch = offset >= end ? EOI : bytes[offset++];
while (ch == '\0' || (ch <= ' ' && ((1L << ch) & SPACE) != 0)) {
ch = offset == end ? EOI : bytes[offset++];
}
if (comma = (ch == ',')) {
ch = offset == end ? EOI : (char) bytes[offset++];
while (ch <= ' ' && ((1L << ch) & SPACE) != 0) {
ch = offset == end ? EOI : bytes[offset++];
}
}
if (ch < 0) {
char_utf8(ch, offset);
} else {
this.offset = offset;
this.ch = (char) ch;
}
return OffsetDateTime.of(
yy + ((int) ymd & 0xFF),
(int) (ymd >> 24) & 0xFF,
(int) (ymd >> 48) & 0xFF,
(int) hms & 0xFF,
(int) (hms >> 24) & 0xFF,
(int) (hms >> 48) & 0xFF,
nanos,
zoneOffset);
} }
} }
} }
@ -6742,7 +6469,7 @@ class JSONReaderUTF8
} }
if (ch != '"' && ch != '\'') { if (ch != '"' && ch != '\'') {
throw error("syntax error, can not read uuid"); throw new JSONException(info("syntax error, can not read uuid"));
} }
final int quote = ch; final int quote = ch;
final byte[] bytes = this.bytes; final byte[] bytes = this.bytes;
@ -6822,10 +6549,7 @@ class JSONReaderUTF8
} }
static long parse4Nibbles(byte[] bytes, int offset) { static long parse4Nibbles(byte[] bytes, int offset) {
int x = UNSAFE.getInt(bytes, ARRAY_BYTE_BASE_OFFSET + offset); int x = getIntLE(bytes, offset);
if (BIG_ENDIAN) {
x = Integer.reverseBytes(x);
}
byte[] ns = NIBBLES; byte[] ns = NIBBLES;
return ns[x & 0xFF] << 12 | ns[(x >> 8) & 0xFF] << 8 | ns[(x >> 16) & 0xFF] << 4 | ns[(x >> 24) & 0xFF]; return ns[x & 0xFF] << 12 | ns[(x >> 8) & 0xFF] << 8 | ns[(x >> 16) & 0xFF] << 4 | ns[(x >> 24) & 0xFF];
} }
@ -7131,9 +6855,6 @@ class JSONReaderUTF8
@Override @Override
public final boolean isReference() { public final boolean isReference() {
// should be codeSize <= FreqInlineSize 325, current : 284 // should be codeSize <= FreqInlineSize 325, current : 284
if ((context.features & MASK_DISABLE_REFERENCE_DETECT) != 0) {
return false;
}
final byte[] bytes = this.bytes; final byte[] bytes = this.bytes;
int ch = this.ch; int ch = this.ch;
if (ch != '{') { if (ch != '{') {
@ -7161,10 +6882,10 @@ class JSONReaderUTF8
return false; return false;
} }
return isReference0(bytes, offset, end, ch); return readReference0(bytes, offset, end, ch);
} }
private boolean isReference0(byte[] bytes, int offset, int end, int quote) { private boolean readReference0(byte[] bytes, int offset, int end, int quote) {
int ch; int ch;
offset += 6; offset += 6;
ch = bytes[offset]; ch = bytes[offset];
@ -7189,9 +6910,7 @@ class JSONReaderUTF8
ch = bytes[offset]; ch = bytes[offset];
} }
if (ch != quote if (ch != quote || (offset + 1 < end && bytes[offset + 1] == '#')) {
|| (offset + 1 < end && (ch = bytes[offset + 1]) != '$' && ch != '.' && ch != '@')
) {
return false; return false;
} }

View File

@ -1632,7 +1632,7 @@ class JSONWriterUTF16
} }
private static void putLong(char[] chars, int off, long name) { private static void putLong(char[] chars, int off, long name) {
final long base = ARRAY_CHAR_BASE_OFFSET + ((long) off << 1); final long base = ARRAY_CHAR_BASE_OFFSET + (off << 1);
UNSAFE.putLong(chars, base, UNSAFE.putLong(chars, base,
(name & 0xFFL) (name & 0xFFL)
| ((name & 0xFF00L) << 8) | ((name & 0xFF00L) << 8)
@ -1646,7 +1646,7 @@ class JSONWriterUTF16
} }
private static void putLong(char[] chars, int off, long name, int name1) { private static void putLong(char[] chars, int off, long name, int name1) {
final long base = ARRAY_CHAR_BASE_OFFSET + ((long) off << 1); final long base = ARRAY_CHAR_BASE_OFFSET + (off << 1);
UNSAFE.putLong(chars, base, UNSAFE.putLong(chars, base,
(name & 0xFFL) (name & 0xFFL)
| ((name & 0xFF00L) << 8) | ((name & 0xFF00L) << 8)
@ -1667,7 +1667,7 @@ class JSONWriterUTF16
} }
private static void putLong(char[] chars, int off, long name, long name1) { private static void putLong(char[] chars, int off, long name, long name1) {
final long base = ARRAY_CHAR_BASE_OFFSET + ((long) off << 1); final long base = ARRAY_CHAR_BASE_OFFSET + (off << 1);
UNSAFE.putLong(chars, base, UNSAFE.putLong(chars, base,
(name & 0xFFL) (name & 0xFFL)
| ((name & 0xFF00L) << 8) | ((name & 0xFF00L) << 8)

View File

@ -471,7 +471,7 @@ class JSONWriterUTF8
this.bytes[this.off++] = (byte) quote; this.bytes[this.off++] = (byte) quote;
} }
public final void writeStringLatin1(byte[] value) { public void writeStringLatin1(byte[] value) {
if ((context.features & MASK_BROWSER_SECURE) != 0) { if ((context.features & MASK_BROWSER_SECURE) != 0) {
writeStringLatin1BrowserSecure(value); writeStringLatin1BrowserSecure(value);
return; return;
@ -1067,11 +1067,8 @@ class JSONWriterUTF8
15 = 0b0000_1111 => m = ((i + 6) & 0x10); (m << 1) + (m >> 1) - (m >> 4) => 39 + 0x30 + (i & 0xF) => 'f' 15 = 0b0000_1111 => m = ((i + 6) & 0x10); (m << 1) + (m >> 1) - (m >> 4) => 39 + 0x30 + (i & 0xF) => 'f'
*/ */
long m = (i + 0x0606_0606_0606_0606L) & 0x1010_1010_1010_1010L; long m = (i + 0x0606_0606_0606_0606L) & 0x1010_1010_1010_1010L;
long v = ((m << 1) + (m >> 1) - (m >> 4)) + 0x3030_3030_3030_3030L + i; return convEndian(true,
if (!BIG_ENDIAN) { ((m << 1) + (m >> 1) - (m >> 4)) + 0x3030_3030_3030_3030L + i);
v = Long.reverseBytes(v);
}
return v;
} }
/** /**

View File

@ -15,8 +15,10 @@ final class JSONWriterUTF8JDK9
return; return;
} }
int coder = STRING_CODER.applyAsInt(str);
byte[] value = STRING_VALUE.apply(str); byte[] value = STRING_VALUE.apply(str);
if (STRING_CODER.applyAsInt(str) == 0) {
if (coder == 0) {
writeStringLatin1(value); writeStringLatin1(value);
} else { } else {
writeStringUTF16(value); writeStringUTF16(value);

View File

@ -58,7 +58,6 @@ public class ASMUtils {
public static final String TYPE_OBJECT_READER_10 = ObjectReader10.class.getName().replace('.', '/'); public static final String TYPE_OBJECT_READER_10 = ObjectReader10.class.getName().replace('.', '/');
public static final String TYPE_OBJECT_READER_11 = ObjectReader11.class.getName().replace('.', '/'); public static final String TYPE_OBJECT_READER_11 = ObjectReader11.class.getName().replace('.', '/');
public static final String TYPE_OBJECT_READER_12 = ObjectReader12.class.getName().replace('.', '/'); public static final String TYPE_OBJECT_READER_12 = ObjectReader12.class.getName().replace('.', '/');
public static final String TYPE_OBJECT_READER_NONE_DEFAULT_CONSTRUCTOR = ObjectReaderNoneDefaultConstructor.class.getName().replace('.', '/');
public static final String TYPE_BYTE_ARRAY_VALUE_CONSUMER = ByteArrayValueConsumer.class.getName().replace('.', '/'); public static final String TYPE_BYTE_ARRAY_VALUE_CONSUMER = ByteArrayValueConsumer.class.getName().replace('.', '/');
public static final String TYPE_CHAR_ARRAY_VALUE_CONSUMER = CharArrayValueConsumer.class.getName().replace('.', '/'); public static final String TYPE_CHAR_ARRAY_VALUE_CONSUMER = CharArrayValueConsumer.class.getName().replace('.', '/');
public static final String TYPE_TYPE_UTILS = TypeUtils.class.getName().replace('.', '/'); public static final String TYPE_TYPE_UTILS = TypeUtils.class.getName().replace('.', '/');

View File

@ -123,8 +123,7 @@ final class Constants {
// static final int ASTORE_3 = 78; // static final int ASTORE_3 = 78;
static final int WIDE = 196; static final int WIDE = 196;
static final int GOTO_W = 200; static final int GOTO_W = 200;
static final int JSR_W = 201; // static final int JSR_W = 201;
static final int ASM_GOTO_W = 220;
// Constants to convert between normal and wide jump instructions. // Constants to convert between normal and wide jump instructions.

View File

@ -77,8 +77,6 @@ class Frame {
// Constants to manipulate the DIM field of an abstract type. // Constants to manipulate the DIM field of an abstract type.
private static final int ARRAY_OF = +1 << DIM_SHIFT;
/** /**
* The constant to be added to an abstract type to get one with one less array dimension. * The constant to be added to an abstract type to get one with one less array dimension.
*/ */
@ -879,7 +877,6 @@ class Frame {
case Opcodes.IASTORE: case Opcodes.IASTORE:
case Opcodes.BASTORE: case Opcodes.BASTORE:
case Opcodes.CASTORE: case Opcodes.CASTORE:
case Opcodes.AASTORE:
pop(3); pop(3);
break; break;
case Opcodes.POP: case Opcodes.POP:
@ -983,15 +980,6 @@ class Frame {
push(LONG); push(LONG);
push(TOP); push(TOP);
break; break;
case Opcodes.I2F:
pop(1);
push(FLOAT);
break;
case Opcodes.I2D:
pop(1);
push(DOUBLE);
push(TOP);
break;
case Opcodes.F2I: case Opcodes.F2I:
case Opcodes.ARRAYLENGTH: case Opcodes.ARRAYLENGTH:
case Opcodes.INSTANCEOF: case Opcodes.INSTANCEOF:
@ -1034,15 +1022,6 @@ class Frame {
case Opcodes.NEW: case Opcodes.NEW:
push(UNINITIALIZED_KIND | symbolTable.addUninitializedType(argSymbol.value, arg)); push(UNINITIALIZED_KIND | symbolTable.addUninitializedType(argSymbol.value, arg));
break; break;
case Opcodes.ANEWARRAY:
String arrayElementType = argSymbol.value;
pop();
if (arrayElementType.charAt(0) == '[') {
push(symbolTable, '[' + arrayElementType);
} else {
push(ARRAY_OF | REFERENCE_KIND | symbolTable.addType(arrayElementType));
}
break;
case Opcodes.CHECKCAST: case Opcodes.CHECKCAST:
String castType = argSymbol.value; String castType = argSymbol.value;
pop(); pop();

View File

@ -194,41 +194,6 @@ public final class MethodWriter {
visitInsn(Opcodes.ICONST_5); visitInsn(Opcodes.ICONST_5);
} }
public void iconst_n(int n) {
switch (n) {
case 0:
iconst_0();
break;
case 1:
iconst_1();
break;
case 2:
iconst_2();
break;
case 3:
iconst_3();
break;
case 4:
iconst_4();
break;
case 5:
iconst_5();
break;
case -1:
iconst_m1();
break;
default:
if (n >= -128 && n < 127) {
bipush(n);
} else if (n >= -32768 && n < 32767) {
sipush(n);
} else {
visitLdcInsn(n);
}
break;
}
}
public void iconst_m1() { public void iconst_m1() {
visitInsn(Opcodes.ICONST_M1); visitInsn(Opcodes.ICONST_M1);
} }
@ -293,14 +258,6 @@ public final class MethodWriter {
visitInsn(Opcodes.I2L); visitInsn(Opcodes.I2L);
} }
public void i2f() {
visitInsn(Opcodes.I2F);
}
public void i2d() {
visitInsn(Opcodes.I2D);
}
public void lxor() { public void lxor() {
visitInsn(Opcodes.LXOR); visitInsn(Opcodes.LXOR);
} }
@ -313,10 +270,6 @@ public final class MethodWriter {
visitInsn(Opcodes.AALOAD); visitInsn(Opcodes.AALOAD);
} }
public void aastore() {
visitInsn(Opcodes.AASTORE);
}
private void visitInsn(final int opcode) { private void visitInsn(final int opcode) {
lastBytecodeOffset = code.length; lastBytecodeOffset = code.length;
// Add the instruction to the bytecode of the method. // Add the instruction to the bytecode of the method.
@ -467,10 +420,6 @@ public final class MethodWriter {
visitTypeInsn(Opcodes.NEW, type); visitTypeInsn(Opcodes.NEW, type);
} }
public void anewArray(final String type) {
visitTypeInsn(Opcodes.ANEWARRAY, type);
}
public void instanceOf(final String type) { public void instanceOf(final String type) {
visitTypeInsn(Opcodes.INSTANCEOF, type); visitTypeInsn(Opcodes.INSTANCEOF, type);
} }
@ -613,32 +562,7 @@ public final class MethodWriter {
boolean nextInsnIsJumpTarget = false; boolean nextInsnIsJumpTarget = false;
if ((label.flags & Label.FLAG_RESOLVED) != 0 if ((label.flags & Label.FLAG_RESOLVED) != 0
&& label.bytecodeOffset - code.length < Short.MIN_VALUE) { && label.bytecodeOffset - code.length < Short.MIN_VALUE) {
// Case of a backward jump with an offset < -32768. In this case we automatically replace GOTO throw new JSONException("not supported");
// with GOTO_W, JSR with JSR_W and IFxxx <l> with IFNOTxxx <L> GOTO_W <l> L:..., where
// IFNOTxxx is the "opposite" opcode of IFxxx (e.g. IFNE for IFEQ) and where <L> designates
// the instruction just after the GOTO_W.
if (baseOpcode == Opcodes.GOTO) {
code.putByte(Constants.GOTO_W);
} else if (baseOpcode == Opcodes.JSR) {
code.putByte(Constants.JSR_W);
} else {
// Put the "opposite" opcode of baseOpcode. This can be done by flipping the least
// significant bit for IFNULL and IFNONNULL, and similarly for IFEQ ... IF_ACMPEQ (with a
// pre and post offset by 1). The jump offset is 8 bytes (3 for IFNOTxxx, 5 for GOTO_W).
code.putByte(baseOpcode >= Opcodes.IFNULL ? baseOpcode ^ 1 : ((baseOpcode + 1) ^ 1) - 1);
code.putShort(8);
// Here we could put a GOTO_W in theory, but if ASM specific instructions are used in this
// method or another one, and if the class has frames, we will need to insert a frame after
// this GOTO_W during the additional ClassReader -> ClassWriter round trip to remove the ASM
// specific instructions. To not miss this additional frame, we need to use an ASM_GOTO_W
// here, which has the unfortunate effect of forcing this additional round trip (which in
// some case would not have been really necessary, but we can't know this at this point).
code.putByte(Constants.ASM_GOTO_W);
hasAsmInstructions = true;
// The instruction after the GOTO_W becomes the target of the IFNOT instruction.
nextInsnIsJumpTarget = true;
}
label.put(code, code.length - 1, true);
} else if (baseOpcode != opcode) { } else if (baseOpcode != opcode) {
// Case of a GOTO_W or JSR_W specified by the user (normally ClassReader when used to remove // Case of a GOTO_W or JSR_W specified by the user (normally ClassReader when used to remove
// ASM specific instructions). In this case we keep the original instruction. // ASM specific instructions). In this case we keep the original instruction.
@ -670,9 +594,6 @@ public final class MethodWriter {
// If the next instruction starts a new basic block, call visitLabel to add the label of this // If the next instruction starts a new basic block, call visitLabel to add the label of this
// instruction as a successor of the current block, and to start a new basic block. // instruction as a successor of the current block, and to start a new basic block.
if (nextBasicBlock != null) { if (nextBasicBlock != null) {
if (nextInsnIsJumpTarget) {
nextBasicBlock.flags |= Label.FLAG_JUMP_TARGET;
}
visitLabel(nextBasicBlock); visitLabel(nextBasicBlock);
} }
if (baseOpcode == Opcodes.GOTO) { if (baseOpcode == Opcodes.GOTO) {

View File

@ -91,7 +91,6 @@ public interface Opcodes {
int DSTORE = 57; // - int DSTORE = 57; // -
int ASTORE = 58; // - int ASTORE = 58; // -
int IASTORE = 79; // visitInsn int IASTORE = 79; // visitInsn
int AASTORE = 83; // -
int BASTORE = 84; // - int BASTORE = 84; // -
int CASTORE = 85; // - int CASTORE = 85; // -
int POP = 87; // visitInsn int POP = 87; // visitInsn
@ -127,8 +126,6 @@ public interface Opcodes {
int LXOR = 131; // - int LXOR = 131; // -
int IINC = 132; // visitIincInsn int IINC = 132; // visitIincInsn
int I2L = 133; // visitInsn int I2L = 133; // visitInsn
int I2F = 134; // -
int I2D = 135; // -
int L2I = 136; // int L2I = 136; //
int F2I = 139; // - int F2I = 139; // -
int F2L = 140; // - int F2L = 140; // -
@ -157,7 +154,6 @@ public interface Opcodes {
int IF_ACMPEQ = 165; // - int IF_ACMPEQ = 165; // -
int IF_ACMPNE = 166; // - int IF_ACMPNE = 166; // -
int GOTO = 167; // - int GOTO = 167; // -
int JSR = 168; // -
int RET = 169; // visitVarInsn int RET = 169; // visitVarInsn
int TABLESWITCH = 170; // visiTableSwitchInsn int TABLESWITCH = 170; // visiTableSwitchInsn
int LOOKUPSWITCH = 171; // visitLookupSwitch int LOOKUPSWITCH = 171; // visitLookupSwitch
@ -176,8 +172,6 @@ public interface Opcodes {
int INVOKESTATIC = 184; // - int INVOKESTATIC = 184; // -
int INVOKEINTERFACE = 185; // - int INVOKEINTERFACE = 185; // -
int NEW = 187; // visitTypeInsn int NEW = 187; // visitTypeInsn
int NEWARRAY = 188; // -
int ANEWARRAY = 189; // -
int ARRAYLENGTH = 190; // visitInsn int ARRAYLENGTH = 190; // visitInsn
int ATHROW = 191; // - int ATHROW = 191; // -
int CHECKCAST = 192; // visitTypeInsn int CHECKCAST = 192; // visitTypeInsn

View File

@ -70,10 +70,8 @@ public abstract class FieldReader<T>
this.fieldName = fieldName; this.fieldName = fieldName;
this.fieldType = fieldType; this.fieldType = fieldType;
this.fieldClass = fieldClass; this.fieldClass = fieldClass;
this.fieldClassSerializable = fieldClass != null this.fieldClassSerializable = fieldClass != null && (Serializable.class.isAssignableFrom(fieldClass)
&& (Serializable.class.isAssignableFrom(fieldClass) || Modifier.isInterface(fieldClass.getModifiers()));
|| Modifier.isInterface(fieldClass.getModifiers())
|| BeanUtils.isRecord(fieldClass));
this.features = features; this.features = features;
this.fieldNameHash = Fnv.hashCode64(fieldName); this.fieldNameHash = Fnv.hashCode64(fieldName);
this.fieldNameHashLCase = Fnv.hashCode64LCase(fieldName); this.fieldNameHashLCase = Fnv.hashCode64LCase(fieldName);

View File

@ -1,37 +0,0 @@
package com.alibaba.fastjson2.reader;
import com.alibaba.fastjson2.schema.JSONSchema;
import com.alibaba.fastjson2.util.Fnv;
import java.lang.reflect.Parameter;
import java.lang.reflect.Type;
import java.util.Locale;
public class FieldReaderListParam
extends FieldReaderList {
final Parameter parameter;
final String paramName;
final long paramNameHash;
public FieldReaderListParam(
String fieldName,
Type fieldType,
String paramName,
Parameter parameter,
Class fieldClass,
Type itemType,
Class itemClass,
int ordinal,
long features,
String format,
Locale locale,
Object defaultValue,
JSONSchema schema
) {
super(fieldName, fieldType, fieldClass, itemType, itemClass, ordinal, features, format, locale, defaultValue, schema, null, null, null);
this.paramName = paramName;
this.paramNameHash = Fnv.hashCode64(paramName);
this.parameter = parameter;
}
}

View File

@ -254,10 +254,6 @@ public class ObjectReaderAdapter<T>
@Override @Override
public T readArrayMappingObject(JSONReader jsonReader, Type fieldType, Object fieldName, long features) { public T readArrayMappingObject(JSONReader jsonReader, Type fieldType, Object fieldName, long features) {
if (jsonReader.jsonb) {
return readArrayMappingJSONBObject(jsonReader, fieldType, fieldName, features);
}
if (!serializable) { if (!serializable) {
jsonReader.errorOnNoneSerializable(objectClass); jsonReader.errorOnNoneSerializable(objectClass);
} }
@ -445,21 +441,6 @@ public class ObjectReaderAdapter<T>
return fieldReader; return fieldReader;
} }
protected final void readFieldValue(long hashCode, JSONReader jsonReader, long features, Map<Long, Object> map) {
FieldReader fieldReader = getFieldReader(hashCode);
if (fieldReader == null
&& jsonReader.isSupportSmartMatch(this.features | features)) {
long hashCodeL = jsonReader.getNameHashCodeLCase();
fieldReader = getFieldReaderLCase(hashCodeL);
}
if (fieldReader != null) {
map.put(hashCode, fieldReader.readFieldValue(jsonReader));
} else {
jsonReader.skipValue();
}
}
protected final void readFieldValue(long hashCode, JSONReader jsonReader, long features, Object object) { protected final void readFieldValue(long hashCode, JSONReader jsonReader, long features, Object object) {
FieldReader fieldReader = getFieldReader(hashCode); FieldReader fieldReader = getFieldReader(hashCode);
if (fieldReader == null if (fieldReader == null

View File

@ -10,7 +10,6 @@ import com.alibaba.fastjson2.util.TypeUtils;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -97,26 +96,6 @@ public abstract class ObjectReaderBean<T>
processExtra(jsonReader, object, 0); processExtra(jsonReader, object, 0);
} }
protected void processExtra(JSONReader jsonReader, Map<Long, Object> map, long features) {
if ((jsonReader.features(this.features | features) & JSONReader.Feature.SupportSmartMatch.mask) != 0) {
String fieldName = jsonReader.getFieldName();
if (fieldName.startsWith("is")) {
String fieldName1 = fieldName.substring(2);
long hashCode64LCase = Fnv.hashCode64LCase(fieldName1);
FieldReader fieldReader = getFieldReaderLCase(hashCode64LCase);
if (fieldReader != null) {
Class fieldClass = fieldReader.fieldClass;
if (fieldClass == Boolean.class || fieldClass == boolean.class) {
map.put(fieldReader.fieldNameHash, fieldReader.readFieldValue(jsonReader));
return;
}
}
}
}
jsonReader.skipValue();
}
protected void processExtra(JSONReader jsonReader, Object object, long features) { protected void processExtra(JSONReader jsonReader, Object object, long features) {
if ((jsonReader.features(this.features | features) & JSONReader.Feature.SupportSmartMatch.mask) != 0) { if ((jsonReader.features(this.features | features) & JSONReader.Feature.SupportSmartMatch.mask) != 0) {
String fieldName = jsonReader.getFieldName(); String fieldName = jsonReader.getFieldName();

View File

@ -184,7 +184,7 @@ public class ObjectReaderCreator {
declaringClass = owner.getDeclaringClass(); declaringClass = owner.getDeclaringClass();
} }
List<FieldReader> fieldReaders = new ArrayList<>(parameters.length); FieldReader[] fieldReaders = new FieldReader[parameters.length];
for (int i = 0; i < parameters.length; i++) { for (int i = 0; i < parameters.length; i++) {
FieldInfo fieldInfo = new FieldInfo(); FieldInfo fieldInfo = new FieldInfo();
@ -224,8 +224,7 @@ public class ObjectReaderCreator {
ObjectReader initReader = getInitReader(provider, parameter.getParameterizedType(), parameter.getType(), fieldInfo); ObjectReader initReader = getInitReader(provider, parameter.getParameterizedType(), parameter.getType(), fieldInfo);
Type paramType = parameter.getParameterizedType(); Type paramType = parameter.getParameterizedType();
fieldReaders.add( fieldReaders[i] = createFieldReaderParam(
createFieldReaderParam(
null, null,
null, null,
fieldName, fieldName,
@ -240,34 +239,10 @@ public class ObjectReaderCreator {
declaringClass, declaringClass,
parameter, parameter,
null, null,
initReader)); initReader
);
if (fieldInfo.alternateNames != null) {
for (String alternateName : fieldInfo.alternateNames) {
if (fieldName.equals(alternateName)) {
continue;
} }
return fieldReaders;
fieldReaders.add(createFieldReaderParam(
null,
null,
alternateName,
i,
fieldInfo.features,
fieldInfo.format,
fieldInfo.locale,
fieldInfo.defaultValue,
paramType,
parameter.getType(),
paramName,
declaringClass,
parameter,
null,
initReader));
}
}
}
return fieldReaders.toArray(new FieldReader[0]);
} }
public <T> Function<Map<Long, Object>, T> createFactoryFunction(Method factoryMethod, String... paramNames) { public <T> Function<Map<Long, Object>, T> createFactoryFunction(Method factoryMethod, String... paramNames) {
@ -1185,13 +1160,6 @@ public class ObjectReaderCreator {
if (creatorConstructor.getParameterCount() == 1) { if (creatorConstructor.getParameterCount() == 1) {
FieldInfo fieldInfo = new FieldInfo(); FieldInfo fieldInfo = new FieldInfo();
provider.getFieldInfo(fieldInfo, objectClass, creatorConstructor, 0, creatorConstructor.getParameters()[0]); provider.getFieldInfo(fieldInfo, objectClass, creatorConstructor, 0, creatorConstructor.getParameters()[0]);
if (record) {
Field field = getField(objectClass, fieldInfo.fieldName);
if (field != null) {
provider.getFieldInfo(fieldInfo, objectClass, field);
}
}
if ((fieldInfo.features & FieldInfo.VALUE_MASK) != 0) { if ((fieldInfo.features & FieldInfo.VALUE_MASK) != 0) {
Type valueType = creatorConstructor.getGenericParameterTypes()[0]; Type valueType = creatorConstructor.getGenericParameterTypes()[0];
Class valueClass = creatorConstructor.getParameterTypes()[0]; Class valueClass = creatorConstructor.getParameterTypes()[0];
@ -1273,14 +1241,18 @@ public class ObjectReaderCreator {
creatorConstructor.getParameters(), creatorConstructor.getParameters(),
parameterNames parameterNames
); );
return createNoneDefaultConstructorObjectReader( return new ObjectReaderNoneDefaultConstructor(
objectClass, objectClass,
beanInfo, beanInfo.typeKey,
beanInfo.typeName,
beanInfo.readerFeatures,
constructorFunction, constructorFunction,
alternateConstructors, alternateConstructors,
parameterNames, parameterNames,
paramFieldReaders, paramFieldReaders,
fieldReaderArray fieldReaderArray,
null,
null
); );
} }
} }
@ -1340,30 +1312,6 @@ public class ObjectReaderCreator {
return objectReader; return objectReader;
} }
protected <T> ObjectReaderNoneDefaultConstructor createNoneDefaultConstructorObjectReader(
Class<T> objectClass,
BeanInfo beanInfo,
Function<Map<Long, Object>, T> constructorFunction,
List<Constructor> alternateConstructors,
String[] parameterNames,
FieldReader[] paramFieldReaders,
FieldReader[] fieldReaderArray
) {
return new ObjectReaderNoneDefaultConstructor(
objectClass,
beanInfo.typeKey,
beanInfo.typeName,
beanInfo.readerFeatures,
constructorFunction,
alternateConstructors,
parameterNames,
paramFieldReaders,
fieldReaderArray,
null,
null
);
}
public <T> FieldReader[] createFieldReaders(Class<T> objectClass) { public <T> FieldReader[] createFieldReaders(Class<T> objectClass) {
return createFieldReaders( return createFieldReaders(
objectClass, objectClass,
@ -2219,33 +2167,6 @@ public class ObjectReaderCreator {
fieldClassResolved = fieldClass; fieldClassResolved = fieldClass;
} }
Type itemType = null;
Class itemClass = null;
if (fieldTypeResolved instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) fieldTypeResolved;
Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
if (actualTypeArguments.length == 1) {
itemType = actualTypeArguments[0];
itemClass = TypeUtils.getClass(itemClass);
}
}
if (fieldClassResolved != null && Collection.class.isAssignableFrom(fieldClassResolved) && itemType != null) {
return new FieldReaderListParam(
fieldName,
fieldTypeResolved,
paramName,
parameter,
fieldClassResolved,
itemType,
itemClass,
ordinal,
features,
format,
locale,
defaultValue,
schema);
}
return new FieldReaderObjectParam( return new FieldReaderObjectParam(
fieldName, fieldName,
fieldTypeResolved, fieldTypeResolved,

View File

@ -150,8 +150,6 @@ public final class ObjectReaderImplList
break; break;
case "com.google.common.collect.Lists$TransformingRandomAccessList": case "com.google.common.collect.Lists$TransformingRandomAccessList":
case "java.util.RandomAccessSubList": case "java.util.RandomAccessSubList":
case "java.util.SubList":
case "java.util.AbstractList$SubList":
case "java.util.AbstractList$RandomAccessSubList": case "java.util.AbstractList$RandomAccessSubList":
instanceClass = ArrayList.class; instanceClass = ArrayList.class;
break; break;

View File

@ -1,6 +1,9 @@
package com.alibaba.fastjson2.reader; package com.alibaba.fastjson2.reader;
import com.alibaba.fastjson2.*; import com.alibaba.fastjson2.JSONB;
import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.util.TypeUtils; import com.alibaba.fastjson2.util.TypeUtils;
import java.lang.reflect.Type; import java.lang.reflect.Type;
@ -232,19 +235,6 @@ public final class ObjectReaderInterface<T>
} else { } else {
object = new JSONObject(map); object = new JSONObject(map);
} }
for (FieldReader fieldReader : fieldReaders) {
Object fieldValue = object.get(fieldReader.fieldName);
if (fieldValue instanceof Map) {
ObjectReader objectReader = fieldReader.getObjectReader(JSONFactory.getDefaultObjectReaderProvider());
if (objectReader instanceof ObjectReaderAdapter) {
if (object == map) {
object = new JSONObject(map);
}
Object fieldValue1 = objectReader.createInstance((Map) fieldValue, features);
object.put(fieldReader.fieldName, fieldValue1);
}
}
}
return (T) TypeUtils.newProxyInstance(objectClass, object); return (T) TypeUtils.newProxyInstance(objectClass, object);
} }
} }

View File

@ -5,7 +5,6 @@ import com.alibaba.fastjson2.util.Fnv;
import com.alibaba.fastjson2.util.TypeUtils; import com.alibaba.fastjson2.util.TypeUtils;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
@ -17,9 +16,8 @@ public class ObjectReaderNoneDefaultConstructor<T>
extends ObjectReaderAdapter<T> { extends ObjectReaderAdapter<T> {
final String[] paramNames; final String[] paramNames;
final FieldReader[] setterFieldReaders; final FieldReader[] setterFieldReaders;
final Function<Map<Long, Object>, T> creatorFunction; private final Function<Map<Long, Object>, T> creator;
final Map<Long, FieldReader> paramFieldReaderMap; final Map<Long, FieldReader> paramFieldReaderMap;
final Constructor noneDefaultConstructor;
public ObjectReaderNoneDefaultConstructor( public ObjectReaderNoneDefaultConstructor(
Class objectClass, Class objectClass,
@ -49,17 +47,12 @@ public class ObjectReaderNoneDefaultConstructor<T>
); );
this.paramNames = paramNames; this.paramNames = paramNames;
this.creatorFunction = creator; this.creator = creator;
this.setterFieldReaders = setterFieldReaders; this.setterFieldReaders = setterFieldReaders;
this.paramFieldReaderMap = new HashMap<>(); this.paramFieldReaderMap = new HashMap<>();
for (FieldReader paramFieldReader : paramFieldReaders) { for (FieldReader paramFieldReader : paramFieldReaders) {
paramFieldReaderMap.put(paramFieldReader.fieldNameHash, paramFieldReader); paramFieldReaderMap.put(paramFieldReader.fieldNameHash, paramFieldReader);
} }
if (creatorFunction instanceof ConstructorFunction) {
noneDefaultConstructor = ((ConstructorFunction) creator).constructor;
} else {
noneDefaultConstructor = null;
}
} }
static FieldReader[] concat(FieldReader[] a, FieldReader[] b) { static FieldReader[] concat(FieldReader[] a, FieldReader[] b) {
@ -72,14 +65,9 @@ public class ObjectReaderNoneDefaultConstructor<T>
return a; return a;
} }
@SuppressWarnings("rawtypes")
public Collection<FieldReader> getParameterFieldReaders() {
return paramFieldReaderMap.values();
}
@Override @Override
public T createInstanceNoneDefaultConstructor(Map<Long, Object> values) { public T createInstanceNoneDefaultConstructor(Map<Long, Object> values) {
return creatorFunction.apply(values); return creator.apply(values);
} }
@Override @Override
@ -354,7 +342,7 @@ public class ObjectReaderNoneDefaultConstructor<T>
} }
Map<Long, Object> argsMap = valueMap == null ? Collections.emptyMap() : valueMap; Map<Long, Object> argsMap = valueMap == null ? Collections.emptyMap() : valueMap;
T object = creatorFunction.apply(argsMap); T object = creator.apply(argsMap);
if (setterFieldReaders != null && valueMap != null) { if (setterFieldReaders != null && valueMap != null) {
for (int i = 0; i < setterFieldReaders.length; i++) { for (int i = 0; i < setterFieldReaders.length; i++) {
@ -533,13 +521,4 @@ public class ObjectReaderNoneDefaultConstructor<T>
return object; return object;
} }
public T createInstance(Object[] args) {
try {
return (T) noneDefaultConstructor.newInstance(args);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException |
InvocationTargetException e) {
throw new JSONException("invoke constructor error, " + constructor, e);
}
}
} }

View File

@ -1333,16 +1333,6 @@ public abstract class BeanUtils {
return fieldName; return fieldName;
} }
public static Field getField(Class objectClass, String fieldName) {
Field[] fields = new Field[1];
declaredFields(objectClass, field -> {
if (field.getName().equals(fieldName)) {
fields[0] = field;
}
});
return fields[0];
}
public static Field getField(Class objectClass, Method method) { public static Field getField(Class objectClass, Method method) {
String methodName = method.getName(); String methodName = method.getName();
final int len = methodName.length(); final int len = methodName.length();

View File

@ -9008,18 +9008,6 @@ public class DateUtils {
return v; return v;
} }
public static ZoneOffset zoneOffset(byte[] bytes, int start, int len) {
return ZoneOffset.of(new String(bytes, start, len));
}
public static ZoneOffset zoneOffset(char[] bytes, int start, int len) {
return ZoneOffset.of(new String(bytes, start, len));
}
public static int nanos(int value, int nanoSize) {
return value * POWERS[(9 - nanoSize) & 0xF];
}
private static final int[] POWERS = { private static final int[] POWERS = {
1, 1,
10, 10,
@ -9040,10 +9028,7 @@ public class DateUtils {
}; };
public static long hms(byte[] bytes, int off) { public static long hms(byte[] bytes, int off) {
long v = UNSAFE.getLong(bytes, ARRAY_BYTE_BASE_OFFSET + off); long v = getLongLE(bytes, off);
if (BIG_ENDIAN) {
v = Long.reverseBytes(v);
}
long d; long d;
if ((((v & 0xF0F0F0F0_F0F0F0F0L) - 0x30303030_30303030L) | (((d = v & 0x0F0F0F0F_0F0F0F0FL) + 0x06060006_06000606L) & 0xF0F000F0_F000F0F0L)) != 0 if ((((v & 0xF0F0F0F0_F0F0F0F0L) - 0x30303030_30303030L) | (((d = v & 0x0F0F0F0F_0F0F0F0FL) + 0x06060006_06000606L) & 0xF0F000F0_F000F0F0L)) != 0
|| (d & 0x00000F00_000F0000L) != 0x00000a00_000a0000L) { // 00:00:00 || (d & 0x00000F00_000F0000L) != 0x00000a00_000a0000L) { // 00:00:00
@ -9053,10 +9038,7 @@ public class DateUtils {
} }
public static long ymd(byte[] bytes, int off) { public static long ymd(byte[] bytes, int off) {
long v = UNSAFE.getLong(bytes, ARRAY_BYTE_BASE_OFFSET + off); long v = getLongLE(bytes, off);
if (BIG_ENDIAN) {
v = Long.reverseBytes(v);
}
long d; long d;
if (((v & 0x0000FF00_00FF0000L) != 0x00002d00_002d0000L) // yy-mm-dd if (((v & 0x0000FF00_00FF0000L) != 0x00002d00_002d0000L) // yy-mm-dd
|| (((v & 0xF0F000F0_F000F0F0L) - 0x30300030_30003030L) | (((d = v & 0x0F0F000F_0F000F0FL) + 0x06060006_06000606L) & 0xF0F000F0_F000F0F0L)) != 0) { || (((v & 0xF0F000F0_F000F0F0L) - 0x30300030_30003030L) | (((d = v & 0x0F0F000F_0F000F0FL) + 0x06060006_06000606L) & 0xF0F000F0_F000F0F0L)) != 0) {
@ -9066,10 +9048,7 @@ public class DateUtils {
} }
public static int yy(byte[] bytes, int off) { public static int yy(byte[] bytes, int off) {
short x = UNSAFE.getShort(bytes, ARRAY_BYTE_BASE_OFFSET + off); int x = getShortLE(bytes, off);
if (BIG_ENDIAN) {
x = Short.reverseBytes(x);
}
int d; int d;
if ((((x & 0xF0F0) - 0x3030) | (((d = x & 0x0F0F) + 0x0606) & 0xF0F0)) != 0 if ((((x & 0xF0F0) - 0x3030) | (((d = x & 0x0F0F) + 0x0606) & 0xF0F0)) != 0
) { ) {

View File

@ -909,19 +909,11 @@ public class IOUtils {
} }
private static int mergeInt32(int v1, int v2) { private static int mergeInt32(int v1, int v2) {
int v = PACKED_DIGITS[v2 & 0x7f] | (PACKED_DIGITS[v1 & 0x7f] << 16); return convEndian(false, PACKED_DIGITS[v2 & 0x7f] | (PACKED_DIGITS[v1 & 0x7f] << 16));
if (BIG_ENDIAN) {
v = Integer.reverseBytes(v);
}
return v;
} }
private static long mergeInt64(int v1, int v2) { private static long mergeInt64(int v1, int v2) {
long v = PACKED_DIGITS_UTF16[v2 & 0x7f] | ((long) PACKED_DIGITS_UTF16[v1 & 0x7f] << 32); return convEndian(false, PACKED_DIGITS_UTF16[v2 & 0x7f] | ((long) PACKED_DIGITS_UTF16[v1 & 0x7f] << 32));
if (BIG_ENDIAN) {
v = Long.reverseBytes(v);
}
return v;
} }
private static int writeInt3(byte[] buf, int off, int val) { private static int writeInt3(byte[] buf, int off, int val) {
@ -1276,24 +1268,15 @@ public class IOUtils {
} }
public static void putIntBE(byte[] buf, int pos, int v) { public static void putIntBE(byte[] buf, int pos, int v) {
if (!BIG_ENDIAN) { UNSAFE.putInt(buf, ARRAY_BYTE_BASE_OFFSET + pos, convEndian(true, v));
v = Integer.reverseBytes(v);
}
UNSAFE.putInt(buf, ARRAY_BYTE_BASE_OFFSET + pos, v);
} }
public static void putIntLE(byte[] buf, int pos, int v) { public static void putIntLE(byte[] buf, int pos, int v) {
if (BIG_ENDIAN) { UNSAFE.putInt(buf, ARRAY_BYTE_BASE_OFFSET + pos, convEndian(false, v));
v = Integer.reverseBytes(v);
}
UNSAFE.putInt(buf, ARRAY_BYTE_BASE_OFFSET + pos, v);
} }
public static void putIntLE(char[] buf, int pos, int v) { public static void putIntLE(char[] buf, int pos, int v) {
if (BIG_ENDIAN) { UNSAFE.putInt(buf, ARRAY_CHAR_BASE_OFFSET + ((long) pos << 1), convEndian(false, v));
v = Integer.reverseBytes(v);
}
UNSAFE.putInt(buf, ARRAY_CHAR_BASE_OFFSET + ((long) pos << 1), v);
} }
public static void putShortUnaligned(byte[] buf, int pos, short v) { public static void putShortUnaligned(byte[] buf, int pos, short v) {
@ -1356,50 +1339,18 @@ public class IOUtils {
return UNSAFE.getInt(buf, ARRAY_BYTE_BASE_OFFSET + pos) == ALSE; return UNSAFE.getInt(buf, ARRAY_BYTE_BASE_OFFSET + pos) == ALSE;
} }
public static boolean notALSE(byte[] buf, int pos) {
return UNSAFE.getInt(buf, ARRAY_BYTE_BASE_OFFSET + pos) != ALSE;
}
public static boolean isALSE(char[] buf, int pos) { public static boolean isALSE(char[] buf, int pos) {
return getLongUnaligned(buf, pos) == ALSE_64; return getLongUnaligned(buf, pos) == ALSE_64;
} }
public static boolean notALSE(char[] buf, int pos) {
return getLongUnaligned(buf, pos) != ALSE_64;
}
public static boolean isNULL(byte[] buf, int pos) { public static boolean isNULL(byte[] buf, int pos) {
return UNSAFE.getInt(buf, ARRAY_BYTE_BASE_OFFSET + pos) == NULL_32; return UNSAFE.getInt(buf, ARRAY_BYTE_BASE_OFFSET + pos) == NULL_32;
} }
public static boolean notNULL(byte[] buf, int pos) {
return UNSAFE.getInt(buf, ARRAY_BYTE_BASE_OFFSET + pos) != NULL_32;
}
public static boolean isTRUE(byte[] buf, int pos) {
return UNSAFE.getInt(buf, ARRAY_BYTE_BASE_OFFSET + pos) == TRUE;
}
public static boolean notTRUE(byte[] buf, int pos) {
return UNSAFE.getInt(buf, ARRAY_BYTE_BASE_OFFSET + pos) != TRUE;
}
public static boolean isTRUE(char[] buf, int pos) {
return UNSAFE.getLong(buf, ARRAY_BYTE_BASE_OFFSET + ((long) pos << 1)) == TRUE_64;
}
public static boolean notTRUE(char[] buf, int pos) {
return UNSAFE.getLong(buf, ARRAY_BYTE_BASE_OFFSET + ((long) pos << 1)) != TRUE_64;
}
public static boolean isNULL(char[] buf, int pos) { public static boolean isNULL(char[] buf, int pos) {
return getLongUnaligned(buf, pos) == NULL_64; return getLongUnaligned(buf, pos) == NULL_64;
} }
public static boolean notNULL(char[] buf, int pos) {
return getLongUnaligned(buf, pos) != NULL_64;
}
public static void putNULL(byte[] buf, int pos) { public static void putNULL(byte[] buf, int pos) {
UNSAFE.putInt(buf, ARRAY_CHAR_BASE_OFFSET + pos, NULL_32); UNSAFE.putInt(buf, ARRAY_CHAR_BASE_OFFSET + pos, NULL_32);
} }
@ -1514,22 +1465,6 @@ public class IOUtils {
return (d & 0xF) * 10 + (d >> 8); return (d & 0xF) * 10 + (d >> 8);
} }
public static boolean isDigit2(byte[] bytes, int off) {
short x = UNSAFE.getShort(bytes, ARRAY_BYTE_BASE_OFFSET + off);
if (BIG_ENDIAN) {
x = Short.reverseBytes(x);
}
return (((x & 0xF0F0) - 0x3030) | (((x & 0x0F0F) + 0x0606) & 0xF0F0)) == 0;
}
public static boolean isDigit2(char[] bytes, int off) {
int x = UNSAFE.getShort(bytes, ARRAY_BYTE_BASE_OFFSET + ((long) off << 1));
if (BIG_ENDIAN) {
x = Integer.reverseBytes(x);
}
return ((((x & 0xFFF0FFF0) - 0x300030) | (((x & 0x0F000F) + 0x060006) & 0xF000F0)) == 0);
}
public static int digit(int d) { public static int digit(int d) {
return d >= 0 && d <= 9 ? d : -1; return d >= 0 && d <= 9 ? d : -1;
} }
@ -1564,7 +1499,7 @@ public class IOUtils {
i += 8; i += 8;
address += 8; address += 8;
} }
return indexOfChar(value, quote, i, max); return indexOfChar0(value, quote, i, max);
} }
public static int indexOfDoubleQuote(byte[] value, int fromIndex, int max) { public static int indexOfDoubleQuote(byte[] value, int fromIndex, int max) {
@ -1586,7 +1521,7 @@ public class IOUtils {
i += 8; i += 8;
address += 8; address += 8;
} }
return indexOfChar(value, '"', i, max); return indexOfChar0(value, '"', i, max);
} }
public static int indexOfLineSeparator(byte[] value, int fromIndex, int max) { public static int indexOfLineSeparator(byte[] value, int fromIndex, int max) {
@ -1608,7 +1543,7 @@ public class IOUtils {
i += 8; i += 8;
address += 8; address += 8;
} }
return indexOfChar(value, '\n', i, max); return indexOfChar0(value, '\n', i, max);
} }
public static int indexOfSlash(byte[] value, int fromIndex, int max) { public static int indexOfSlash(byte[] value, int fromIndex, int max) {
@ -1630,19 +1565,10 @@ public class IOUtils {
i += 8; i += 8;
address += 8; address += 8;
} }
return indexOfChar(value, '\\', i, max); return indexOfChar0(value, '\\', i, max);
} }
public static int indexOfChar(byte[] value, int ch, int fromIndex, int max) { private static int indexOfChar0(byte[] value, int ch, int fromIndex, int max) {
for (int i = fromIndex; i < max; i++) {
if (value[i] == ch) {
return i;
}
}
return -1;
}
public static int indexOfChar(char[] value, int ch, int fromIndex, int max) {
for (int i = fromIndex; i < max; i++) { for (int i = fromIndex; i < max; i++) {
if (value[i] == ch) { if (value[i] == ch) {
return i; return i;
@ -1702,27 +1628,18 @@ public class IOUtils {
} }
public static int getIntBE(byte[] bytes, int offset) { public static int getIntBE(byte[] bytes, int offset) {
int v = UNSAFE.getInt(bytes, ARRAY_BYTE_BASE_OFFSET + offset); return convEndian(true,
if (!BIG_ENDIAN) { UNSAFE.getInt(bytes, ARRAY_BYTE_BASE_OFFSET + offset));
v = Integer.reverseBytes(v);
}
return v;
} }
public static int getIntLE(byte[] bytes, int offset) { public static int getIntLE(byte[] bytes, int offset) {
int v = UNSAFE.getInt(bytes, ARRAY_BYTE_BASE_OFFSET + offset); return convEndian(false,
if (BIG_ENDIAN) { UNSAFE.getInt(bytes, ARRAY_BYTE_BASE_OFFSET + offset));
v = Integer.reverseBytes(v);
}
return v;
} }
public static int getIntLE(char[] bytes, int offset) { public static int getIntLE(char[] bytes, int offset) {
int v = UNSAFE.getInt(bytes, ARRAY_CHAR_BASE_OFFSET + ((long) offset << 1)); return convEndian(false,
if (BIG_ENDIAN) { UNSAFE.getInt(bytes, ARRAY_CHAR_BASE_OFFSET + ((long) offset << 1)));
v = Integer.reverseBytes(v);
}
return v;
} }
public static int getIntUnaligned(byte[] bytes, int offset) { public static int getIntUnaligned(byte[] bytes, int offset) {
@ -1734,11 +1651,8 @@ public class IOUtils {
} }
public static long getLongBE(byte[] bytes, int offset) { public static long getLongBE(byte[] bytes, int offset) {
long v = UNSAFE.getLong(bytes, ARRAY_BYTE_BASE_OFFSET + offset); return convEndian(true,
if (!BIG_ENDIAN) { UNSAFE.getLong(bytes, ARRAY_BYTE_BASE_OFFSET + offset));
v = Long.reverseBytes(v);
}
return v;
} }
public static long getLongUnaligned(byte[] bytes, int offset) { public static long getLongUnaligned(byte[] bytes, int offset) {
@ -1755,11 +1669,8 @@ public class IOUtils {
} }
public static long getLongLE(char[] bytes, int offset) { public static long getLongLE(char[] bytes, int offset) {
long v = UNSAFE.getLong(bytes, ARRAY_CHAR_BASE_OFFSET + ((long) offset << 1)); return convEndian(false,
if (BIG_ENDIAN) { UNSAFE.getLong(bytes, ARRAY_CHAR_BASE_OFFSET + ((long) offset << 1)));
v = Long.reverseBytes(v);
}
return v;
} }
public static short hex2(int i) { public static short hex2(int i) {
@ -1844,7 +1755,7 @@ public class IOUtils {
return ((i & 0xF000L) >> 12) | ((i & 0xF00L) << 8) | ((i & 0xF0L) << 28) | ((i & 0xFL) << 48); return ((i & 0xF000L) >> 12) | ((i & 0xF00L) << 8) | ((i & 0xF0L) << 28) | ((i & 0xFL) << 48);
} }
public static int convEndian(boolean big, int n) { static int convEndian(boolean big, int n) {
return big == BIG_ENDIAN ? n : Integer.reverseBytes(n); return big == BIG_ENDIAN ? n : Integer.reverseBytes(n);
} }

View File

@ -675,16 +675,6 @@ public class ObjectWriterAdapter<T>
if (fieldValue == object) { if (fieldValue == object) {
fieldValue = jsonObject; fieldValue = jsonObject;
} }
if (fieldWriter instanceof FieldWriterObject && !(fieldValue instanceof Map)) {
ObjectWriter valueWriter = fieldWriter.getInitWriter();
if (valueWriter == null) {
valueWriter = JSONFactory.getObjectWriter(fieldWriter.fieldType, this.features | features);
}
if (valueWriter instanceof ObjectWriterAdapter) {
ObjectWriterAdapter objectWriterAdapter = (ObjectWriterAdapter) valueWriter;
fieldValue = objectWriterAdapter.toJSONObject(fieldValue);
}
}
jsonObject.put(fieldWriter.fieldName, fieldValue); jsonObject.put(fieldWriter.fieldName, fieldValue);
} }

View File

@ -878,7 +878,10 @@ public class ObjectWriterCreatorASM
if (group.start) { if (group.start) {
// bytes[off++] = BC_OBJECT; // bytes[off++] = BC_OBJECT;
gwWriteByte(mw, BYTES, OFFSET, BC_OBJECT); mw.aload(BYTES);
mw.iload(OFFSET);
mw.visitLdcInsn(BC_OBJECT);
mw.bastore();
mw.visitIincInsn(OFFSET, 1); mw.visitIincInsn(OFFSET, 1);
} }
for (FieldWriterRecord item : group.fieldWriters) { for (FieldWriterRecord item : group.fieldWriters) {
@ -899,7 +902,10 @@ public class ObjectWriterCreatorASM
} }
if (group.end) { if (group.end) {
gwWriteByte(mw, BYTES, OFFSET, BC_OBJECT_END); mw.aload(BYTES);
mw.iload(OFFSET);
mw.visitLdcInsn(BC_OBJECT_END);
mw.bastore();
} }
mw.aload(JSON_WRITER); mw.aload(JSON_WRITER);
@ -978,22 +984,155 @@ public class ObjectWriterCreatorASM
} }
byte[] name = fieldWriter.nameJSONB; byte[] name = fieldWriter.nameJSONB;
int i = 0; switch (name.length) {
for (; i + 8 <= name.length; i += 8) { case 3: {
gwWriteLong(mw, BYTES, OFFSET, name, i); /*
* IOUtils.putShortUnaligned(bytes, offset, IOUtils.getIntUnaligned(name, 0));
*/
int nameInt = IOUtils.getShortUnaligned(name, 0);
mw.aload(BYTES);
mw.iload(OFFSET);
mw.visitLdcInsn(nameInt);
mw.invokestatic(TYPE_IO_UTILS, "putShortUnaligned", "([BIS)V");
// bytes[offset + 2] = name[4];
mw.aload(BYTES);
mw.iload(OFFSET);
mw.visitLdcInsn(2);
mw.iadd();
mw.visitLdcInsn(name[2]);
mw.bastore();
/*
* offset += 3;
*/
mw.visitIincInsn(OFFSET, 3);
break;
} }
if (i + 4 <= name.length) { case 4: {
gwWriteInt(mw, BYTES, OFFSET, name, i); int nameInt = IOUtils.getIntUnaligned(name, 0);
i += 4; mw.aload(BYTES);
mw.iload(OFFSET);
mw.visitLdcInsn(nameInt);
mw.invokestatic(TYPE_IO_UTILS, "putIntUnaligned", "([BII)V");
/*
* offset += 4;
*/
mw.visitIincInsn(OFFSET, 4);
break;
} }
if (i + 2 <= name.length) { case 5: {
gwWriteShort(mw, BYTES, OFFSET, name, i); /*
i += 2; * IOUtils.putShortUnaligned(bytes, offset, IOUtils.getIntUnaligned(name, 0));
*/
int nameInt = IOUtils.getIntUnaligned(name, 0);
mw.aload(BYTES);
mw.iload(OFFSET);
mw.visitLdcInsn(nameInt);
mw.invokestatic(TYPE_IO_UTILS, "putIntUnaligned", "([BII)V");
// bytes[offset + 4] = name[4];
mw.aload(BYTES);
mw.iload(OFFSET);
mw.visitLdcInsn(4);
mw.iadd();
mw.visitLdcInsn(name[4]);
mw.bastore();
/*
* offset += 5;
*/
mw.visitIincInsn(OFFSET, 5);
break;
}
case 6: {
/*
* IOUtils.putShortUnaligned(bytes, offset, IOUtils.getIntUnaligned(name, 0));
*/
int nameInt = IOUtils.getIntUnaligned(name, 0);
mw.aload(BYTES);
mw.iload(OFFSET);
mw.visitLdcInsn(nameInt);
mw.invokestatic(TYPE_IO_UTILS, "putIntUnaligned", "([BII)V");
/*
* IOUtils.putShortUnaligned(bytes, offset + 4, IOUtils.getShortUnaligned(name, 4));
*/
short nameInt1 = IOUtils.getShortUnaligned(name, 4);
mw.aload(BYTES);
mw.iload(OFFSET);
mw.visitLdcInsn(4);
mw.iadd();
mw.visitLdcInsn(nameInt1);
mw.invokestatic(TYPE_IO_UTILS, "putShortUnaligned", "([BIS)V");
/*
* offset += 6;
*/
mw.visitIincInsn(OFFSET, 6);
break;
}
case 7: {
/*
* IOUtils.putShortUnaligned(bytes, offset, IOUtils.getIntUnaligned(name, 0));
*/
int nameInt = IOUtils.getIntUnaligned(name, 0);
mw.aload(BYTES);
mw.iload(OFFSET);
mw.visitLdcInsn(nameInt);
mw.invokestatic(TYPE_IO_UTILS, "putIntUnaligned", "([BII)V");
/*
* IOUtils.putShortUnaligned(bytes, offset + 4, IOUtils.getShortUnaligned(name, 4));
*/
short nameInt1 = IOUtils.getShortUnaligned(name, 4);
mw.aload(BYTES);
mw.iload(OFFSET);
mw.visitLdcInsn(4);
mw.iadd();
mw.visitLdcInsn(nameInt1);
mw.invokestatic(TYPE_IO_UTILS, "putShortUnaligned", "([BIS)V");
// bytes[offset + 6] = name[6];
mw.aload(BYTES);
mw.iload(OFFSET);
mw.visitLdcInsn(6);
mw.iadd();
mw.visitLdcInsn(name[6]);
mw.bastore();
/*
* offset += 7;
*/
mw.visitIincInsn(OFFSET, 7);
break;
}
case 8: {
long nameInt = IOUtils.getLongUnaligned(name, 0);
mw.aload(BYTES);
mw.iload(OFFSET);
mw.visitLdcInsn(nameInt);
mw.invokestatic(TYPE_IO_UTILS, "putLongUnaligned", "([BIJ)V");
/*
* offset += 4;
*/
mw.visitIincInsn(OFFSET, 8);
break;
}
default: {
/*
* offset = fieldWriterN.writeFieldNameJSONB(bytes, offset);
*/
mw.aload(THIS);
mw.getfield(classNameType, fieldWriter(ordinal), DESC_FIELD_WRITER);
mw.aload(BYTES);
mw.iload(OFFSET);
mw.invokevirtual(TYPE_FIELD_WRITER, "writeFieldNameJSONB", "([BI)I");
mw.istore(OFFSET);
} }
if (i + 1 <= name.length) {
gwWriteByte(mw, BYTES, OFFSET, name, i);
} }
mw.visitIincInsn(OFFSET, name.length);
mw.goto_(L_NAME_END); mw.goto_(L_NAME_END);
mw.visitLabel(L0); mw.visitLabel(L0);
@ -1011,60 +1150,6 @@ public class ObjectWriterCreatorASM
mw.visitLabel(L_NAME_END); mw.visitLabel(L_NAME_END);
} }
private static void gwWriteByte(MethodWriter mw, int BYTES, int OFFSET, byte value) {
mw.aload(BYTES);
mw.iload(OFFSET);
mw.iconst_n(value);
mw.bastore();
}
private static void gwWriteByte(MethodWriter mw, int BYTES, int OFFSET, byte[] name, int offset) {
mw.aload(BYTES);
mw.iload(OFFSET);
if (offset != 0) {
mw.iconst_n(offset);
mw.iadd();
}
mw.iconst_n(name[offset]);
mw.bastore();
}
private static void gwWriteShort(MethodWriter mw, int BYTES, int OFFSET, byte[] name, int offset) {
short nameInt = IOUtils.getShortUnaligned(name, offset);
mw.aload(BYTES);
mw.iload(OFFSET);
if (offset != 0) {
mw.iconst_n(offset);
mw.iadd();
}
mw.visitLdcInsn(nameInt);
mw.invokestatic(TYPE_IO_UTILS, "putShortUnaligned", "([BIS)V");
}
private static void gwWriteInt(MethodWriter mw, int BYTES, int OFFSET, byte[] name, int offset) {
int nameInt = IOUtils.getIntUnaligned(name, offset);
mw.aload(BYTES);
mw.iload(OFFSET);
if (offset != 0) {
mw.iconst_n(offset);
mw.iadd();
}
mw.visitLdcInsn(nameInt);
mw.invokestatic(TYPE_IO_UTILS, "putIntUnaligned", "([BII)V");
}
private static void gwWriteLong(MethodWriter mw, int BYTES, int OFFSET, byte[] name, int offset) {
long nameInt = IOUtils.getLongUnaligned(name, offset);
mw.aload(BYTES);
mw.iload(OFFSET);
if (offset != 0) {
mw.iconst_n(offset);
mw.iadd();
}
mw.visitLdcInsn(nameInt);
mw.invokestatic(TYPE_IO_UTILS, "putLongUnaligned", "([BIJ)V");
}
private void writeFieldValueDirectJSONB( private void writeFieldValueDirectJSONB(
long objectFeatures, long objectFeatures,
String classNameType, String classNameType,
@ -1303,7 +1388,7 @@ public class ObjectWriterCreatorASM
methodName = "writeLocalDateTime"; methodName = "writeLocalDateTime";
methodDesc = "([BILjava/time/LocalDateTime;)I"; methodDesc = "([BILjava/time/LocalDateTime;)I";
} else if (fieldClass == OffsetDateTime.class) { } else if (fieldClass == OffsetDateTime.class) {
methodName = "writeOffsetDateTime"; methodName = "writeLocalOffsetDateTime";
methodDesc = "([BILjava/time/OffsetDateTime;)I"; methodDesc = "([BILjava/time/OffsetDateTime;)I";
} else if (fieldClass == OffsetTime.class) { } else if (fieldClass == OffsetTime.class) {
methodName = "writeOffsetTime"; methodName = "writeOffsetTime";
@ -1435,6 +1520,36 @@ public class ObjectWriterCreatorASM
} }
} }
public boolean supportDirectdWriteArrayMappingJSONB(List<FieldWriter> fieldWriters) {
for (FieldWriter fieldWriter : fieldWriters) {
if (fieldWriter.initObjectWriter != null) {
return false;
}
Class fieldClass = fieldWriter.fieldClass;
if (fieldClass == boolean.class || fieldClass == Boolean.class
|| fieldClass == int.class || fieldClass == Integer.class
|| fieldClass == long.class || fieldClass == Long.class
|| fieldClass == float.class || fieldClass == Float.class
|| fieldClass == double.class || fieldClass == Double.class
|| fieldClass == String.class
|| fieldWriter instanceof FieldWriterEnum
) {
continue;
}
if (Collection.class.isAssignableFrom(fieldClass)) {
Class itemClass = fieldWriter.getItemClass();
if (itemClass == String.class || itemClass == Long.class) {
continue;
}
}
return false;
}
return true;
}
private void genMethodWriteArrayMappingJSONB( private void genMethodWriteArrayMappingJSONB(
ObjectWriterProvider provider, ObjectWriterProvider provider,
Class objectType, Class objectType,
@ -1537,7 +1652,11 @@ public class ObjectWriterCreatorASM
if (size <= 15) { if (size <= 15) {
mw.invokevirtual(TYPE_JSON_WRITER, "startArray" + size, "()V"); mw.invokevirtual(TYPE_JSON_WRITER, "startArray" + size, "()V");
} else { } else {
mw.iconst_n(size); if (size >= 128) {
mw.sipush(size);
} else {
mw.bipush(size);
}
mw.invokevirtual(TYPE_JSON_WRITER, "startArray", "(I)V"); mw.invokevirtual(TYPE_JSON_WRITER, "startArray", "(I)V");
} }
} }
@ -4219,7 +4338,33 @@ public class ObjectWriterCreatorASM
mw.dup(); mw.dup();
mw.getfield(TYPE_OBJECT_WRITER_ADAPTER, "fieldWriterArray", DESC_FIELD_WRITER_ARRAY); mw.getfield(TYPE_OBJECT_WRITER_ADAPTER, "fieldWriterArray", DESC_FIELD_WRITER_ARRAY);
mw.iconst_n(i); switch (i) {
case 0:
mw.iconst_0();
break;
case 1:
mw.iconst_1();
break;
case 2:
mw.iconst_2();
break;
case 3:
mw.iconst_3();
break;
case 4:
mw.iconst_4();
break;
case 5:
mw.iconst_5();
break;
default:
if (i >= 128) {
mw.sipush(i);
} else {
mw.bipush(i);
}
break;
}
mw.aaload(); // fieldWriterArray mw.aaload(); // fieldWriterArray
mw.checkcast(TYPE_FIELD_WRITER); mw.checkcast(TYPE_FIELD_WRITER);
mw.putfield(classNameType, fieldWriter(i), DESC_FIELD_WRITER); mw.putfield(classNameType, fieldWriter(i), DESC_FIELD_WRITER);

View File

@ -1626,7 +1626,7 @@ public class JSONReaderTest1 {
for (String name : names) { for (String name : names) {
String str = "{\"" + name + "\":123456789}"; String str = "{\"" + name + "\":123456789}";
byte[] bytes = str.getBytes(); byte[] bytes = str.getBytes();
JSONReaderASCII jsonReader = JSONReaderASCII.of(JSONFactory.createReadContext(), str, bytes, 0, bytes.length); JSONReaderASCII jsonReader = new JSONReaderASCII(JSONFactory.createReadContext(), str, bytes, 0, bytes.length);
assertTrue(jsonReader.nextIfObjectStart()); assertTrue(jsonReader.nextIfObjectStart());
assertEquals( assertEquals(
Fnv.hashCode64(name), Fnv.hashCode64(name),
@ -1646,7 +1646,7 @@ public class JSONReaderTest1 {
bytes[2] = (byte) i0; bytes[2] = (byte) i0;
bytes[3] = (byte) i1; bytes[3] = (byte) i1;
String name = new String(new char[]{(char) i0, (char) i1}); String name = new String(new char[]{(char) i0, (char) i1});
JSONReaderASCII jsonReader = JSONReaderASCII.of(context, null, bytes, 0, bytes.length); JSONReaderASCII jsonReader = new JSONReaderASCII(context, null, bytes, 0, bytes.length);
assertTrue(jsonReader.nextIfObjectStart()); assertTrue(jsonReader.nextIfObjectStart());
assertEquals(Fnv.hashCode64(name), jsonReader.readFieldNameHashCode()); assertEquals(Fnv.hashCode64(name), jsonReader.readFieldNameHashCode());
} }
@ -1665,7 +1665,7 @@ public class JSONReaderTest1 {
bytes[3] = (byte) i1; bytes[3] = (byte) i1;
bytes[4] = (byte) i2; bytes[4] = (byte) i2;
String name = new String(new char[]{(char) i0, (char) i1, (char) i2}); String name = new String(new char[]{(char) i0, (char) i1, (char) i2});
JSONReaderASCII jsonReader = JSONReaderASCII.of(context, null, bytes, 0, bytes.length); JSONReaderASCII jsonReader = new JSONReaderASCII(context, null, bytes, 0, bytes.length);
assertTrue(jsonReader.nextIfObjectStart()); assertTrue(jsonReader.nextIfObjectStart());
assertEquals(Fnv.hashCode64(name), jsonReader.readFieldNameHashCode()); assertEquals(Fnv.hashCode64(name), jsonReader.readFieldNameHashCode());
} }
@ -1680,7 +1680,7 @@ public class JSONReaderTest1 {
bytes[3] = (byte) i1; bytes[3] = (byte) i1;
bytes[4] = (byte) i2; bytes[4] = (byte) i2;
String name = new String(new char[]{(char) i0, (char) i1, (char) i2}); String name = new String(new char[]{(char) i0, (char) i1, (char) i2});
JSONReaderASCII jsonReader = JSONReaderASCII.of(context, null, bytes, 0, bytes.length); JSONReaderASCII jsonReader = new JSONReaderASCII(context, null, bytes, 0, bytes.length);
assertTrue(jsonReader.nextIfObjectStart()); assertTrue(jsonReader.nextIfObjectStart());
assertEquals(Fnv.hashCode64(name), jsonReader.readFieldNameHashCode()); assertEquals(Fnv.hashCode64(name), jsonReader.readFieldNameHashCode());
} }
@ -1703,7 +1703,7 @@ public class JSONReaderTest1 {
bytes[5] = (byte) i3; bytes[5] = (byte) i3;
String name = new String(new char[]{(char) i0, (char) i1, (char) i2, (char) i3}); String name = new String(new char[]{(char) i0, (char) i1, (char) i2, (char) i3});
JSONReaderASCII jsonReader = JSONReaderASCII.of(context, null, bytes, 0, bytes.length); JSONReaderASCII jsonReader = new JSONReaderASCII(context, null, bytes, 0, bytes.length);
assertTrue(jsonReader.nextIfObjectStart()); assertTrue(jsonReader.nextIfObjectStart());
assertEquals(Fnv.hashCode64(name), jsonReader.readFieldNameHashCode()); assertEquals(Fnv.hashCode64(name), jsonReader.readFieldNameHashCode());
} }
@ -1728,7 +1728,7 @@ public class JSONReaderTest1 {
assertTrue(utf16Reader.nextIfObjectStart()); assertTrue(utf16Reader.nextIfObjectStart());
String name0 = utf16Reader.readFieldName(); String name0 = utf16Reader.readFieldName();
JSONReaderASCII asciiReader = JSONReaderASCII.of(JSONFactory.createReadContext(), null, bytes, 0, bytes.length); JSONReaderASCII asciiReader = new JSONReaderASCII(JSONFactory.createReadContext(), null, bytes, 0, bytes.length);
assertTrue(asciiReader.nextIfObjectStart()); assertTrue(asciiReader.nextIfObjectStart());
String name1 = asciiReader.readFieldName(); String name1 = asciiReader.readFieldName();
@ -1756,7 +1756,7 @@ public class JSONReaderTest1 {
assertTrue(utf16Reader.nextIfObjectStart()); assertTrue(utf16Reader.nextIfObjectStart());
String name0 = utf16Reader.readFieldName(); String name0 = utf16Reader.readFieldName();
JSONReaderASCII asciiReader = JSONReaderASCII.of(JSONFactory.createReadContext(), null, bytes, 0, bytes.length); JSONReaderASCII asciiReader = new JSONReaderASCII(JSONFactory.createReadContext(), null, bytes, 0, bytes.length);
assertTrue(asciiReader.nextIfObjectStart()); assertTrue(asciiReader.nextIfObjectStart());
String name1 = asciiReader.readFieldName(); String name1 = asciiReader.readFieldName();
@ -1996,7 +1996,7 @@ public class JSONReaderTest1 {
String json = JSON.toJSONString(JSONObject.of(s1, s1)); String json = JSON.toJSONString(JSONObject.of(s1, s1));
byte[] bytes = json.getBytes(StandardCharsets.ISO_8859_1); byte[] bytes = json.getBytes(StandardCharsets.ISO_8859_1);
JSONReader.Context ctx = JSONFactory.createReadContext(); JSONReader.Context ctx = JSONFactory.createReadContext();
JSONReaderASCII jsonReader = JSONReaderASCII.of(ctx, json, bytes, 0, bytes.length); JSONReaderASCII jsonReader = new JSONReaderASCII(ctx, json, bytes, 0, bytes.length);
JSONObject object = (JSONObject) jsonReader.readObject(); JSONObject object = (JSONObject) jsonReader.readObject();
Object v1 = object.get(s1); Object v1 = object.get(s1);
assertEquals(s1, v1, Integer.toString(i)); assertEquals(s1, v1, Integer.toString(i));
@ -2008,7 +2008,7 @@ public class JSONReaderTest1 {
String json = JSON.toJSONString(JSONObject.of(s2, s2)); String json = JSON.toJSONString(JSONObject.of(s2, s2));
byte[] bytes = json.getBytes(StandardCharsets.ISO_8859_1); byte[] bytes = json.getBytes(StandardCharsets.ISO_8859_1);
JSONReader.Context ctx = JSONFactory.createReadContext(); JSONReader.Context ctx = JSONFactory.createReadContext();
JSONReaderASCII jsonReader = JSONReaderASCII.of(ctx, json, bytes, 0, bytes.length); JSONReaderASCII jsonReader = new JSONReaderASCII(ctx, json, bytes, 0, bytes.length);
JSONObject object = (JSONObject) jsonReader.readObject(); JSONObject object = (JSONObject) jsonReader.readObject();
Object v1 = object.get(s2); Object v1 = object.get(s2);
assertEquals(s2, v1); assertEquals(s2, v1);

View File

@ -161,7 +161,7 @@ public class TestUtils {
return new JSONReader[]{ return new JSONReader[]{
new JSONReaderUTF8(JSONFactory.createReadContext(), utf8Bytes, 0, utf8Bytes.length), new JSONReaderUTF8(JSONFactory.createReadContext(), utf8Bytes, 0, utf8Bytes.length),
new JSONReaderUTF16(JSONFactory.createReadContext(), utf16Bytes, 0, utf16Bytes.length), new JSONReaderUTF16(JSONFactory.createReadContext(), utf16Bytes, 0, utf16Bytes.length),
JSONReaderASCII.of(JSONFactory.createReadContext(), null, utf8Bytes, 0, utf8Bytes.length) new JSONReaderASCII(JSONFactory.createReadContext(), null, utf8Bytes, 0, utf8Bytes.length)
}; };
} }

View File

@ -6,7 +6,6 @@ import com.alibaba.fastjson2.writer.ObjectWriterCreator;
import com.alibaba.fastjson2_vo.*; import com.alibaba.fastjson2_vo.*;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.time.OffsetDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -177,40 +176,4 @@ public class ArrayMappingTest {
return values; return values;
} }
} }
@Test
public void test_4() {
Bean4 vo = new Bean4();
vo.value = OffsetDateTime.MIN;
{
byte[] jsonbBytes = JSONB.toBytes(vo, JSONWriter.Feature.BeanToArray);
assertEquals("[15]", JSONB.toJSONString(jsonbBytes, true));
}
}
public static class Bean4 {
public OffsetDateTime value;
}
@Test
public void test_5() {
Bean5 vo = new Bean5();
vo.values.add(new String1("abc"));
{
byte[] jsonbBytes = JSONB.toBytes(vo, JSONWriter.Feature.BeanToArray);
assertEquals("[\n" +
"\t[\n" +
"\t\t[\"abc\"]\n" +
"\t]\n" +
"]", JSONB.toJSONString(jsonbBytes));
}
}
public class Bean5 {
private List<String1> values = new ArrayList<>();
public List<String1> getValues() {
return values;
}
}
} }

View File

@ -180,33 +180,6 @@ public class AutoTypeTest27 {
assertSame(bean.items.stream().findFirst().get(), bean2.items.stream().findFirst().get()); assertSame(bean.items.stream().findFirst().get(), bean2.items.stream().findFirst().get());
} }
@Test
public void test_subList2() throws Exception {
LinkedList list = new LinkedList();
list.add(0);
list.add(1);
list.add(2);
Bean1 bean = new Bean1();
bean.items = list.subList(0, 1);
byte[] bytes = JSONB.toBytes(bean,
JSONWriter.Feature.WriteClassName,
JSONWriter.Feature.FieldBased,
JSONWriter.Feature.ReferenceDetection,
JSONWriter.Feature.WriteNulls,
JSONWriter.Feature.NotWriteDefaultValue
);
JSONB.dump(bytes);
Bean1 bean2 = (Bean1) JSONB.parseObject(bytes, Object.class, JSONReader.Feature.SupportAutoType, JSONReader.Feature.FieldBased);
assertNotNull(bean2);
assertNotNull(bean2.items);
assertSame(bean.items.size(), bean2.items.size());
assertSame(bean.items.stream().findFirst().get(), bean2.items.stream().findFirst().get());
}
@Test @Test
public void test_arrayList() throws Exception { public void test_arrayList() throws Exception {
Bean1 bean = new Bean1(); Bean1 bean = new Bean1();

View File

@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONWriter;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
public class Issue1396 { public class Issue1396 {
@Test @Test
@ -32,7 +33,7 @@ public class Issue1396 {
// Unknown instance type // Unknown instance type
LivingObject living = JSONObject.parseObject(userJsonString, LivingObject.class); LivingObject living = JSONObject.parseObject(userJsonString, LivingObject.class);
assertEquals(name, living.getSignature().toString()); // -> "null" assertNull(living.getSignature().toString()); // -> "null"
assertEquals(name, living.getSignatureString()); // -> "bob" assertEquals(name, living.getSignatureString()); // -> "bob"
assertEquals(name, living.withSignatureString()); // -> This method 'withSignatureString' is not a getter assertEquals(name, living.withSignatureString()); // -> This method 'withSignatureString' is not a getter
} }
@ -62,10 +63,6 @@ public class Issue1396 {
this.sign = sign; this.sign = sign;
} }
public String getSign() {
return sign;
}
@Override @Override
public String toString() { public String toString() {
return sign; return sign;

View File

@ -1,26 +0,0 @@
package com.alibaba.fastjson2.issues_2200
import com.alibaba.fastjson2.JSON
import com.alibaba.fastjson2.JSONObject
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
class Issue2227 {
@Test
fun testAssertJSONObjectWithVersion2() {
val jsonObject = JSON.toJSON(OuterClass()) as JSONObject
// 以下断言失败
Assertions.assertTrue(jsonObject["nestedClass"] is JSONObject)
}
@Test
fun testAssertJSONObjectWithVersion1() {
val jsonObject = com.alibaba.fastjson.JSON.toJSON(OuterClass()) as com.alibaba.fastjson.JSONObject
// 以下断言成功
Assertions.assertTrue(jsonObject["nestedClass"] is com.alibaba.fastjson.JSONObject)
}
data class OuterClass(val id: Int = 1, val nestedClass: NestedClass = NestedClass())
data class NestedClass(val id: Int = 2)
}

View File

@ -1,22 +0,0 @@
package com.alibaba.fastjson2.issues_3300;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.PropertyNamingStrategy;
import com.alibaba.fastjson2.filter.NameFilter;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue3344 {
@Test
public void test() {
Bean bean = new Bean();
bean.userName = "DataWorks";
String jsonString = JSON.toJSONString(bean, NameFilter.of(PropertyNamingStrategy.SnakeCase));
assertEquals("{\"user_name\":\"DataWorks\"}", jsonString);
}
public static class Bean {
public String userName;
}
}

View File

@ -1,34 +0,0 @@
package com.alibaba.fastjson2.issues_3300;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSONReader;
import org.junit.jupiter.api.Test;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue3347 {
@Test
public void test() {
String json2 = "{\"*/*\":{\"schema\":{\"$ref\":\"Error-ModelName{namespace='javax.servlet.http', name='HttpServletResponse'}\"}}}";
String expected = "Error-ModelName{namespace='javax.servlet.http', name='HttpServletResponse'}";
{
JSONObject jsonObject4 = JSON.parseObject(json2);
assertEquals(expected, jsonObject4.getJSONObject("*/*").getJSONObject("schema").getString("$ref"));
}
{
JSONObject jsonObject4 = JSON.parseObject(json2.getBytes(StandardCharsets.UTF_8));
assertEquals(expected, jsonObject4.getJSONObject("*/*").getJSONObject("schema").getString("$ref"));
}
{
JSONObject jsonObject4 = JSON.parseObject(json2.toCharArray());
assertEquals(expected, jsonObject4.getJSONObject("*/*").getJSONObject("schema").getString("$ref"));
}
{
JSONObject jsonObject4 = JSON.parseObject(json2, JSONReader.Feature.DisableReferenceDetect);
assertEquals(expected, jsonObject4.getJSONObject("*/*").getJSONObject("schema").getString("$ref"));
}
}
}

View File

@ -1,22 +0,0 @@
package com.alibaba.fastjson2.issues_3300;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue3355 {
@Test
public void test() {
com.alibaba.fastjson.JSONObject jsonObject1 = new com.alibaba.fastjson.JSONObject();
Bean bean1 = jsonObject1.toJavaObject(Bean.class);
com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject();
Bean bean2 = jsonObject.toJavaObject(Bean.class);
assertEquals(bean2.value, bean1.value);
}
public static class Bean {
public Integer value = 2;
}
}

View File

@ -3,13 +3,6 @@ package com.alibaba.fastjson2_vo;
public class String1 { public class String1 {
private String id; private String id;
public String1() {
}
public String1(String id) {
this.id = id;
}
public String getId() { public String getId() {
return id; return id;
} }

View File

@ -1,720 +0,0 @@
## 1. [EishayFuryCompatibleParse](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayFuryCompatibleParse.java)
这个场景是JSONB格式和Fury CompatibleMode反序列化性能比较。基于KeyValue的映射对增加和删除字段的序列化结构都能有很好的兼容性。
| aliyun ecs spec | jdk version | jsonb | fury |
|-----|-----|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 6308.151 | 5961.37 (94.5%) |
| | jdk-11.0.20 | 7835.257 | 7518.721 (95.96%) |
| | jdk-17.0.8 | 8718.078 | 9467.17 (108.59%) |
| | jdk-21.0.2 | 8926.819 | 9373.313 (105%) |
| | graalvm_21+35.1 | 12425.613 | 9495.807 (76.42%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 5248.192 | 5087.319 (96.93%) |
| | jdk-11.0.20 | 4496.515 | 4793.425 (106.6%) |
| | jdk-17.0.8 | 5477.867 | 5643.844 (103.03%) |
| | jdk-21.0.2 | 6967.569 | 6425.217 (92.22%) |
| | graalvm_21+35.1 | 8849.176 | 6445.184 (72.83%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 7835.405 | 7996.888 (102.06%) |
| | jdk-11.0.20 | 8895.283 | 9413.711 (105.83%) |
| | zulu17.54.21 | 9987.426 | 10016.849 (100.29%) |
| | jdk-21.0.2 | 9903.646 | 10115.71 (102.14%) |
| | graalvm_21+35.1 | 11438.495 | 11973.436 (104.68%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 5299.446 | 6948.599 (131.12%) |
| | jdk-11.0.19 | 6315.463 | 6340.329 (100.39%) |
| | jdk-17.0.7 | 6300.933 | 6363.643 (101%) |
| | jdk-21 | 6618.831 | 6647.125 (100.43%) |
| | graalvm_21+35.1 | 7511.678 | 7711.597 (102.66%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 1586.826 | 1604.598 (101.12%) |
| | jdk-11.0.20 | 1580.381 | 1863.967 (117.94%) |
| | jdk-17.0.8 | 2079.293 | 2104.009 (101.19%) |
| | jdk-21.0.2 | 2080.679 | 2080.991 (100.01%) |
| | graalvm_21+35.1 | 2249.75 | 2242.94 (99.7%) |
| MacBookM1Pro | zulu-8.jdk | 26381.287 | 18903.668 (71.66%) |
| | zulu-11.jdk | 17834.77 | 22275.525 (124.9%) |
| | zulu-17.jdk | 29855.431 | 31567.428 (105.73%) |
| | zulu-21.jdk | 30559.492 | 29302.787 (95.89%) |
| | graalvm_21+35.1 | 41273.265 | 28599.967 (69.29%) |
## 2. [EishayFuryCompatibleWrite](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayFuryCompatibleWrite.java)
这个场景是JSONB格式和Fury CompatibleMode序列化性能比较。基于KeyValue的映射对增加和删除字段的序列化结构都能有很好的兼容性。
| aliyun ecs spec | jdk version | jsonb | fury |
|-----|-----|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 8458.114 | 6474.97 (76.55%) |
| | jdk-11.0.20 | 9463.611 | 7887.165 (83.34%) |
| | jdk-17.0.8 | 11450.654 | 9307.791 (81.29%) |
| | jdk-21.0.2 | 11178.289 | 9301.156 (83.21%) |
| | graalvm_21+35.1 | 10862.415 | 8065.954 (74.26%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 5440.245 | 4574.911 (84.09%) |
| | jdk-11.0.20 | 6378.579 | 5039.58 (79.01%) |
| | jdk-17.0.8 | 6720.296 | 5791.581 (86.18%) |
| | jdk-21.0.2 | 8366.563 | 6184.094 (73.91%) |
| | graalvm_21+35.1 | 8171.179 | 5995.456 (73.37%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 8088.53 | 7107.342 (87.87%) |
| | jdk-11.0.20 | 9899.123 | 9478.667 (95.75%) |
| | zulu17.54.21 | 10101.525 | 9871.632 (97.72%) |
| | jdk-21.0.2 | 10642.193 | 8151.738 (76.6%) |
| | graalvm_21+35.1 | 11086.091 | 8481.956 (76.51%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 6442.063 | 5813.335 (90.24%) |
| | jdk-11.0.19 | 7465.824 | 5896.543 (78.98%) |
| | jdk-17.0.7 | 7262.206 | 5783.882 (79.64%) |
| | jdk-21 | 7334.474 | 5574.463 (76%) |
| | graalvm_21+35.1 | 6888.997 | 6334.12 (91.95%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 1904.231 | 1601.64 (84.11%) |
| | jdk-11.0.20 | 1890.186 | 2111.901 (111.73%) |
| | jdk-17.0.8 | 2257.126 | 2281.391 (101.08%) |
| | jdk-21.0.2 | 2216.647 | 2156.899 (97.3%) |
| | graalvm_21+35.1 | 2252.834 | 1923.363 (85.38%) |
| MacBookM1Pro | zulu-8.jdk | 19051.787 | 9267.983 (48.65%) |
| | zulu-11.jdk | 22892.219 | 12398.577 (54.16%) |
| | zulu-17.jdk | 42413.58 | 14473.962 (34.13%) |
| | zulu-21.jdk | 41681.487 | 24168.853 (57.98%) |
| | graalvm_21+35.1 | 43612.715 | 19240.98 (44.12%) |
## 3. [EishayParseBinary](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayParseBinary.java)
这个场景是二进制反序列化比较JSONB格式、JSON UTF8编码(fastjson2UTF8Bytes)、hessian、javaSerialize的比较用于[Apache dubbo](https://github.com/apache/dubbo)的用户选择二进制协议比较
| aliyun ecs spec | jdk version | jsonb | fastjson2UTF8Bytes | hessian | javaSerialize |
|-----|-----|----------|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 8282.732 | 3135.539 (37.86%) | 834.373 (10.07%) | 141.673 (1.71%) |
| | jdk-11.0.20 | 9421.761 | 3880.974 (41.19%) | 774.375 (8.22%) | 152.445 (1.62%) |
| | jdk-17.0.8 | 10125.749 | 5876.745 (58.04%) | 796.068 (7.86%) | 165.593 (1.64%) |
| | jdk-21.0.2 | 10237.533 | 5586.216 (54.57%) | 801.012 (7.82%) | 157.157 (1.54%) |
| | graalvm_21+35.1 | 14472.476 | 8442.394 (58.33%) | 1053.48 (7.28%) | 154.037 (1.06%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 5555.23 | 2618.308 (47.13%) | 499.944 (9%) | 92.792 (1.67%) |
| | jdk-11.0.20 | 5996.851 | 3040.053 (50.69%) | 446.39 (7.44%) | 93.91 (1.57%) |
| | jdk-17.0.8 | 6728.642 | 3551.535 (52.78%) | 469.996 (6.99%) | 104.312 (1.55%) |
| | jdk-21.0.2 | 7978.888 | 3878.629 (48.61%) | 653.511 (8.19%) | 125.889 (1.58%) |
| | graalvm_21+35.1 | 9869.028 | 4715.628 (47.78%) | 824.71 (8.36%) | 126.117 (1.28%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 9010.644 | 5311.038 (58.94%) | 532.499 (5.91%) | 174.473 (1.94%) |
| | jdk-11.0.20 | 10263.216 | 4778.458 (46.56%) | 418.32 (4.08%) | 170.721 (1.66%) |
| | zulu17.54.21 | 11012.213 | 5837.519 (53.01%) | 617.446 (5.61%) | 179.328 (1.63%) |
| | jdk-21.0.2 | 10724.977 | 5902.829 (55.04%) | 500.038 (4.66%) | 175.851 (1.64%) |
| | graalvm_21+35.1 | 13053.072 | 7296.631 (55.9%) | 685.243 (5.25%) | 176.736 (1.35%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 6487.346 | 2394.844 (36.92%) | 231.678 (3.57%) | 127.847 (1.97%) |
| | jdk-11.0.19 | 6814.621 | 4071.401 (59.75%) | 218.254 (3.2%) | 123.886 (1.82%) |
| | jdk-17.0.7 | 7177.715 | 4046.726 (56.38%) | 235.181 (3.28%) | 128.877 (1.8%) |
| | jdk-21 | 7061.12 | 4266.899 (60.43%) | 208.429 (2.95%) | 124.06 (1.76%) |
| | graalvm_21+35.1 | 9020.81 | 5374.14 (59.57%) | 299.399 (3.32%) | 126.903 (1.41%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 1849.933 | 512.742 (27.72%) | 151.091 (8.17%) | 28.481 (1.54%) |
| | jdk-11.0.20 | 2338.188 | 927.996 (39.69%) | 136.978 (5.86%) | 27.86 (1.19%) |
| | jdk-17.0.8 | 2381.963 | 968.619 (40.66%) | 151.105 (6.34%) | 28.18 (1.18%) |
| | jdk-21.0.2 | 2408.451 | 1199.735 (49.81%) | 136.229 (5.66%) | 28.317 (1.18%) |
| | graalvm_21+35.1 | 2686.944 | 1536.926 (57.2%) | 197.736 (7.36%) | 26.881 (1%) |
| MacBookM1Pro | zulu-8.jdk | 38296.214 | 11971.278 (31.26%) | 878.03 (2.29%) | 433.63 (1.13%) |
| | zulu-11.jdk | 24125.779 | 13344.906 (55.31%) | 608.537 (2.52%) | 319.188 (1.32%) |
| | zulu-17.jdk | 44264.512 | 19320.732 (43.65%) | 785.499 (1.77%) | 547.255 (1.24%) |
| | zulu-21.jdk | 43995.211 | 18692.724 (42.49%) | 822.857 (1.87%) | 521.666 (1.19%) |
| | graalvm_21+35.1 | 52086.866 | 21606.086 (41.48%) | 1155.949 (2.22%) | 521.086 (1%) |
## 4. [EishayParseBinaryArrayMapping](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayParseBinaryArrayMapping.java)
这个场景是二进制反序列化比较JSONB格式基于字段顺序映射、kryo、protobuf的比较
| aliyun ecs spec | jdk version | jsonb | kryo | protobuf |
|-----|-----|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 9464.455 | 4654.75 (49.18%) | 3834.889 (40.52%) |
| | jdk-11.0.20 | 13356.472 | 4300.447 (32.2%) | 4525.63 (33.88%) |
| | jdk-17.0.8 | 14652.228 | 4405.428 (30.07%) | 5830.922 (39.8%) |
| | jdk-21.0.2 | 14347.299 | 4888.046 (34.07%) | 5672.71 (39.54%) |
| | graalvm_21+35.1 | 22345.515 | 5348.536 (23.94%) | 8101.286 (36.25%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 6638.497 | 2971.215 (44.76%) | 2332.795 (35.14%) |
| | jdk-11.0.20 | 8301.48 | 3110.747 (37.47%) | 2423.424 (29.19%) |
| | jdk-17.0.8 | 9426.761 | 3023.763 (32.08%) | 3190.998 (33.85%) |
| | jdk-21.0.2 | 11539.349 | 3186.151 (27.61%) | 3827.654 (33.17%) |
| | graalvm_21+35.1 | 15746.822 | 3942.631 (25.04%) | 5554.128 (35.27%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 12430.541 | 6129.338 (49.31%) | 3938.235 (31.68%) |
| | jdk-11.0.20 | 13218.033 | 5951.796 (45.03%) | 4107.184 (31.07%) |
| | zulu17.54.21 | 15076.226 | 5492.099 (36.43%) | 5477.797 (36.33%) |
| | jdk-21.0.2 | 12898.985 | 5738.34 (44.49%) | 5786.616 (44.86%) |
| | graalvm_21+35.1 | 22981.145 | 5364.062 (23.34%) | 8034.082 (34.96%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 6593.08 | 4001.694 (60.7%) | 2515.57 (38.15%) |
| | jdk-11.0.19 | 7097.24 | 3260.969 (45.95%) | 3039.014 (42.82%) |
| | jdk-17.0.7 | 7073.207 | 3449.194 (48.76%) | 3899.272 (55.13%) |
| | jdk-21 | 7110.259 | 3949.259 (55.54%) | 4223.303 (59.4%) |
| | graalvm_21+35.1 | 8896.385 | 3642.887 (40.95%) | 5003.124 (56.24%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 2348.424 | 1101.798 (46.92%) | 569.475 (24.25%) |
| | jdk-11.0.20 | 2806.129 | 1103.47 (39.32%) | 683.19 (24.35%) |
| | jdk-17.0.8 | 2372.346 | 1182.712 (49.85%) | 827.469 (34.88%) |
| | jdk-21.0.2 | 2359.553 | 1091.94 (46.28%) | 959.918 (40.68%) |
| | graalvm_21+35.1 | 3806.811 | 990.92 (26.03%) | 1274.824 (33.49%) |
| MacBookM1Pro | zulu-8.jdk | 48464.484 | 13085.034 (27%) | 13629.661 (28.12%) |
| | zulu-11.jdk | 31559.195 | 10774.334 (34.14%) | 7457.334 (23.63%) |
| | zulu-17.jdk | 51852.664 | 11834.523 (22.82%) | 18284.436 (35.26%) |
| | zulu-21.jdk | 52523.651 | 14472.767 (27.55%) | 14792.122 (28.16%) |
| | graalvm_21+35.1 | 83596.261 | 13274.636 (15.88%) | 32138.427 (38.44%) |
## 5. [EishayParseBinaryAutoType](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayParseBinaryAutoType.java)
这个场景是带类型信息二进制反序列化比较JSONB格式、JSON UTF8编码(fastjson2UTF8Bytes)、hessian、javaSerialize的比较用于[Apache dubbo](https://github.com/apache/dubbo)的用户选择二进制协议比较
| aliyun ecs spec | jdk version | fastjson2JSONB | hessian | javaSerialize |
|-----|-----|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 4545.949 | 801.594 (17.63%) | 143.422 (3.15%) |
| | jdk-11.0.20 | 5367.983 | 766.959 (14.29%) | 145.782 (2.72%) |
| | jdk-17.0.8 | 5876.906 | 803.2 (13.67%) | 167.726 (2.85%) |
| | jdk-21.0.2 | 5756.175 | 801.134 (13.92%) | 153.991 (2.68%) |
| | graalvm_21+35.1 | 8030.239 | 1071.867 (13.35%) | 155.02 (1.93%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 3189.094 | 504.712 (15.83%) | 93.728 (2.94%) |
| | jdk-11.0.20 | 3475.567 | 436.425 (12.56%) | 94.529 (2.72%) |
| | jdk-17.0.8 | 3895.933 | 467.394 (12%) | 102.702 (2.64%) |
| | jdk-21.0.2 | 4625.316 | 681.275 (14.73%) | 124.615 (2.69%) |
| | graalvm_21+35.1 | 4907.826 | 780.672 (15.91%) | 128.333 (2.61%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 5748.941 | 475.098 (8.26%) | 177.392 (3.09%) |
| | jdk-11.0.20 | 6241.326 | 420.439 (6.74%) | 172.583 (2.77%) |
| | zulu17.54.21 | 6825.305 | 567.859 (8.32%) | 174.834 (2.56%) |
| | jdk-21.0.2 | 6398.192 | 519.413 (8.12%) | 179.796 (2.81%) |
| | graalvm_21+35.1 | 7855.656 | 722.838 (9.2%) | 177.825 (2.26%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 3412.58 | 224.114 (6.57%) | 129.06 (3.78%) |
| | jdk-11.0.19 | 3767.312 | 236.434 (6.28%) | 123.166 (3.27%) |
| | jdk-17.0.7 | 3925.021 | 235.679 (6%) | 134.006 (3.41%) |
| | jdk-21 | 3885.626 | 207.021 (5.33%) | 121.753 (3.13%) |
| | graalvm_21+35.1 | 5085.403 | 289.795 (5.7%) | 119.531 (2.35%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 1044.261 | 150.358 (14.4%) | 28.711 (2.75%) |
| | jdk-11.0.20 | 1120.57 | 136.609 (12.19%) | 28.632 (2.56%) |
| | jdk-17.0.8 | 1321.051 | 148.74 (11.26%) | 29.034 (2.2%) |
| | jdk-21.0.2 | 1291.34 | 133.681 (10.35%) | 27.95 (2.16%) |
| | graalvm_21+35.1 | 1443.878 | 213.705 (14.8%) | 27.225 (1.89%) |
| MacBookM1Pro | zulu-8.jdk | 20888.923 | 884.407 (4.23%) | 431.939 (2.07%) |
| | zulu-11.jdk | 13911.232 | 562.236 (4.04%) | 314.914 (2.26%) |
| | zulu-17.jdk | 23793.052 | 839.234 (3.53%) | 536.573 (2.26%) |
| | zulu-21.jdk | 23722.46 | 854.004 (3.6%) | 519.201 (2.19%) |
| | graalvm_21+35.1 | 29366.999 | 1259.926 (4.29%) | 508.525 (1.73%) |
## 6. [EishayParseString](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayParseString.java)
这个场景是将没有格式化的JSON字符串反序列化为JavaBean对象是最常用的场景这个是fastjson1的强项。
| aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
|-----|-----|----------|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 4351.646 | 3311.876 (76.11%) | 1461.9 (33.59%) | 1320.65 (30.35%) |
| | jdk-11.0.20 | 4866.615 | 2846.977 (58.5%) | 1326.355 (27.25%) | 1353.619 (27.81%) |
| | jdk-17.0.8 | 6042.858 | 4087.74 (67.65%) | 1440.174 (23.83%) | 1398.874 (23.15%) |
| | jdk-21.0.2 | 6309.225 | 3991.188 (63.26%) | 1350.378 (21.4%) | 1186.074 (18.8%) |
| | graalvm_21+35.1 | 7819.334 | 5811.03 (74.32%) | 1464.285 (18.73%) | 1395.616 (17.85%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 3115.917 | 1952.299 (62.66%) | 959.773 (30.8%) | 852.281 (27.35%) |
| | jdk-11.0.20 | 2668.918 | 1810.487 (67.84%) | 845.237 (31.67%) | 819.701 (30.71%) |
| | jdk-17.0.8 | 3657.929 | 2409.559 (65.87%) | 897.834 (24.54%) | 804.751 (22%) |
| | jdk-21.0.2 | 4004.469 | 2610.865 (65.2%) | 992.67 (24.79%) | 932.654 (23.29%) |
| | graalvm_21+35.1 | 4722.084 | 3560.773 (75.41%) | 1036.354 (21.95%) | 1037.467 (21.97%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 5740.284 | 3721.044 (64.82%) | 1625.763 (28.32%) | 1587.396 (27.65%) |
| | jdk-11.0.20 | 4716.571 | 3465.788 (73.48%) | 1438.082 (30.49%) | 1524.497 (32.32%) |
| | zulu17.54.21 | 5997.298 | 4696.47 (78.31%) | 1497.11 (24.96%) | 1548.803 (25.83%) |
| | jdk-21.0.2 | 6183.133 | 4565.612 (73.84%) | 1442.438 (23.33%) | 1370.656 (22.17%) |
| | graalvm_21+35.1 | 7313.839 | 5316.51 (72.69%) | 1450.921 (19.84%) | 1300.545 (17.78%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 3998.932 | 2565.254 (64.15%) | 1143.416 (28.59%) | 1009.898 (25.25%) |
| | jdk-11.0.19 | 2461.526 | 2481.649 (100.82%) | 943.421 (38.33%) | 1034.43 (42.02%) |
| | jdk-17.0.7 | 4322.153 | 3404.168 (78.76%) | 1019.267 (23.58%) | 1005.258 (23.26%) |
| | jdk-21 | 4318.49 | 3318.522 (76.84%) | 922.081 (21.35%) | 903.595 (20.92%) |
| | graalvm_21+35.1 | 4831.554 | 3889.458 (80.5%) | 1046.839 (21.67%) | 960.125 (19.87%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 1142.071 | 753.286 (65.96%) | 294.443 (25.78%) | 258.051 (22.6%) |
| | jdk-11.0.20 | 954.331 | 721.569 (75.61%) | 293.06 (30.71%) | 252.689 (26.48%) |
| | jdk-17.0.8 | 1142.343 | 981.687 (85.94%) | 306.992 (26.87%) | 261.265 (22.87%) |
| | jdk-21.0.2 | 1234.169 | 961.722 (77.92%) | 289.241 (23.44%) | 225.421 (18.27%) |
| | graalvm_21+35.1 | 1428.564 | 1022.382 (71.57%) | 276.705 (19.37%) | 237.63 (16.63%) |
| MacBookM1Pro | zulu-8.jdk | 21702.695 | 11544.811 (53.2%) | 4878.074 (22.48%) | 5478.81 (25.24%) |
| | zulu-11.jdk | 14001.815 | 6848.044 (48.91%) | 3101.987 (22.15%) | 3775.602 (26.97%) |
| | zulu-17.jdk | 18450.272 | 16286.644 (88.27%) | 4611.942 (25%) | 5549.198 (30.08%) |
| | zulu-21.jdk | 20021.409 | 16233.609 (81.08%) | 5038.7 (25.17%) | 5395.118 (26.95%) |
| | graalvm_21+35.1 | 21890.646 | 15014.989 (68.59%) | 4986.761 (22.78%) | 4831.978 (22.07%) |
## 7. [EishayParseStringPretty](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayParseStringPretty.java)
这个场景是将格式化过的JSON字符串反序列化为JavaBean对象
| aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
|-----|-----|----------|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 3424.622 | 901.688 (26.33%) | 1328.462 (38.79%) | 1224.65 (35.76%) |
| | jdk-11.0.20 | 3288.698 | 767.171 (23.33%) | 1239.538 (37.69%) | 1268.884 (38.58%) |
| | jdk-17.0.8 | 4312.868 | 943.544 (21.88%) | 1301.617 (30.18%) | 1287.129 (29.84%) |
| | jdk-21.0.2 | 4358.06 | 874.673 (20.07%) | 1259.545 (28.9%) | 1141.023 (26.18%) |
| | graalvm_21+35.1 | 4639.983 | 1171.898 (25.26%) | 1328.666 (28.64%) | 1284.805 (27.69%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 1584.232 | 511.01 (32.26%) | 883.109 (55.74%) | 777.428 (49.07%) |
| | jdk-11.0.20 | 1378.824 | 492.532 (35.72%) | 807.676 (58.58%) | 735.079 (53.31%) |
| | jdk-17.0.8 | 2689.57 | 549.209 (20.42%) | 789.244 (29.34%) | 741.108 (27.55%) |
| | jdk-21.0.2 | 3079.79 | 625.092 (20.3%) | 912.683 (29.63%) | 901.799 (29.28%) |
| | graalvm_21+35.1 | 2769.475 | 885.437 (31.97%) | 961.268 (34.71%) | 973.271 (35.14%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 4144.529 | 1025.054 (24.73%) | 1429.836 (34.5%) | 1450.311 (34.99%) |
| | jdk-11.0.20 | 2076.426 | 1013.94 (48.83%) | 1439.014 (69.3%) | 1418.195 (68.3%) |
| | zulu17.54.21 | 4378.181 | 1124.945 (25.69%) | 1451.654 (33.16%) | 1432.596 (32.72%) |
| | jdk-21.0.2 | 4262.799 | 1034.916 (24.28%) | 1311.69 (30.77%) | 1307.524 (30.67%) |
| | graalvm_21+35.1 | 4694.058 | 1358.97 (28.95%) | 1305.342 (27.81%) | 1326.252 (28.25%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 3191.102 | 684.772 (21.46%) | 1006.536 (31.54%) | 940.158 (29.46%) |
| | jdk-11.0.19 | 3191.813 | 713.041 (22.34%) | 996.443 (31.22%) | 940.948 (29.48%) |
| | jdk-17.0.7 | 3269.789 | 805.879 (24.65%) | 1009.362 (30.87%) | 967.199 (29.58%) |
| | jdk-21 | 3278.12 | 699.619 (21.34%) | 889.393 (27.13%) | 857.267 (26.15%) |
| | graalvm_21+35.1 | 3668.898 | 864.921 (23.57%) | 932.247 (25.41%) | 890.641 (24.28%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 651.623 | 178.188 (27.35%) | 274.439 (42.12%) | 235.95 (36.21%) |
| | jdk-11.0.20 | 763.37 | 174.991 (22.92%) | 276.256 (36.19%) | 243.778 (31.93%) |
| | jdk-17.0.8 | 893.912 | 209.02 (23.38%) | 275.875 (30.86%) | 246.096 (27.53%) |
| | jdk-21.0.2 | 939.202 | 179.094 (19.07%) | 263.451 (28.05%) | 210.865 (22.45%) |
| | graalvm_21+35.1 | 812.041 | 226.216 (27.86%) | 254.21 (31.31%) | 212.814 (26.21%) |
| MacBookM1Pro | zulu-8.jdk | 14632.99 | 2889.084 (19.74%) | 4663.3 (31.87%) | 4722.814 (32.28%) |
| | zulu-11.jdk | 8640.531 | 2113.527 (24.46%) | 2997.565 (34.69%) | 3545.433 (41.03%) |
| | zulu-17.jdk | 14538.151 | 3728.326 (25.65%) | 4408.375 (30.32%) | 5208.3 (35.83%) |
| | zulu-21.jdk | 15257.558 | 3549.981 (23.27%) | 4702.335 (30.82%) | 4833.41 (31.68%) |
| | graalvm_21+35.1 | 14233.589 | 4709.9 (33.09%) | 4611.665 (32.4%) | 4512.574 (31.7%) |
## 8. [EishayParseTreeString](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayParseTreeString.java)
这个场景是将没有格式化的JSON字符串解析为JSONObject或者HashMap不涉及绑定JavaBean对象。
| aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
|-----|-----|----------|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 2613.722 | 1529.949 (58.54%) | 1481.671 (56.69%) | 1132.302 (43.32%) |
| | jdk-11.0.20 | 2216.672 | 1124.669 (50.74%) | 1409.169 (63.57%) | 1118.717 (50.47%) |
| | jdk-17.0.8 | 3098.773 | 1554.314 (50.16%) | 1566.044 (50.54%) | 1151.493 (37.16%) |
| | jdk-21.0.2 | 3083.638 | 1508.688 (48.93%) | 1454.015 (47.15%) | 1127.398 (36.56%) |
| | graalvm_21+35.1 | 3370.182 | 1996.3 (59.23%) | 1731.683 (51.38%) | 1378.08 (40.89%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 1770.215 | 990.008 (55.93%) | 1015.223 (57.35%) | 676.282 (38.2%) |
| | jdk-11.0.20 | 1482.857 | 866.81 (58.46%) | 851.212 (57.4%) | 621.206 (41.89%) |
| | jdk-17.0.8 | 2101.787 | 1050.098 (49.96%) | 949.971 (45.2%) | 626.845 (29.82%) |
| | jdk-21.0.2 | 2625.061 | 1160.641 (44.21%) | 1092.346 (41.61%) | 768.962 (29.29%) |
| | graalvm_21+35.1 | 2307.526 | 1505.812 (65.26%) | 1191.135 (51.62%) | 941.261 (40.79%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 2878.649 | 1333.041 (46.31%) | 1272.621 (44.21%) | 1299.2 (45.13%) |
| | jdk-11.0.20 | 2983.056 | 1580.729 (52.99%) | 1372.68 (46.02%) | 1205.167 (40.4%) |
| | zulu17.54.21 | 3521.744 | 1726.533 (49.02%) | 1456.723 (41.36%) | 1250.488 (35.51%) |
| | jdk-21.0.2 | 3376.656 | 1493.635 (44.23%) | 1498.054 (44.37%) | 1201.162 (35.57%) |
| | graalvm_21+35.1 | 3831.508 | 2353.292 (61.42%) | 1750.27 (45.68%) | 1422.435 (37.12%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 1937.914 | 871.964 (44.99%) | 1039.239 (53.63%) | 833.38 (43%) |
| | jdk-11.0.19 | 2052.815 | 1051.819 (51.24%) | 1034.38 (50.39%) | 829.92 (40.43%) |
| | jdk-17.0.7 | 2201.828 | 1276.769 (57.99%) | 1141.657 (51.85%) | 824.521 (37.45%) |
| | jdk-21 | 2161.527 | 1075.439 (49.75%) | 1124.227 (52.01%) | 771.676 (35.7%) |
| | graalvm_21+35.1 | 2221.373 | 1528.78 (68.82%) | 1200.846 (54.06%) | 947.912 (42.67%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 539.845 | 246.622 (45.68%) | 259.024 (47.98%) | 204.272 (37.84%) |
| | jdk-11.0.20 | 640.805 | 296.452 (46.26%) | 290.703 (45.37%) | 207.031 (32.31%) |
| | jdk-17.0.8 | 691.792 | 330.885 (47.83%) | 313.17 (45.27%) | 210.718 (30.46%) |
| | jdk-21.0.2 | 677.477 | 276.051 (40.75%) | 353.039 (52.11%) | 202.218 (29.85%) |
| | graalvm_21+35.1 | 691.829 | 425.734 (61.54%) | 337.658 (48.81%) | 239.434 (34.61%) |
| MacBookM1Pro | zulu-8.jdk | 11462.0 | 4609.902 (40.22%) | 4307.991 (37.58%) | 3678.067 (32.09%) |
| | zulu-11.jdk | 6345.56 | 3405.038 (53.66%) | 3174.569 (50.03%) | 3451.229 (54.39%) |
| | zulu-17.jdk | 13999.312 | 5763.849 (41.17%) | 5077.309 (36.27%) | 4226.636 (30.19%) |
| | zulu-21.jdk | 13343.955 | 5141.986 (38.53%) | 4694.853 (35.18%) | 4157.677 (31.16%) |
| | graalvm_21+35.1 | 13521.157 | 8384.946 (62.01%) | 5117.915 (37.85%) | 4536.544 (33.55%) |
## 9. [EishayParseTreeStringPretty](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayParseTreeStringPretty.java)
这个场景是将格式化过的字符串解析为JSONObject或者HashMap不涉及绑定JavaBean对象。
| aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
|-----|-----|----------|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 2246.599 | 1357.763 (60.44%) | 1412.304 (62.86%) | 1067.016 (47.49%) |
| | jdk-11.0.20 | 1960.442 | 991.974 (50.6%) | 1307.481 (66.69%) | 1068.053 (54.48%) |
| | jdk-17.0.8 | 2490.561 | 1369.493 (54.99%) | 1406.358 (56.47%) | 1090.567 (43.79%) |
| | jdk-21.0.2 | 2490.4 | 1323.036 (53.13%) | 1389.027 (55.78%) | 1058.737 (42.51%) |
| | graalvm_21+35.1 | 2717.866 | 1698.344 (62.49%) | 1602.437 (58.96%) | 1246.007 (45.85%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 1387.741 | 870.0 (62.69%) | 903.934 (65.14%) | 627.292 (45.2%) |
| | jdk-11.0.20 | 1245.44 | 771.104 (61.91%) | 775.278 (62.25%) | 578.201 (46.43%) |
| | jdk-17.0.8 | 1657.421 | 961.918 (58.04%) | 852.487 (51.43%) | 600.235 (36.21%) |
| | jdk-21.0.2 | 2003.353 | 1021.88 (51.01%) | 1031.245 (51.48%) | 727.651 (36.32%) |
| | graalvm_21+35.1 | 1685.677 | 1265.419 (75.07%) | 1051.357 (62.37%) | 874.112 (51.86%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 2409.619 | 1247.458 (51.77%) | 1211.459 (50.28%) | 1224.558 (50.82%) |
| | jdk-11.0.20 | 2730.236 | 1322.572 (48.44%) | 1313.096 (48.09%) | 1125.164 (41.21%) |
| | zulu17.54.21 | 2877.344 | 1531.287 (53.22%) | 1351.363 (46.97%) | 1174.359 (40.81%) |
| | jdk-21.0.2 | 2785.731 | 1311.816 (47.09%) | 1235.883 (44.36%) | 1102.589 (39.58%) |
| | graalvm_21+35.1 | 2954.04 | 2062.251 (69.81%) | 1564.76 (52.97%) | 1334.495 (45.18%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 1741.576 | 804.607 (46.2%) | 995.932 (57.19%) | 783.5 (44.99%) |
| | jdk-11.0.19 | 1757.346 | 843.974 (48.03%) | 958.058 (54.52%) | 763.917 (43.47%) |
| | jdk-17.0.7 | 1870.633 | 1072.544 (57.34%) | 1081.46 (57.81%) | 767.611 (41.03%) |
| | jdk-21 | 1798.138 | 949.944 (52.83%) | 1040.429 (57.86%) | 745.418 (41.45%) |
| | graalvm_21+35.1 | 1922.984 | 1295.262 (67.36%) | 1066.182 (55.44%) | 843.815 (43.88%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 483.947 | 217.074 (44.85%) | 246.936 (51.03%) | 195.464 (40.39%) |
| | jdk-11.0.20 | 557.239 | 226.011 (40.56%) | 269.093 (48.29%) | 197.71 (35.48%) |
| | jdk-17.0.8 | 575.822 | 293.687 (51%) | 294.366 (51.12%) | 197.622 (34.32%) |
| | jdk-21.0.2 | 585.402 | 252.299 (43.1%) | 280.327 (47.89%) | 186.367 (31.84%) |
| | graalvm_21+35.1 | 567.789 | 362.094 (63.77%) | 302.605 (53.3%) | 223.104 (39.29%) |
| MacBookM1Pro | zulu-8.jdk | 9868.125 | 4205.652 (42.62%) | 4221.291 (42.78%) | 3549.842 (35.97%) |
| | zulu-11.jdk | 5572.531 | 2706.692 (48.57%) | 2862.979 (51.38%) | 2946.439 (52.87%) |
| | zulu-17.jdk | 11049.872 | 4981.977 (45.09%) | 4380.198 (39.64%) | 4020.892 (36.39%) |
| | zulu-21.jdk | 10866.774 | 4828.978 (44.44%) | 4641.882 (42.72%) | 3841.608 (35.35%) |
| | graalvm_21+35.1 | 10960.079 | 7033.633 (64.18%) | 4588.459 (41.87%) | 4477.779 (40.86%) |
## 10. [EishayParseTreeUTF8Bytes](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayParseTreeUTF8Bytes.java)
这个场景是将没有格式化的JSON字符串UTF8编码的byte[]数组反序列化解析为JSONObject或者HashMap不涉及绑定JavaBean对象。
| aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
|-----|-----|----------|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 2218.258 | 1344.009 (60.59%) | 1663.572 (74.99%) | 1037.544 (46.77%) |
| | jdk-11.0.20 | 2188.457 | 1019.842 (46.6%) | 1581.811 (72.28%) | 1076.109 (49.17%) |
| | jdk-17.0.8 | 3102.606 | 1357.032 (43.74%) | 1707.61 (55.04%) | 1150.997 (37.1%) |
| | jdk-21.0.2 | 3079.374 | 1376.359 (44.7%) | 1727.088 (56.09%) | 1106.124 (35.92%) |
| | graalvm_21+35.1 | 3343.67 | 1693.288 (50.64%) | 1804.045 (53.95%) | 1280.206 (38.29%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 1471.724 | 882.615 (59.97%) | 1084.421 (73.68%) | 626.534 (42.57%) |
| | jdk-11.0.20 | 1507.135 | 806.79 (53.53%) | 918.433 (60.94%) | 625.271 (41.49%) |
| | jdk-17.0.8 | 2114.474 | 974.483 (46.09%) | 1134.626 (53.66%) | 725.734 (34.32%) |
| | jdk-21.0.2 | 2565.239 | 1086.65 (42.36%) | 1194.348 (46.56%) | 760.27 (29.64%) |
| | graalvm_21+35.1 | 2308.482 | 1314.445 (56.94%) | 1217.277 (52.73%) | 927.01 (40.16%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 2375.349 | 1266.141 (53.3%) | 1534.552 (64.6%) | 1145.833 (48.24%) |
| | jdk-11.0.20 | 3017.738 | 1391.477 (46.11%) | 1663.574 (55.13%) | 1145.219 (37.95%) |
| | zulu17.54.21 | 3491.891 | 1513.468 (43.34%) | 1545.27 (44.25%) | 1225.654 (35.1%) |
| | jdk-21.0.2 | 3335.353 | 1352.948 (40.56%) | 1667.619 (50%) | 1122.798 (33.66%) |
| | graalvm_21+35.1 | 3690.406 | 1892.493 (51.28%) | 1727.186 (46.8%) | 1361.99 (36.91%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 1627.579 | 836.701 (51.41%) | 1147.507 (70.5%) | 757.185 (46.52%) |
| | jdk-11.0.19 | 2023.96 | 919.593 (45.44%) | 1168.773 (57.75%) | 771.608 (38.12%) |
| | jdk-17.0.7 | 2197.923 | 1097.116 (49.92%) | 1276.757 (58.09%) | 766.22 (34.86%) |
| | jdk-21 | 2099.766 | 969.997 (46.2%) | 1155.845 (55.05%) | 748.579 (35.65%) |
| | graalvm_21+35.1 | 2220.306 | 1196.103 (53.87%) | 1211.961 (54.59%) | 860.51 (38.76%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 444.894 | 223.736 (50.29%) | 311.076 (69.92%) | 193.254 (43.44%) |
| | jdk-11.0.20 | 578.916 | 258.33 (44.62%) | 324.291 (56.02%) | 207.809 (35.9%) |
| | jdk-17.0.8 | 674.613 | 296.902 (44.01%) | 383.907 (56.91%) | 206.258 (30.57%) |
| | jdk-21.0.2 | 661.424 | 257.061 (38.86%) | 388.765 (58.78%) | 207.267 (31.34%) |
| | graalvm_21+35.1 | 680.125 | 330.3 (48.56%) | 346.497 (50.95%) | 202.992 (29.85%) |
| MacBookM1Pro | zulu-8.jdk | 10556.727 | 4583.079 (43.41%) | 5064.838 (47.98%) | 4429.154 (41.96%) |
| | zulu-11.jdk | 6162.342 | 3146.409 (51.06%) | 3342.078 (54.23%) | 2944.384 (47.78%) |
| | zulu-17.jdk | 13522.584 | 5368.963 (39.7%) | 5584.576 (41.3%) | 4227.026 (31.26%) |
| | zulu-21.jdk | 13160.806 | 4764.947 (36.21%) | 5344.315 (40.61%) | 3995.525 (30.36%) |
| | graalvm_21+35.1 | 13804.455 | 6179.808 (44.77%) | 5406.434 (39.16%) | 4494.591 (32.56%) |
## 11. [EishayParseTreeUTF8BytesPretty](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayParseTreeUTF8BytesPretty.java)
这个场景是将格式化过的字符串UTF8编码的byte[]数组反序列化解析为JSONObject或者HashMap不涉及绑定JavaBean对象。
| aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
|-----|-----|----------|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 1953.3 | 1147.9 (58.77%) | 1684.457 (86.24%) | 948.637 (48.57%) |
| | jdk-11.0.20 | 1952.858 | 896.697 (45.92%) | 1399.214 (71.65%) | 1047.829 (53.66%) |
| | jdk-17.0.8 | 2459.404 | 1149.262 (46.73%) | 1567.554 (63.74%) | 1050.821 (42.73%) |
| | jdk-21.0.2 | 2466.753 | 1182.355 (47.93%) | 1631.821 (66.15%) | 1034.159 (41.92%) |
| | graalvm_21+35.1 | 2675.403 | 1359.617 (50.82%) | 1551.258 (57.98%) | 1238.635 (46.3%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 1162.597 | 754.449 (64.89%) | 1007.004 (86.62%) | 572.332 (49.23%) |
| | jdk-11.0.20 | 1252.794 | 670.283 (53.5%) | 877.666 (70.06%) | 579.181 (46.23%) |
| | jdk-17.0.8 | 1797.614 | 922.89 (51.34%) | 1013.695 (56.39%) | 728.421 (40.52%) |
| | jdk-21.0.2 | 1930.449 | 909.191 (47.1%) | 1049.968 (54.39%) | 706.127 (36.58%) |
| | graalvm_21+35.1 | 1711.965 | 1079.461 (63.05%) | 1106.305 (64.62%) | 873.709 (51.04%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 2102.733 | 1141.877 (54.3%) | 1403.776 (66.76%) | 1082.574 (51.48%) |
| | jdk-11.0.20 | 2743.292 | 1199.342 (43.72%) | 1550.114 (56.51%) | 1108.903 (40.42%) |
| | zulu17.54.21 | 2842.885 | 1319.114 (46.4%) | 1600.127 (56.29%) | 1158.307 (40.74%) |
| | jdk-21.0.2 | 2684.352 | 1179.838 (43.95%) | 1440.627 (53.67%) | 1060.592 (39.51%) |
| | graalvm_21+35.1 | 2968.966 | 1618.34 (54.51%) | 1625.485 (54.75%) | 1230.695 (41.45%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 1474.987 | 758.744 (51.44%) | 1239.552 (84.04%) | 689.382 (46.74%) |
| | jdk-11.0.19 | 1735.069 | 740.625 (42.69%) | 1174.069 (67.67%) | 717.63 (41.36%) |
| | jdk-17.0.7 | 1844.011 | 946.042 (51.3%) | 1206.418 (65.42%) | 728.204 (39.49%) |
| | jdk-21 | 1798.895 | 807.71 (44.9%) | 1055.527 (58.68%) | 701.999 (39.02%) |
| | graalvm_21+35.1 | 1855.469 | 1005.468 (54.19%) | 1110.977 (59.88%) | 820.787 (44.24%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 407.33 | 186.605 (45.81%) | 257.797 (63.29%) | 163.81 (40.22%) |
| | jdk-11.0.20 | 522.745 | 208.81 (39.94%) | 307.826 (58.89%) | 185.537 (35.49%) |
| | jdk-17.0.8 | 563.691 | 269.235 (47.76%) | 349.792 (62.05%) | 197.388 (35.02%) |
| | jdk-21.0.2 | 584.655 | 215.577 (36.87%) | 352.563 (60.3%) | 181.979 (31.13%) |
| | graalvm_21+35.1 | 556.843 | 284.886 (51.16%) | 296.597 (53.26%) | 198.193 (35.59%) |
| MacBookM1Pro | zulu-8.jdk | 9364.794 | 4342.484 (46.37%) | 4697.815 (50.16%) | 3858.513 (41.2%) |
| | zulu-11.jdk | 5455.182 | 2734.904 (50.13%) | 3199.528 (58.65%) | 2790.62 (51.16%) |
| | zulu-17.jdk | 10775.057 | 4201.524 (38.99%) | 5073.577 (47.09%) | 4266.324 (39.59%) |
| | zulu-21.jdk | 10676.415 | 4211.782 (39.45%) | 4987.316 (46.71%) | 4105.915 (38.46%) |
| | graalvm_21+35.1 | 10812.529 | 4902.497 (45.34%) | 4974.673 (46.01%) | 4771.116 (44.13%) |
## 12. [EishayParseUTF8Bytes](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayParseUTF8Bytes.java)
这个场景是将没有格式化的JSON字符串UTF8编码的byte[]数组反序列化为JavaBean对象是最常用的场景这个是fastjson1的强项。
| aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
|-----|-----|----------|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 3063.868 | 2505.316 (81.77%) | 1596.911 (52.12%) | 1169.166 (38.16%) |
| | jdk-11.0.20 | 3225.973 | 2227.777 (69.06%) | 1572.418 (48.74%) | 1307.113 (40.52%) |
| | jdk-17.0.8 | 5815.149 | 2821.138 (48.51%) | 1616.422 (27.8%) | 1359.585 (23.38%) |
| | jdk-21.0.2 | 5687.206 | 2805.258 (49.33%) | 1500.952 (26.39%) | 1145.667 (20.14%) |
| | graalvm_21+35.1 | 8307.753 | 3501.172 (42.14%) | 1464.36 (17.63%) | 1337.681 (16.1%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 1590.372 | 1615.834 (101.6%) | 1049.581 (66%) | 755.697 (47.52%) |
| | jdk-11.0.20 | 1501.809 | 1452.13 (96.69%) | 977.312 (65.08%) | 787.107 (52.41%) |
| | jdk-17.0.8 | 4003.545 | 2068.743 (51.67%) | 1093.395 (27.31%) | 984.493 (24.59%) |
| | jdk-21.0.2 | 4038.521 | 2118.52 (52.46%) | 1083.426 (26.83%) | 895.263 (22.17%) |
| | graalvm_21+35.1 | 4570.167 | 2638.786 (57.74%) | 1133.875 (24.81%) | 1005.202 (21.99%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 2137.024 | 3153.846 (147.58%) | 1776.151 (83.11%) | 1448.833 (67.8%) |
| | jdk-11.0.20 | 1966.894 | 2867.452 (145.79%) | 1608.301 (81.77%) | 1399.962 (71.18%) |
| | zulu17.54.21 | 6068.411 | 3731.147 (61.48%) | 1689.168 (27.84%) | 1500.416 (24.73%) |
| | jdk-21.0.2 | 6146.302 | 3598.29 (58.54%) | 1551.078 (25.24%) | 1378.058 (22.42%) |
| | graalvm_21+35.1 | 7709.805 | 3259.734 (42.28%) | 1512.587 (19.62%) | 1322.974 (17.16%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 2262.245 | 1966.811 (86.94%) | 1341.156 (59.28%) | 898.499 (39.72%) |
| | jdk-11.0.19 | 2792.963 | 1976.833 (70.78%) | 1218.547 (43.63%) | 954.024 (34.16%) |
| | jdk-17.0.7 | 4249.664 | 2540.636 (59.78%) | 1294.69 (30.47%) | 971.632 (22.86%) |
| | jdk-21 | 4244.942 | 2489.342 (58.64%) | 1155.456 (27.22%) | 857.172 (20.19%) |
| | graalvm_21+35.1 | 5431.706 | 2217.584 (40.83%) | 1084.107 (19.96%) | 906.659 (16.69%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 587.709 | 594.978 (101.24%) | 323.141 (54.98%) | 232.709 (39.6%) |
| | jdk-11.0.20 | 585.494 | 561.844 (95.96%) | 328.164 (56.05%) | 242.748 (41.46%) |
| | jdk-17.0.8 | 1118.562 | 749.085 (66.97%) | 347.069 (31.03%) | 263.74 (23.58%) |
| | jdk-21.0.2 | 1194.227 | 724.083 (60.63%) | 319.126 (26.72%) | 224.516 (18.8%) |
| | graalvm_21+35.1 | 1494.579 | 616.593 (41.26%) | 284.367 (19.03%) | 246.488 (16.49%) |
| MacBookM1Pro | zulu-8.jdk | 2399.998 | 10895.15 (453.96%) | 5432.326 (226.35%) | 4977.114 (207.38%) |
| | zulu-11.jdk | 14232.813 | 6301.228 (44.27%) | 3620.76 (25.44%) | 3606.921 (25.34%) |
| | zulu-17.jdk | 20647.186 | 12714.671 (61.58%) | 5281.183 (25.58%) | 5491.613 (26.6%) |
| | zulu-21.jdk | 19701.152 | 12662.735 (64.27%) | 5732.542 (29.1%) | 5239.018 (26.59%) |
| | graalvm_21+35.1 | 20943.038 | 10884.172 (51.97%) | 5231.966 (24.98%) | 4838.174 (23.1%) |
## 13. [EishayParseUTF8BytesPretty](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayParseUTF8BytesPretty.java)
这个场景是将格式化过的JSON字符串UTF8编码的byte[]数组反序列化为JavaBean对象
| aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
|-----|-----|----------|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 2654.545 | 796.77 (30.02%) | 1513.804 (57.03%) | 946.27 (35.65%) |
| | jdk-11.0.20 | 3574.55 | 694.235 (19.42%) | 1356.503 (37.95%) | 1023.925 (28.64%) |
| | jdk-17.0.8 | 4310.284 | 827.965 (19.21%) | 1438.538 (33.37%) | 1042.799 (24.19%) |
| | jdk-21.0.2 | 4424.02 | 812.08 (18.36%) | 1358.425 (30.71%) | 1032.703 (23.34%) |
| | graalvm_21+35.1 | 4046.554 | 990.39 (24.47%) | 1343.38 (33.2%) | 1240.27 (30.65%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 1542.285 | 474.451 (30.76%) | 914.718 (59.31%) | 568.788 (36.88%) |
| | jdk-11.0.20 | 1513.998 | 458.2 (30.26%) | 862.579 (56.97%) | 582.461 (38.47%) |
| | jdk-17.0.8 | 2873.527 | 584.935 (20.36%) | 980.281 (34.11%) | 720.855 (25.09%) |
| | jdk-21.0.2 | 3002.618 | 590.049 (19.65%) | 979.57 (32.62%) | 715.556 (23.83%) |
| | graalvm_21+35.1 | 2713.729 | 785.592 (28.95%) | 999.2 (36.82%) | 861.111 (31.73%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 2484.825 | 945.759 (38.06%) | 1608.424 (64.73%) | 1057.933 (42.58%) |
| | jdk-11.0.20 | 4321.337 | 945.063 (21.87%) | 1505.855 (34.85%) | 1093.531 (25.31%) |
| | zulu17.54.21 | 4323.814 | 1041.152 (24.08%) | 1566.545 (36.23%) | 1142.164 (26.42%) |
| | jdk-21.0.2 | 4176.668 | 937.826 (22.45%) | 1495.679 (35.81%) | 1090.071 (26.1%) |
| | graalvm_21+35.1 | 4694.087 | 1161.832 (24.75%) | 1344.718 (28.65%) | 1218.713 (25.96%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 2653.751 | 617.703 (23.28%) | 1223.916 (46.12%) | 682.651 (25.72%) |
| | jdk-11.0.19 | 3121.485 | 622.813 (19.95%) | 1128.254 (36.14%) | 730.467 (23.4%) |
| | jdk-17.0.7 | 3223.377 | 713.971 (22.15%) | 1189.784 (36.91%) | 727.152 (22.56%) |
| | jdk-21 | 3152.167 | 608.973 (19.32%) | 1079.459 (34.24%) | 697.616 (22.13%) |
| | graalvm_21+35.1 | 3531.94 | 736.204 (20.84%) | 958.954 (27.15%) | 830.232 (23.51%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 510.342 | 153.439 (30.07%) | 286.51 (56.14%) | 165.507 (32.43%) |
| | jdk-11.0.20 | 658.081 | 160.035 (24.32%) | 294.408 (44.74%) | 194.642 (29.58%) |
| | jdk-17.0.8 | 849.633 | 187.074 (22.02%) | 329.936 (38.83%) | 198.617 (23.38%) |
| | jdk-21.0.2 | 923.354 | 156.223 (16.92%) | 282.091 (30.55%) | 183.306 (19.85%) |
| | graalvm_21+35.1 | 909.517 | 197.183 (21.68%) | 258.378 (28.41%) | 197.857 (21.75%) |
| MacBookM1Pro | zulu-8.jdk | 13994.076 | 3316.416 (23.7%) | 4454.25 (31.83%) | 3951.748 (28.24%) |
| | zulu-11.jdk | 2087.171 | 2056.432 (98.53%) | 2965.971 (142.1%) | 3214.822 (154.03%) |
| | zulu-17.jdk | 15317.272 | 3054.288 (19.94%) | 5153.223 (33.64%) | 4248.597 (27.74%) |
| | zulu-21.jdk | 15187.331 | 3302.901 (21.75%) | 5120.742 (33.72%) | 4116.484 (27.1%) |
| | graalvm_21+35.1 | 3022.647 | 3930.375 (130.03%) | 4737.568 (156.74%) | 4730.325 (156.5%) |
## 14. [EishayWriteBinary](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayWriteBinary.java)
这个场景是二进制序列化比较JSONB格式、JSON UTF8编码(fastjson2UTF8Bytes)、hessian、javaSerialize的比较用于[Apache dubbo](https://github.com/apache/dubbo)的用户选择二进制协议比较
| aliyun ecs spec | jdk version | jsonb | msgpack | protobuf |
|-----|-----|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 10978.072 | 1529.138 (13.93%) | 4895.32 (44.59%) |
| | jdk-11.0.20 | 14080.385 | 1715.404 (12.18%) | 4122.797 (29.28%) |
| | jdk-17.0.8 | 16332.72 | 1800.954 (11.03%) | 5801.567 (35.52%) |
| | jdk-21.0.2 | 16171.177 | 1647.287 (10.19%) | 5404.928 (33.42%) |
| | graalvm_21+35.1 | 14865.073 | 1872.337 (12.6%) | 10324.822 (69.46%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 6576.721 | 1055.226 (16.04%) | 2757.353 (41.93%) |
| | jdk-11.0.20 | 8329.695 | 1164.315 (13.98%) | 2486.346 (29.85%) |
| | jdk-17.0.8 | 11857.402 | 1458.37 (12.3%) | 3559.534 (30.02%) |
| | jdk-21.0.2 | 12872.412 | 1480.039 (11.5%) | 3945.032 (30.65%) |
| | graalvm_21+35.1 | 11715.182 | 1521.023 (12.98%) | 6913.999 (59.02%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 9490.15 | 1556.343 (16.4%) | 4986.336 (52.54%) |
| | jdk-11.0.20 | 12931.291 | 1795.238 (13.88%) | 4007.493 (30.99%) |
| | zulu17.54.21 | 12897.762 | 1963.118 (15.22%) | 5229.348 (40.54%) |
| | jdk-21.0.2 | 15520.389 | 1824.757 (11.76%) | 5799.135 (37.36%) |
| | graalvm_21+35.1 | 17278.959 | 1960.812 (11.35%) | 10239.193 (59.26%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 7363.433 | 1042.337 (14.16%) | 3134.894 (42.57%) |
| | jdk-11.0.19 | 9152.757 | 1234.183 (13.48%) | 2705.186 (29.56%) |
| | jdk-17.0.7 | 9316.167 | 1248.343 (13.4%) | 4376.876 (46.98%) |
| | jdk-21 | 8393.721 | 1175.246 (14%) | 3897.929 (46.44%) |
| | graalvm_21+35.1 | 10265.569 | 1244.659 (12.12%) | 6281.014 (61.19%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 2215.58 | 281.069 (12.69%) | 966.814 (43.64%) |
| | jdk-11.0.20 | 2333.41 | 335.347 (14.37%) | 719.032 (30.81%) |
| | jdk-17.0.8 | 2897.464 | 358.386 (12.37%) | 963.89 (33.27%) |
| | jdk-21.0.2 | 2600.15 | 330.976 (12.73%) | 940.353 (36.17%) |
| | graalvm_21+35.1 | 3272.253 | 345.388 (10.56%) | 2025.808 (61.91%) |
| MacBookM1Pro | zulu-8.jdk | 26605.264 | 5164.322 (19.41%) | 14593.309 (54.85%) |
| | zulu-11.jdk | 24617.033 | 4221.352 (17.15%) | 10554.26 (42.87%) |
| | zulu-17.jdk | 28298.102 | 7481.953 (26.44%) | 18339.847 (64.81%) |
| | zulu-21.jdk | 34626.421 | 6791.959 (19.61%) | 18687.684 (53.97%) |
| | graalvm_21+35.1 | 61375.957 | 7735.585 (12.6%) | 38034.724 (61.97%) |
## 15. [EishayWriteBinaryArrayMapping](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayWriteBinaryArrayMapping.java)
这个场景是二进制序列化比较JSONB格式基于字段顺序映射、kryo、protobuf的比较
| aliyun ecs spec | jdk version | jsonb | kryo | protobuf |
|-----|-----|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 13049.529 | 4858.049 (37.23%) | 4520.915 (34.64%) |
| | jdk-11.0.20 | 15367.953 | 4850.996 (31.57%) | 5246.393 (34.14%) |
| | jdk-17.0.8 | 18457.892 | 5161.847 (27.97%) | 5456.177 (29.56%) |
| | jdk-21.0.2 | 17488.156 | 5487.991 (31.38%) | 6115.866 (34.97%) |
| | graalvm_21+35.1 | 15905.932 | 6098.94 (38.34%) | 11169.41 (70.22%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 8103.662 | 3338.215 (41.19%) | 2805.578 (34.62%) |
| | jdk-11.0.20 | 10944.955 | 2918.732 (26.67%) | 2846.622 (26.01%) |
| | jdk-17.0.8 | 12570.421 | 4228.401 (33.64%) | 3617.76 (28.78%) |
| | jdk-21.0.2 | 13367.971 | 4286.696 (32.07%) | 3843.518 (28.75%) |
| | graalvm_21+35.1 | 10772.437 | 5746.715 (53.35%) | 6570.509 (60.99%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 10713.017 | 5896.777 (55.04%) | 5325.764 (49.71%) |
| | jdk-11.0.20 | 11514.857 | 5430.873 (47.16%) | 6043.079 (52.48%) |
| | zulu17.54.21 | 17914.945 | 6813.867 (38.03%) | 5316.436 (29.68%) |
| | jdk-21.0.2 | 13839.157 | 6466.334 (46.72%) | 5908.201 (42.69%) |
| | graalvm_21+35.1 | 18254.669 | 7738.679 (42.39%) | 10668.106 (58.44%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 9248.488 | 2986.516 (32.29%) | 3399.378 (36.76%) |
| | jdk-11.0.19 | 10457.314 | 3218.583 (30.78%) | 3641.059 (34.82%) |
| | jdk-17.0.7 | 10683.995 | 3950.35 (36.97%) | 3728.323 (34.9%) |
| | jdk-21 | 10496.989 | 3148.017 (29.99%) | 3527.955 (33.61%) |
| | graalvm_21+35.1 | 11436.425 | 4246.28 (37.13%) | 6750.05 (59.02%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 2486.519 | 1152.523 (46.35%) | 920.547 (37.02%) |
| | jdk-11.0.20 | 3240.204 | 1049.391 (32.39%) | 698.794 (21.57%) |
| | jdk-17.0.8 | 3608.658 | 1103.483 (30.58%) | 1004.428 (27.83%) |
| | jdk-21.0.2 | 3616.0 | 1094.016 (30.25%) | 961.454 (26.59%) |
| | graalvm_21+35.1 | 3830.318 | 1335.94 (34.88%) | 2065.592 (53.93%) |
| MacBookM1Pro | zulu-8.jdk | 32625.564 | 9755.379 (29.9%) | 15854.818 (48.6%) |
| | zulu-11.jdk | 35145.4 | 7151.97 (20.35%) | 9352.752 (26.61%) |
| | zulu-17.jdk | 59322.145 | 14206.772 (23.95%) | 18624.436 (31.4%) |
| | zulu-21.jdk | 64268.743 | 9169.334 (14.27%) | 22130.493 (34.43%) |
| | graalvm_21+35.1 | 31322.342 | 12941.621 (41.32%) | 37557.897 (119.91%) |
## 16. [EishayWriteBinaryAutoType](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayWriteBinaryAutoType.java)
这个场景是带类型信息二进制序列化比较JSONB格式、JSON UTF8编码(fastjson2UTF8Bytes)、hessian、javaSerialize的比较用于[Apache dubbo](https://github.com/apache/dubbo)的用户选择二进制协议比较
| aliyun ecs spec | jdk version | fastjson2JSONB | hessian | javaSerialize |
|-----|-----|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 4370.273 | 1351.365 (30.92%) | 809.637 (18.53%) |
| | jdk-11.0.20 | 4531.622 | 1242.753 (27.42%) | 766.428 (16.91%) |
| | jdk-17.0.8 | 5657.981 | 1228.478 (21.71%) | 783.861 (13.85%) |
| | jdk-21.0.2 | 6050.163 | 1280.194 (21.16%) | 812.722 (13.43%) |
| | graalvm_21+35.1 | 5288.358 | 1709.57 (32.33%) | 767.865 (14.52%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 2842.7 | 640.067 (22.52%) | 454.281 (15.98%) |
| | jdk-11.0.20 | 2791.95 | 588.095 (21.06%) | 414.281 (14.84%) |
| | jdk-17.0.8 | 3856.884 | 788.68 (20.45%) | 541.43 (14.04%) |
| | jdk-21.0.2 | 3909.541 | 828.174 (21.18%) | 558.695 (14.29%) |
| | graalvm_21+35.1 | 4033.344 | 1161.774 (28.8%) | 575.249 (14.26%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 5344.271 | 1391.112 (26.03%) | 873.439 (16.34%) |
| | jdk-11.0.20 | 5897.08 | 1022.158 (17.33%) | 939.387 (15.93%) |
| | zulu17.54.21 | 5602.546 | 1265.529 (22.59%) | 870.203 (15.53%) |
| | jdk-21.0.2 | 6042.662 | 1252.779 (20.73%) | 926.416 (15.33%) |
| | graalvm_21+35.1 | 5875.516 | 1232.62 (20.98%) | 846.858 (14.41%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 3847.048 | 655.559 (17.04%) | 588.547 (15.3%) |
| | jdk-11.0.19 | 3824.453 | 646.157 (16.9%) | 609.885 (15.95%) |
| | jdk-17.0.7 | 3520.23 | 653.106 (18.55%) | 558.6 (15.87%) |
| | jdk-21 | 3598.671 | 644.879 (17.92%) | 609.278 (16.93%) |
| | graalvm_21+35.1 | 3880.506 | 629.372 (16.22%) | 560.906 (14.45%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 1069.386 | 262.37 (24.53%) | 162.075 (15.16%) |
| | jdk-11.0.20 | 1237.563 | 221.359 (17.89%) | 167.233 (13.51%) |
| | jdk-17.0.8 | 896.722 | 234.17 (26.11%) | 164.72 (18.37%) |
| | jdk-21.0.2 | 1018.688 | 230.94 (22.67%) | 162.507 (15.95%) |
| | graalvm_21+35.1 | 1102.406 | 264.919 (24.03%) | 123.568 (11.21%) |
| MacBookM1Pro | zulu-8.jdk | 17310.798 | 2370.854 (13.7%) | 3304.574 (19.09%) |
| | zulu-11.jdk | 12304.878 | 2261.085 (18.38%) | 1858.589 (15.1%) |
| | zulu-17.jdk | 20150.108 | 2116.059 (10.5%) | 3460.111 (17.17%) |
| | zulu-21.jdk | 20731.54 | 2176.334 (10.5%) | 3775.7 (18.21%) |
| | graalvm_21+35.1 | 19661.769 | 2779.258 (14.14%) | 3524.893 (17.93%) |
## 17. [EishayWriteString](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayWriteString.java)
这个场景是将JavaBean对象序列化为字符串
| aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
|-----|-----|----------|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 6271.686 | 1892.83 (30.18%) | 2267.069 (36.15%) | 1306.957 (20.84%) |
| | jdk-11.0.20 | 6518.359 | 1852.956 (28.43%) | 2522.58 (38.7%) | 829.993 (12.73%) |
| | jdk-17.0.8 | 6840.802 | 1935.612 (28.3%) | 2753.834 (40.26%) | 1161.99 (16.99%) |
| | jdk-21.0.2 | 6558.849 | 1809.819 (27.59%) | 2462.226 (37.54%) | 1074.491 (16.38%) |
| | graalvm_21+35.1 | 9972.026 | 2396.37 (24.03%) | 2650.01 (26.57%) | 1020.943 (10.24%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 3572.891 | 1284.643 (35.96%) | 1917.17 (53.66%) | 866.451 (24.25%) |
| | jdk-11.0.20 | 4085.341 | 1157.17 (28.32%) | 1734.937 (42.47%) | 713.774 (17.47%) |
| | jdk-17.0.8 | 4346.393 | 1484.155 (34.15%) | 2111.985 (48.59%) | 700.681 (16.12%) |
| | jdk-21.0.2 | 4500.974 | 1537.353 (34.16%) | 2002.28 (44.49%) | 683.052 (15.18%) |
| | graalvm_21+35.1 | 6792.343 | 1701.319 (25.05%) | 2040.889 (30.05%) | 647.259 (9.53%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 5553.856 | 2194.069 (39.51%) | 2598.167 (46.78%) | 1658.773 (29.87%) |
| | jdk-11.0.20 | 6372.355 | 2444.672 (38.36%) | 2853.192 (44.77%) | 1321.002 (20.73%) |
| | zulu17.54.21 | 7044.599 | 3092.509 (43.9%) | 2905.78 (41.25%) | 906.772 (12.87%) |
| | jdk-21.0.2 | 6560.721 | 1997.14 (30.44%) | 2778.564 (42.35%) | 880.396 (13.42%) |
| | graalvm_21+35.1 | 8824.868 | 2865.189 (32.47%) | 2854.476 (32.35%) | 858.811 (9.73%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 4248.536 | 1835.022 (43.19%) | 1760.934 (41.45%) | 930.691 (21.91%) |
| | jdk-11.0.19 | 4445.314 | 1767.386 (39.76%) | 1761.563 (39.63%) | 828.049 (18.63%) |
| | jdk-17.0.7 | 5181.561 | 1491.746 (28.79%) | 1937.875 (37.4%) | 756.101 (14.59%) |
| | jdk-21 | 5088.634 | 1289.9 (25.35%) | 1679.428 (33%) | 707.06 (13.89%) |
| | graalvm_21+35.1 | 6222.255 | 1653.168 (26.57%) | 1821.68 (29.28%) | 672.161 (10.8%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 1303.355 | 360.305 (27.64%) | 442.291 (33.93%) | 267.365 (20.51%) |
| | jdk-11.0.20 | 1395.305 | 344.245 (24.67%) | 422.973 (30.31%) | 206.388 (14.79%) |
| | jdk-17.0.8 | 1656.203 | 377.502 (22.79%) | 494.534 (29.86%) | 111.665 (6.74%) |
| | jdk-21.0.2 | 1436.685 | 418.384 (29.12%) | 494.269 (34.4%) | 106.309 (7.4%) |
| | graalvm_21+35.1 | 2182.283 | 464.575 (21.29%) | 500.92 (22.95%) | 102.859 (4.71%) |
| MacBookM1Pro | zulu-8.jdk | 19923.085 | 7815.579 (39.23%) | 11646.2 (58.46%) | 5709.965 (28.66%) |
| | zulu-11.jdk | 15230.68 | 4870.81 (31.98%) | 6289.873 (41.3%) | 2477.822 (16.27%) |
| | zulu-17.jdk | 23307.616 | 10919.949 (46.85%) | 11247.543 (48.26%) | 4258.909 (18.27%) |
| | zulu-21.jdk | 21634.396 | 7009.146 (32.4%) | 9719.862 (44.93%) | 4195.627 (19.39%) |
| | graalvm_21+35.1 | 30984.324 | 8447.511 (27.26%) | 9976.627 (32.2%) | 3372.05 (10.88%) |
## 18. [EishayWriteStringTree](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayWriteStringTree.java)
这个场景是将JSONObject或者Map序列化为字符串
| aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
|-----|-----|----------|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 4106.526 | 2297.505 (55.95%) | 2382.412 (58.02%) | 1381.002 (33.63%) |
| | jdk-11.0.20 | 4060.071 | 2269.513 (55.9%) | 2389.022 (58.84%) | 888.211 (21.88%) |
| | jdk-17.0.8 | 3917.297 | 2262.023 (57.74%) | 2551.362 (65.13%) | 1246.672 (31.82%) |
| | jdk-21.0.2 | 4087.614 | 2289.681 (56.02%) | 2477.236 (60.6%) | 1236.383 (30.25%) |
| | graalvm_21+35.1 | 5309.658 | 2611.658 (49.19%) | 2688.493 (50.63%) | 1156.643 (21.78%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 3014.444 | 1613.145 (53.51%) | 1735.196 (57.56%) | 894.483 (29.67%) |
| | jdk-11.0.20 | 2834.014 | 1504.463 (53.09%) | 1664.508 (58.73%) | 710.294 (25.06%) |
| | jdk-17.0.8 | 3567.543 | 1832.707 (51.37%) | 1843.684 (51.68%) | 735.027 (20.6%) |
| | jdk-21.0.2 | 3708.678 | 2002.352 (53.99%) | 1863.345 (50.24%) | 728.633 (19.65%) |
| | graalvm_21+35.1 | 4120.584 | 1792.804 (43.51%) | 1989.994 (48.29%) | 674.569 (16.37%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 3558.925 | 2441.211 (68.59%) | 2605.8 (73.22%) | 1828.804 (51.39%) |
| | jdk-11.0.20 | 4220.738 | 2666.828 (63.18%) | 2726.283 (64.59%) | 1384.697 (32.81%) |
| | zulu17.54.21 | 4272.723 | 2663.729 (62.34%) | 2569.578 (60.14%) | 956.709 (22.39%) |
| | jdk-21.0.2 | 5522.927 | 2691.079 (48.73%) | 2799.098 (50.68%) | 990.251 (17.93%) |
| | graalvm_21+35.1 | 6492.052 | 2998.703 (46.19%) | 3021.284 (46.54%) | 912.169 (14.05%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 2511.286 | 1600.338 (63.73%) | 1769.621 (70.47%) | 1053.216 (41.94%) |
| | jdk-11.0.19 | 3044.611 | 1558.262 (51.18%) | 1775.902 (58.33%) | 926.139 (30.42%) |
| | jdk-17.0.7 | 2866.115 | 1655.3 (57.75%) | 1865.051 (65.07%) | 794.956 (27.74%) |
| | jdk-21 | 3379.355 | 1514.789 (44.82%) | 1667.254 (49.34%) | 793.43 (23.48%) |
| | graalvm_21+35.1 | 3612.972 | 1805.47 (49.97%) | 1991.044 (55.11%) | 762.542 (21.11%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 752.301 | 440.251 (58.52%) | 534.671 (71.07%) | 306.906 (40.8%) |
| | jdk-11.0.20 | 901.628 | 435.41 (48.29%) | 470.173 (52.15%) | 256.512 (28.45%) |
| | jdk-17.0.8 | 785.223 | 408.653 (52.04%) | 559.089 (71.2%) | 110.337 (14.05%) |
| | jdk-21.0.2 | 966.555 | 418.473 (43.3%) | 510.631 (52.83%) | 115.576 (11.96%) |
| | graalvm_21+35.1 | 1198.964 | 535.695 (44.68%) | 591.421 (49.33%) | 117.233 (9.78%) |
| MacBookM1Pro | zulu-8.jdk | 13726.928 | 9301.78 (67.76%) | 11038.807 (80.42%) | 6105.049 (44.47%) |
| | zulu-11.jdk | 9788.557 | 5940.308 (60.69%) | 5169.242 (52.81%) | 2718.558 (27.77%) |
| | zulu-17.jdk | 11389.098 | 8838.94 (77.61%) | 7365.792 (64.67%) | 4230.433 (37.14%) |
| | zulu-21.jdk | 14383.13 | 7980.704 (55.49%) | 8842.316 (61.48%) | 4308.389 (29.95%) |
| | graalvm_21+35.1 | 14487.762 | 9173.243 (63.32%) | 9875.866 (68.17%) | 3437.8 (23.73%) |
## 19. [EishayWriteUTF8Bytes](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayWriteUTF8Bytes.java)
这个场景是将JavaBean对象序列化为UTF8编码的Bytes
| aliyun ecs spec | jdk version | fastjson2 | fastjson1 | jackson | gson |
|-----|-----|----------|----------|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 5734.153 | 1705.292 (29.74%) | 2501.566 (43.63%) | 1163.873 (20.3%) |
| | jdk-11.0.20 | 6962.422 | 2264.804 (32.53%) | 2288.375 (32.87%) | 838.678 (12.05%) |
| | jdk-17.0.8 | 8622.983 | 1722.046 (19.97%) | 2558.74 (29.67%) | 1144.645 (13.27%) |
| | jdk-21.0.2 | 8363.914 | 1708.909 (20.43%) | 2563.649 (30.65%) | 1074.212 (12.84%) |
| | graalvm_21+35.1 | 9380.145 | 1996.926 (21.29%) | 2872.223 (30.62%) | 1063.176 (11.33%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 3587.114 | 1159.354 (32.32%) | 1722.067 (48.01%) | 701.103 (19.55%) |
| | jdk-11.0.20 | 4580.489 | 1075.264 (23.47%) | 1618.769 (35.34%) | 612.057 (13.36%) |
| | jdk-17.0.8 | 5389.43 | 1355.99 (25.16%) | 1912.813 (35.49%) | 697.967 (12.95%) |
| | jdk-21.0.2 | 5559.484 | 1402.199 (25.22%) | 2217.57 (39.89%) | 694.77 (12.5%) |
| | graalvm_21+35.1 | 6849.174 | 1543.6 (22.54%) | 2310.68 (33.74%) | 663.484 (9.69%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 6185.25 | 2196.801 (35.52%) | 2909.139 (47.03%) | 1378.328 (22.28%) |
| | jdk-11.0.20 | 6946.725 | 1978.262 (28.48%) | 2511.213 (36.15%) | 1292.639 (18.61%) |
| | zulu17.54.21 | 7392.456 | 2034.732 (27.52%) | 2883.209 (39%) | 927.63 (12.55%) |
| | jdk-21.0.2 | 7774.184 | 1892.906 (24.35%) | 2670.244 (34.35%) | 908.876 (11.69%) |
| | graalvm_21+35.1 | 9209.203 | 2164.77 (23.51%) | 3088.673 (33.54%) | 862.43 (9.36%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 5101.615 | 1199.569 (23.51%) | 1937.925 (37.99%) | 805.367 (15.79%) |
| | jdk-11.0.19 | 4732.961 | 1171.283 (24.75%) | 1636.302 (34.57%) | 754.159 (15.93%) |
| | jdk-17.0.7 | 4919.902 | 1238.358 (25.17%) | 1921.304 (39.05%) | 721.362 (14.66%) |
| | jdk-21 | 5056.646 | 1229.235 (24.31%) | 1692.171 (33.46%) | 692.957 (13.7%) |
| | graalvm_21+35.1 | 6520.234 | 1686.952 (25.87%) | 1928.451 (29.58%) | 659.763 (10.12%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 1360.643 | 340.932 (25.06%) | 457.811 (33.65%) | 234.474 (17.23%) |
| | jdk-11.0.20 | 1417.944 | 315.748 (22.27%) | 431.087 (30.4%) | 194.429 (13.71%) |
| | jdk-17.0.8 | 1609.777 | 378.787 (23.53%) | 501.841 (31.17%) | 107.872 (6.7%) |
| | jdk-21.0.2 | 1737.072 | 333.279 (19.19%) | 467.85 (26.93%) | 107.299 (6.18%) |
| | graalvm_21+35.1 | 1902.585 | 433.319 (22.78%) | 477.457 (25.1%) | 90.821 (4.77%) |
| MacBookM1Pro | zulu-8.jdk | 19397.268 | 7709.675 (39.75%) | 10136.534 (52.26%) | 4924.437 (25.39%) |
| | zulu-11.jdk | 16608.272 | 5060.709 (30.47%) | 6062.913 (36.51%) | 2691.976 (16.21%) |
| | zulu-17.jdk | 18459.652 | 7301.577 (39.55%) | 9862.421 (53.43%) | 4221.695 (22.87%) |
| | zulu-21.jdk | 22969.074 | 6012.807 (26.18%) | 10226.7 (44.52%) | 4179.211 (18.19%) |
| | graalvm_21+35.1 | 25730.102 | 7834.655 (30.45%) | 10834.127 (42.11%) | 3332.292 (12.95%) |
## 20. [EishayWriteUTF8BytesTree](https://github.com/alibaba/fastjson2/blob/main/benchmark/src/main/java/com/alibaba/fastjson2/benchmark/eishay/EishayWriteUTF8BytesTree.java)
这个场景是将JSONObject或者Map序列化为UTF8编码的Bytes
| aliyun ecs spec | jdk version | fastjson2 | jackson |
|-----|-----|----------|-----|
| aliyun_ecs.c8a.large | jdk1.8.0_381 | 4153.59 | 2510.328 (60.44%) |
| | jdk-11.0.20 | 3568.359 | 2019.207 (56.59%) |
| | jdk-17.0.8 | 4398.154 | 2257.095 (51.32%) |
| | jdk-21.0.2 | 4586.936 | 2512.676 (54.78%) |
| | graalvm_21+35.1 | 4051.224 | 3160.174 (78.01%) |
| [aliyun_ecs.c8i.large](https://help.aliyun.com/zh/ecs/user-guide/compute-optimized-instance-families#c8i) | jdk1.8.0_381 | 2959.891 | 1710.896 (57.8%) |
| | jdk-11.0.20 | 2665.289 | 1450.877 (54.44%) |
| | jdk-17.0.8 | 4041.264 | 1822.421 (45.1%) |
| | jdk-21.0.2 | 3599.322 | 2010.536 (55.86%) |
| | graalvm_21+35.1 | 3088.946 | 2493.35 (80.72%) |
| [aliyun_ecs.g8y.large](https://www.alibabacloud.com/zh/product/ecs/g8y) | zulu8.82.0.21 | 4523.241 | 3339.446 (73.83%) |
| | jdk-11.0.20 | 4420.129 | 2186.682 (49.47%) |
| | zulu17.54.21 | 4529.697 | 2821.828 (62.3%) |
| | jdk-21.0.2 | 5540.168 | 2960.826 (53.44%) |
| | graalvm_21+35.1 | 5211.373 | 3676.996 (70.56%) |
| [orangepi5p](http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5-Pro.html) | zulu8.68.0.21 | 3161.802 | 2025.545 (64.06%) |
| | jdk-11.0.19 | 3172.518 | 1653.801 (52.13%) |
| | jdk-17.0.7 | 3064.329 | 1953.727 (63.76%) |
| | jdk-21 | 3102.282 | 1803.506 (58.13%) |
| | graalvm_21+35.1 | 3317.842 | 2256.421 (68.01%) |
| [orangepi_aipro](http://www.orangepi.cn/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-AIpro.html) | zulu8.82.0.21 | 814.807 | 584.681 (71.76%) |
| | jdk-11.0.20 | 896.227 | 446.951 (49.87%) |
| | jdk-17.0.8 | 901.375 | 573.214 (63.59%) |
| | jdk-21.0.2 | 901.976 | 536.178 (59.44%) |
| | graalvm_21+35.1 | 996.474 | 666.255 (66.86%) |
| MacBookM1Pro | zulu-8.jdk | 12180.316 | 10548.989 (86.61%) |
| | zulu-11.jdk | 10945.307 | 4925.375 (45%) |
| | zulu-17.jdk | 10126.624 | 9109.499 (89.96%) |
| | zulu-21.jdk | 13431.446 | 9747.027 (72.57%) |
| | graalvm_21+35.1 | 15444.614 | 11682.416 (75.64%) |

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId> <artifactId>fastjson2</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -39,7 +39,7 @@
```groovy ```groovy
dependencies { dependencies {
implementation 'com.alibaba.fastjson2:fastjson2:2.0.56' implementation 'com.alibaba.fastjson2:fastjson2:2.0.55'
} }
``` ```
@ -57,7 +57,7 @@ dependencies {
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -65,7 +65,7 @@ dependencies {
```groovy ```groovy
dependencies { dependencies {
implementation 'com.alibaba:fastjson:2.0.56' implementation 'com.alibaba:fastjson:2.0.55'
} }
``` ```
@ -79,7 +79,7 @@ dependencies {
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-kotlin</artifactId> <artifactId>fastjson2-kotlin</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -87,7 +87,7 @@ dependencies {
```kotlin ```kotlin
dependencies { dependencies {
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.56") implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.55")
} }
``` ```
@ -101,7 +101,7 @@ dependencies {
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension</artifactId> <artifactId>fastjson2-extension</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -109,7 +109,7 @@ dependencies {
```groovy ```groovy
dependencies { dependencies {
implementation 'com.alibaba.fastjson2:fastjson2-extension:2.0.56' implementation 'com.alibaba.fastjson2:fastjson2-extension:2.0.55'
} }
``` ```

View File

@ -10,7 +10,7 @@
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-kotlin</artifactId> <artifactId>fastjson2-kotlin</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -35,7 +35,7 @@
```kotlin ```kotlin
dependencies { dependencies {
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.56") implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.55")
} }
``` ```

View File

@ -10,7 +10,7 @@ If your project uses `kotlin`, you can use the` Fastjson-Kotlin` module, and use
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-kotlin</artifactId> <artifactId>fastjson2-kotlin</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -35,7 +35,7 @@ If the data class is used or the parameters are passed in through constructor, t
```kotlin ```kotlin
dependencies { dependencies {
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.56") implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.55")
} }
``` ```

View File

@ -146,5 +146,3 @@
* https://github.com/elunez/eladmin-mp * https://github.com/elunez/eladmin-mp
* https://github.com/LinQi0777/RiskEngine * https://github.com/LinQi0777/RiskEngine
* https://github.com/niujt/Hospital * https://github.com/niujt/Hospital
* https://github.com/xbatis/xbatis
* https://github.com/ageerle/ruoyi-ai

View File

@ -10,7 +10,7 @@ Fastjson2采用多module的结构设计对SpringFramework等框架的支持
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension-spring5</artifactId> <artifactId>fastjson2-extension-spring5</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
or or
@ -18,7 +18,7 @@ or
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension-spring6</artifactId> <artifactId>fastjson2-extension-spring6</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -26,13 +26,13 @@ or
```groovy ```groovy
dependencies { dependencies {
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring5:2.0.56' implementation 'com.alibaba.fastjson2:fastjson2-extension-spring5:2.0.55'
} }
or or
dependencies { dependencies {
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring6:2.0.56' implementation 'com.alibaba.fastjson2:fastjson2-extension-spring6:2.0.55'
} }
``` ```
> 2.0.23版本之后为了兼容Spring 5.x / 6.x将不同版本独立开不同的依赖包。 > 2.0.23版本之后为了兼容Spring 5.x / 6.x将不同版本独立开不同的依赖包。

View File

@ -11,7 +11,7 @@ independent in the `extension` dependency.
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension-spring5</artifactId> <artifactId>fastjson2-extension-spring5</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
or or
@ -19,7 +19,7 @@ or
<dependency> <dependency>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension-spring6</artifactId> <artifactId>fastjson2-extension-spring6</artifactId>
<version>2.0.56</version> <version>2.0.55</version>
</dependency> </dependency>
``` ```
@ -27,13 +27,13 @@ or
```groovy ```groovy
dependencies { dependencies {
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring5:2.0.56' implementation 'com.alibaba.fastjson2:fastjson2-extension-spring5:2.0.55'
} }
or or
dependencies { dependencies {
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring6:2.0.56' implementation 'com.alibaba.fastjson2:fastjson2-extension-spring6:2.0.55'
} }
``` ```
> After version 2.0.23, in order to be compatible with Spring 5.x / 6.x, different versions are independently opened with different dependency packages. > After version 2.0.23, in order to be compatible with Spring 5.x / 6.x, different versions are independently opened with different dependency packages.

View File

@ -1,3 +1,3 @@
JDK 17中提供了[vector api](https://openjdk.org/jeps/426)可以用SIMD来优化性能。 JDK 17中提供了[vector api](https://openjdk.org/jeps/426)可以用SIMD来优化性能。
fastjson 2.0.56版本开始全面使用SWAR(SIMD within a register)来做SIMD优化不再需要使用vector api. fastjson 2.0.55版本开始全面使用SWAR(SIMD within a register)来做SIMD优化不再需要使用vector api.

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
@ -35,7 +35,7 @@
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target> <maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version> <maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
<fastjson2.version>2.0.57-SNAPSHOT</fastjson2.version> <fastjson2.version>2.0.56-SNAPSHOT</fastjson2.version>
<imageName>fastjson2-example-graalvm-native</imageName> <imageName>fastjson2-example-graalvm-native</imageName>
</properties> </properties>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
@ -16,7 +16,7 @@
<properties> <properties>
<maven.test.skip>true</maven.test.skip> <maven.test.skip>true</maven.test.skip>
<maven.deploy.skip>true</maven.deploy.skip> <maven.deploy.skip>true</maven.deploy.skip>
<fastjson2.version>2.0.57-SNAPSHOT</fastjson2.version> <fastjson2.version>2.0.56-SNAPSHOT</fastjson2.version>
<java.version>17</java.version> <java.version>17</java.version>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>${maven.compiler.source}</maven.compiler.target> <maven.compiler.target>${maven.compiler.source}</maven.compiler.target>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension-jaxrs</artifactId> <artifactId>fastjson2-extension-jaxrs</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
</parent> </parent>
<artifactId>fastjson2-extension-jaxrs-jakarta</artifactId> <artifactId>fastjson2-extension-jaxrs-jakarta</artifactId>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-extension-jaxrs</artifactId> <artifactId>fastjson2-extension-jaxrs</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
</parent> </parent>
<artifactId>fastjson2-extension-jaxrs-javax</artifactId> <artifactId>fastjson2-extension-jaxrs-javax</artifactId>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
</parent> </parent>
<artifactId>fastjson2-extension-jaxrs</artifactId> <artifactId>fastjson2-extension-jaxrs</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

15
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<name>${project.artifactId}</name> <name>${project.artifactId}</name>
<description>Fastjson is a JSON processor (JSON parser + JSON generator) written in Java</description> <description>Fastjson is a JSON processor (JSON parser + JSON generator) written in Java</description>
<packaging>pom</packaging> <packaging>pom</packaging>
@ -315,7 +315,7 @@
<dependency> <dependency>
<groupId>net.minidev</groupId> <groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId> <artifactId>json-smart</artifactId>
<version>2.5.2</version> <version>2.5.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.sf.json-lib</groupId> <groupId>net.sf.json-lib</groupId>
@ -450,7 +450,7 @@
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.36</version> <version>1.18.34</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
@ -1019,15 +1019,6 @@
<module>test-jdk17</module> <module>test-jdk17</module>
</modules> </modules>
</profile> </profile>
<profile>
<id>enable-for-jdk21+</id>
<activation>
<jdk>[21,)</jdk>
</activation>
<modules>
<module>benchmark_21</module>
</modules>
</profile>
<profile> <profile>
<id>enable-codegen</id> <id>enable-codegen</id>
<activation> <activation>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>com.alibaba.fastjson2</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2-parent</artifactId> <artifactId>fastjson2-parent</artifactId>
<version>2.0.57-SNAPSHOT</version> <version>2.0.56-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
@ -28,9 +28,5 @@
<artifactId>fastjson2</artifactId> <artifactId>fastjson2</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -2,10 +2,6 @@ package com.alibaba.fastjson2;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
public class RecordTest { public class RecordTest {
@ -18,49 +14,7 @@ public class RecordTest {
JSONObject object = JSON.parseObject(str); JSONObject object = JSON.parseObject(str);
assertEquals(item.value, object.get("value")); assertEquals(item.value, object.get("value"));
Item item2 = JSON.parseObject(str, Item.class);
assertEquals(item.value, item2.value);
} }
public record Item(int value) { record Item(int value) { }
}
@Test
public void test1() {
Item1 item = new Item1(Arrays.asList("abc"));
String str = JSON.toJSONString(item);
Item1 item2 = JSON.parseObject(str, Item1.class);
assertEquals(item.value, item2.value);
}
public record Item1(List<String> value) {
}
@Test
public void test2() {
Item2 item = new Item2(Arrays.asList(new Item(123)));
String str = JSON.toJSONString(item);
Item2 item2 = JSON.parseObject(str, Item2.class);
assertEquals(item.value.size(), item2.value.size());
assertEquals(item.value.get(0).value, item2.value.get(0).value);
}
public record Item2(List<Item> value) {
}
@Test
public void test3() {
Item3 item = new Item3(new User(true, "abc"));
String str = JSON.toJSONString(item);
Item3 item2 = JSON.parseObject(str, Item3.class);
assertEquals(item.user.default_profile, item2.user.default_profile);
assertEquals(item.user.screen_name, item2.user.screen_name);
}
public record User(boolean default_profile, String screen_name) {
}
public record Item3(User user) implements Serializable {
}
} }

View File

@ -1,36 +0,0 @@
package com.alibaba.fastjson2.issues;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.annotation.JSONField;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class Issue3351 {
record AnimalRecord(@JSONField(name = "age", alternateNames = "age2") Long age) {
}
static class AnimalClass {
@JSONField(name = "age", alternateNames = "age2")
public Long age;
}
@Test
public void test() {
String s1 = "{\"age\": 20}";
AnimalRecord a1 = JSON.parseObject(s1, AnimalRecord.class);
assertEquals(20, a1.age);
String s2 = "{\"age2\": 20}";
AnimalRecord a2 = JSON.parseObject(s2, AnimalRecord.class);
assertEquals(20, a2.age);
String s3 = "{\"age\": 20}";
AnimalClass a3 = JSON.parseObject(s3, AnimalClass.class);
assertEquals(20, a3.age);
String s4 = "{\"age2\": 20}";
AnimalClass a4 = JSON.parseObject(s4, AnimalClass.class);
assertEquals(20, a4.age);
}
}