Compare commits
105 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f7888afc8e | ||
![]() |
dbfd35f30f | ||
![]() |
6a61695f4f | ||
![]() |
c87505c4bb | ||
![]() |
b6adb4a25a | ||
![]() |
3d4fffdc89 | ||
![]() |
0f0dcf130c | ||
![]() |
2bd791075d | ||
![]() |
6bf070cfdd | ||
![]() |
50b1a19969 | ||
![]() |
21a66ee63a | ||
![]() |
2440d9af83 | ||
![]() |
8a36d43915 | ||
![]() |
44c4a86172 | ||
![]() |
3048f63b9d | ||
![]() |
87ce61270e | ||
![]() |
5df97e0b21 | ||
![]() |
be25205b08 | ||
![]() |
e68bf51d31 | ||
![]() |
160a26031d | ||
![]() |
89de4e7cdf | ||
![]() |
db328efb4c | ||
![]() |
cf770536f3 | ||
![]() |
ec1c9a9251 | ||
![]() |
7a6a9f1d52 | ||
![]() |
ec04556886 | ||
![]() |
f30ae5fea4 | ||
![]() |
f3da5681e5 | ||
![]() |
cc3712bf90 | ||
![]() |
ccafb7078f | ||
![]() |
a27b46d74e | ||
![]() |
9b4022cf52 | ||
![]() |
f80524707a | ||
![]() |
1ce907ebf4 | ||
![]() |
24399628a8 | ||
![]() |
23cad3cd8c | ||
![]() |
3e59cd9b03 | ||
![]() |
8c379f1588 | ||
![]() |
8b8774e4b8 | ||
![]() |
7f4ff37034 | ||
![]() |
73d8873b2d | ||
![]() |
b2d2b6b117 | ||
![]() |
a646a44ded | ||
![]() |
cead0f267b | ||
![]() |
4b9fcb7e91 | ||
![]() |
c7c3131016 | ||
![]() |
804c20ddea | ||
![]() |
44a398f4e4 | ||
![]() |
bb92ad41c8 | ||
![]() |
ad388be269 | ||
![]() |
b34eb00f50 | ||
![]() |
c33e5060e7 | ||
![]() |
6ea9d19511 | ||
![]() |
e75eab6362 | ||
![]() |
e18c913bf5 | ||
![]() |
91bb641e23 | ||
![]() |
a0c6adc29a | ||
![]() |
b02571b628 | ||
![]() |
f96a709c00 | ||
![]() |
d37342d943 | ||
![]() |
dbfb282d29 | ||
![]() |
e76edc98bb | ||
![]() |
47335c5f57 | ||
![]() |
427c00e9ff | ||
![]() |
363f679942 | ||
![]() |
4acd377ebf | ||
![]() |
e2c3e0ec82 | ||
![]() |
6809f3dc05 | ||
![]() |
9db2e597c9 | ||
![]() |
de05f44515 | ||
![]() |
7721c372f9 | ||
![]() |
6a7ab9277d | ||
![]() |
320c191d5b | ||
![]() |
c24ba4540e | ||
![]() |
701bda4784 | ||
![]() |
84d850d28b | ||
![]() |
2cac1a61e6 | ||
![]() |
45703ac2a6 | ||
![]() |
dd520888a3 | ||
![]() |
a691ecd019 | ||
![]() |
5eb448e3d4 | ||
![]() |
67fbb20ca0 | ||
![]() |
c2bf67ee91 | ||
![]() |
2a365fd243 | ||
![]() |
39b304bb27 | ||
![]() |
e64eda38a2 | ||
![]() |
bce215abc1 | ||
![]() |
4ba99ca04f | ||
![]() |
4cf2d6f412 | ||
![]() |
d11a8edc12 | ||
![]() |
16d68170c9 | ||
![]() |
22f0e602cb | ||
![]() |
832a98ba73 | ||
![]() |
38fed434ab | ||
![]() |
7f4f6fc52c | ||
![]() |
12703cffa0 | ||
![]() |
633c579cd0 | ||
![]() |
184d1de6cf | ||
![]() |
fe53f0b8d1 | ||
![]() |
5a5961fb32 | ||
![]() |
29029e80b6 | ||
![]() |
6ae0acc43a | ||
![]() |
c262c7889c | ||
![]() |
ddcb3e52c1 | ||
![]() |
8dd38ea0aa |
BIN
.gitignore
vendored
BIN
.gitignore
vendored
Binary file not shown.
20
README.md
20
README.md
@ -41,7 +41,7 @@
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.32</version>
|
||||
<version>2.0.33</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -49,7 +49,7 @@
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba.fastjson2:fastjson2:2.0.32'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2:2.0.33'
|
||||
}
|
||||
```
|
||||
|
||||
@ -67,7 +67,7 @@ dependencies {
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>2.0.32</version>
|
||||
<version>2.0.33</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -75,7 +75,7 @@ dependencies {
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba:fastjson:2.0.32'
|
||||
implementation 'com.alibaba:fastjson:2.0.33'
|
||||
}
|
||||
```
|
||||
|
||||
@ -89,7 +89,7 @@ dependencies {
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-kotlin</artifactId>
|
||||
<version>2.0.32</version>
|
||||
<version>2.0.33</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 有些场景需要依赖kotlin-reflect -->
|
||||
@ -104,7 +104,7 @@ dependencies {
|
||||
|
||||
```kotlin
|
||||
dependencies {
|
||||
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.32")
|
||||
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.33")
|
||||
}
|
||||
```
|
||||
|
||||
@ -118,7 +118,7 @@ dependencies {
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-extension-spring5</artifactId>
|
||||
<version>2.0.32</version>
|
||||
<version>2.0.33</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -126,7 +126,7 @@ dependencies {
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-extension-spring6</artifactId>
|
||||
<version>2.0.32</version>
|
||||
<version>2.0.33</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -134,14 +134,14 @@ dependencies {
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring5:2.0.32'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring5:2.0.33'
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring6:2.0.32'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2-extension-spring6:2.0.33'
|
||||
}
|
||||
```
|
||||
|
||||
|
20
README_EN.md
20
README_EN.md
@ -12,11 +12,11 @@
|
||||
[](https://github.com/alibaba/fastjson2/graphs/contributors)
|
||||
|
||||
##### 📖 English Documentation | 📖 [中文文档](README.md)
|
||||
##### The issues of fastjson will be aslo posted on [Alibaba Cloud Developer Community](https://developer.aliyun.com/ask/)
|
||||
##### The issues of fastjson will be also posted on [Alibaba Cloud Developer Community](https://developer.aliyun.com/ask/)
|
||||
|
||||
# FASTJSON v2
|
||||
|
||||
`FASTJSON v2` is an upgrade of the `FASTJSON`, with the goal of providing a highly optimized `JSON` librarray for the next ten years.
|
||||
`FASTJSON v2` is an upgrade of the `FASTJSON`, with the goal of providing a highly optimized `JSON` library for the next ten years.
|
||||
|
||||
- Supports the JSON and JSONB Protocols.
|
||||
- Supports full parsing and partial parsing.
|
||||
@ -47,7 +47,7 @@ Related Documents:
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.32</version>
|
||||
<version>2.0.33</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -55,7 +55,7 @@ Related Documents:
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba.fastjson2:fastjson2:2.0.32'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2:2.0.33'
|
||||
}
|
||||
```
|
||||
|
||||
@ -73,7 +73,7 @@ If you are using `fastjson 1.2.x`, you can use the compatibility package. The co
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>2.0.32</version>
|
||||
<version>2.0.33</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -81,7 +81,7 @@ If you are using `fastjson 1.2.x`, you can use the compatibility package. The co
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba:fastjson:2.0.32'
|
||||
implementation 'com.alibaba:fastjson:2.0.33'
|
||||
}
|
||||
```
|
||||
|
||||
@ -95,7 +95,7 @@ If your project uses `kotlin`, you can use the `Fastjson-Kotlin` module, and use
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-kotlin</artifactId>
|
||||
<version>2.0.32</version>
|
||||
<version>2.0.33</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -103,7 +103,7 @@ If your project uses `kotlin`, you can use the `Fastjson-Kotlin` module, and use
|
||||
|
||||
```kotlin
|
||||
dependencies {
|
||||
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.32")
|
||||
implementation("com.alibaba.fastjson2:fastjson2-kotlin:2.0.33")
|
||||
}
|
||||
```
|
||||
|
||||
@ -117,7 +117,7 @@ If your project uses a framework such as `SpringFramework`, you can use the `fas
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-extension</artifactId>
|
||||
<version>2.0.32</version>
|
||||
<version>2.0.33</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -125,7 +125,7 @@ If your project uses a framework such as `SpringFramework`, you can use the `fas
|
||||
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.alibaba.fastjson2:fastjson2-extension:2.0.32'
|
||||
implementation 'com.alibaba.fastjson2:fastjson2-extension:2.0.33'
|
||||
}
|
||||
```
|
||||
|
||||
|
116
adapter/pom.xml
116
adapter/pom.xml
@ -1,116 +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>
|
||||
<artifactId>fastjson2-parent</artifactId>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<version>2.0.33-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>fastjson2-adapter</artifactId>
|
||||
<name>fastjson2-adapter</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2-extension</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.aliyun.odps</groupId>
|
||||
<artifactId>odps-sdk-udf</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.squareup.retrofit2</groupId>
|
||||
<artifactId>retrofit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.airlift</groupId>
|
||||
<artifactId>slice</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-spring-web</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-messaging</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-websocket</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-elasticsearch</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-mongodb</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-csv</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jdk8</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar-no-fork</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<attach>true</attach>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -1,67 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.gson;
|
||||
|
||||
import com.alibaba.fastjson2.JSONFactory;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.adapter.gson.reflect.TypeToken;
|
||||
import com.alibaba.fastjson2.reader.ObjectReader;
|
||||
import com.alibaba.fastjson2.reader.ObjectReaderProvider;
|
||||
import com.alibaba.fastjson2.writer.ObjectWriterProvider;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class Gson {
|
||||
ObjectReaderProvider readerProvider;
|
||||
ObjectWriterProvider writerProvider;
|
||||
|
||||
public Gson() {
|
||||
}
|
||||
|
||||
protected ObjectReaderProvider getReaderProvider() {
|
||||
if (readerProvider == null) {
|
||||
readerProvider = new ObjectReaderProvider();
|
||||
}
|
||||
return readerProvider;
|
||||
}
|
||||
|
||||
public ObjectWriterProvider getWriterProvider() {
|
||||
if (writerProvider == null) {
|
||||
writerProvider = new ObjectWriterProvider();
|
||||
}
|
||||
return writerProvider;
|
||||
}
|
||||
|
||||
public <T> T fromJson(String json, Class<T> classOfT) {
|
||||
ObjectReaderProvider provider = getReaderProvider();
|
||||
JSONReader.Context context = JSONFactory.createReadContext(provider);
|
||||
ObjectReader objectReader = provider.getObjectReader(classOfT);
|
||||
try (JSONReader jsonReader = JSONReader.of(json, context)) {
|
||||
Object object = objectReader.readObject(jsonReader, classOfT, null, 0L);
|
||||
jsonReader.handleResolveTasks(object);
|
||||
return (T) object;
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T fromJson(String json, Type typeOfT) {
|
||||
ObjectReaderProvider provider = getReaderProvider();
|
||||
JSONReader.Context context = JSONFactory.createReadContext(provider);
|
||||
ObjectReader objectReader = provider.getObjectReader(typeOfT);
|
||||
try (JSONReader jsonReader = JSONReader.of(json, context)) {
|
||||
Object object = objectReader.readObject(jsonReader, typeOfT, null, 0L);
|
||||
jsonReader.handleResolveTasks(object);
|
||||
return (T) object;
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T fromJson(String json, TypeToken<T> typeToken) {
|
||||
return fromJson(json, typeToken.getType());
|
||||
}
|
||||
|
||||
public String toJson(Object src) {
|
||||
ObjectWriterProvider provider = getWriterProvider();
|
||||
JSONWriter.Context context = JSONFactory.createWriteContext(provider);
|
||||
JSONWriter writer = JSONWriter.of(context);
|
||||
writer.writeAny(src);
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.gson.reflect;
|
||||
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
|
||||
public class TypeToken<T>
|
||||
extends TypeReference<T> {
|
||||
protected TypeToken() {
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JacksonInject {
|
||||
public String value() default "";
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, // for combo-annotations
|
||||
ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER// for properties (field, setter, ctor param)
|
||||
})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonAlias {
|
||||
public String[] value() default { };
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonAnyGetter {
|
||||
boolean enabled() default true;
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonAnySetter {
|
||||
boolean enabled() default true;
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonCreator {
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
|
||||
ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonFormat {
|
||||
String pattern() default "";
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonGetter {
|
||||
String value() default "";
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonIgnore {
|
||||
/**
|
||||
* Optional argument that defines whether this annotation is active
|
||||
* or not. The only use for value 'false' if for overriding purposes
|
||||
* (which is not needed often); most likely it is needed for use
|
||||
* with "mix-in annotations" (aka "annotation overrides").
|
||||
* For most cases, however, default value of "true" is just fine
|
||||
* and should be omitted.
|
||||
*
|
||||
* @return True if annotation is enabled (normal case); false if it is to
|
||||
* be ignored (only useful for mix-in annotations to "mask" annotation)
|
||||
*/
|
||||
boolean value() default true;
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE,
|
||||
ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonIgnoreProperties {
|
||||
String[] value() default { };
|
||||
|
||||
boolean ignoreUnknown() default false;
|
||||
|
||||
boolean allowGetters() default false;
|
||||
|
||||
boolean allowSetters() default false;
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonInclude {
|
||||
Include value() default Include.ALWAYS;
|
||||
|
||||
Class<?> valueFilter() default Void.class;
|
||||
|
||||
Class<?> contentFilter() default Void.class;
|
||||
|
||||
enum Include {
|
||||
ALWAYS,
|
||||
NON_NULL,
|
||||
NON_ABSENT,
|
||||
NON_EMPTY,
|
||||
NON_DEFAULT,
|
||||
USE_DEFAULTS,
|
||||
CUSTOM
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonProperty {
|
||||
String value() default "";
|
||||
|
||||
boolean required() default false;
|
||||
|
||||
Access access() default Access.AUTO;
|
||||
|
||||
int index() default -1;
|
||||
|
||||
enum Access {
|
||||
/**
|
||||
* Access setting which means that visibility rules are to be used
|
||||
* to automatically determine read- and/or write-access of this property.
|
||||
*/
|
||||
AUTO,
|
||||
|
||||
/**
|
||||
* Access setting that means that the property may only be read for serialization
|
||||
* (value accessed via "getter" Method, or read from Field)
|
||||
* but not written (set) during deserialization.
|
||||
* Put another way, this would reflect "read-only POJO", in which value contained
|
||||
* may be read but not written/set.
|
||||
*/
|
||||
READ_ONLY,
|
||||
|
||||
/**
|
||||
* Access setting that means that the property may only be written (set)
|
||||
* as part of deserialization (using "setter" method, or assigning to Field,
|
||||
* or passed as Creator argument)
|
||||
* but will not be read (get) for serialization, that is, the value of the property
|
||||
* is not included in serialization.
|
||||
*/
|
||||
WRITE_ONLY,
|
||||
|
||||
/**
|
||||
* Access setting that means that the property will be accessed for both
|
||||
* serialization (writing out values as external representation)
|
||||
* and deserialization (reading values from external representation),
|
||||
* regardless of visibility rules.
|
||||
*/
|
||||
READ_WRITE;
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonRawValue {
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD,
|
||||
ElementType.METHOD, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonSubTypes {
|
||||
Type[] value();
|
||||
boolean failOnRepeatedNames() default false;
|
||||
|
||||
@interface Type {
|
||||
Class<?> value();
|
||||
String name() default "";
|
||||
String[] names() default {};
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE,
|
||||
ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonTypeInfo {
|
||||
JsonTypeInfo.Id use();
|
||||
|
||||
As include() default As.PROPERTY;
|
||||
|
||||
String property() default "";
|
||||
|
||||
boolean visible() default false;
|
||||
|
||||
enum Id {
|
||||
NONE(null),
|
||||
NAME("@type"),
|
||||
MINIMAL_CLASS("@c"),
|
||||
CLASS("@class");
|
||||
|
||||
private final String defaultPropertyName;
|
||||
|
||||
Id(String defProp) {
|
||||
defaultPropertyName = defProp;
|
||||
}
|
||||
|
||||
public String getDefaultPropertyName() { return defaultPropertyName; }
|
||||
}
|
||||
|
||||
enum As {
|
||||
PROPERTY,
|
||||
WRAPPER_OBJECT,
|
||||
WRAPPER_ARRAY,
|
||||
EXTERNAL_PROPERTY,
|
||||
EXISTING_PROPERTY
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonTypeName {
|
||||
String value() default "";
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD,
|
||||
ElementType.FIELD
|
||||
})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonValue {
|
||||
boolean value() default true;
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
public class Base64Variant {
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
public class Base64Variants {
|
||||
public static final Base64Variant MIME_NO_LINEFEEDS = new Base64Variant();
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.util.JacksonFeature;
|
||||
|
||||
public interface FormatFeature
|
||||
extends JacksonFeature {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
public class FormatSchema {
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class JacksonException
|
||||
extends IOException {
|
||||
public JacksonException() {
|
||||
}
|
||||
|
||||
public JacksonException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JacksonException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public abstract String getOriginalMessage();
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/* Jackson JSON-processor.
|
||||
*
|
||||
* Copyright (c) 2007- Tatu Saloranta, tatu.saloranta@iki.fi
|
||||
*/
|
||||
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
public enum JsonEncoding {
|
||||
UTF8("UTF-8", false, 8), // N/A for big-endian, really
|
||||
UTF16_BE("UTF-16BE", true, 16),
|
||||
UTF16_LE("UTF-16LE", false, 16),
|
||||
UTF32_BE("UTF-32BE", true, 32),
|
||||
UTF32_LE("UTF-32LE", false, 32);
|
||||
|
||||
private final String javaName;
|
||||
private final boolean bigEndian;
|
||||
private final int bits;
|
||||
|
||||
JsonEncoding(String javaName, boolean bigEndian, int bits) {
|
||||
this.javaName = javaName;
|
||||
this.bigEndian = bigEndian;
|
||||
this.bits = bits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for accessing encoding name that JDK will support.
|
||||
*
|
||||
* @return Matching encoding name that JDK will support.
|
||||
*/
|
||||
public String getJavaName() {
|
||||
return javaName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether encoding is big-endian (if encoding supports such
|
||||
* notion). If no such distinction is made (as is the case for
|
||||
* {@link #UTF8}), return value is undefined.
|
||||
*
|
||||
* @return True for big-endian encodings; false for little-endian
|
||||
* (or if not applicable)
|
||||
*/
|
||||
public boolean isBigEndian() {
|
||||
return bigEndian;
|
||||
}
|
||||
|
||||
public int bits() {
|
||||
return bits;
|
||||
}
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
import com.alibaba.fastjson2.JSONFactory;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.util.JacksonFeature;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class JsonFactory {
|
||||
private long parserFeatures;
|
||||
private long generatorFeatures;
|
||||
|
||||
public JSONWriter createJSONWriter() {
|
||||
JSONWriter jsonWriter = JSONWriter.of();
|
||||
return jsonWriter;
|
||||
}
|
||||
|
||||
public boolean isCSV() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public JSONReader.Context createReaderContext() {
|
||||
return JSONFactory.createReadContext();
|
||||
}
|
||||
|
||||
public JSONReader createJSONReader(String str) {
|
||||
JSONReader jsonReader = JSONReader.of(str, createReaderContext());
|
||||
return jsonReader;
|
||||
}
|
||||
|
||||
public JSONReader createJSONReader(File str) throws IOException {
|
||||
JSONReader jsonReader = JSONReader.of(new FileInputStream(str), StandardCharsets.UTF_8, createReaderContext());
|
||||
return jsonReader;
|
||||
}
|
||||
|
||||
public JsonGenerator createGenerator(OutputStream out) throws IOException {
|
||||
return createGenerator(out, JsonEncoding.UTF8);
|
||||
}
|
||||
|
||||
public JsonGenerator createGenerator(OutputStream out, JsonEncoding enc)
|
||||
throws IOException {
|
||||
JSONWriter jsonWriter = createJSONWriter();
|
||||
return new JsonGenerator(jsonWriter, out, enc);
|
||||
}
|
||||
|
||||
public JsonGenerator createGenerator(Writer w) throws IOException {
|
||||
JSONWriter jsonWriter = createJSONWriter();
|
||||
return new JsonGenerator(jsonWriter, w);
|
||||
}
|
||||
|
||||
public JsonGenerator createGenerator(File f, JsonEncoding enc) throws IOException {
|
||||
FileOutputStream out = new FileOutputStream(f);
|
||||
return createGenerator(out, enc);
|
||||
}
|
||||
|
||||
public JsonParser createParser(String content) throws IOException, JsonParseException {
|
||||
JSONReader jsonReader = JSONReader.of(content);
|
||||
return new JsonParser(jsonReader);
|
||||
}
|
||||
|
||||
public JsonParser createParser(InputStream in) throws IOException, JsonParseException {
|
||||
JSONReader jsonReader = JSONReader.of(in, StandardCharsets.UTF_8);
|
||||
return new JsonParser(jsonReader);
|
||||
}
|
||||
|
||||
public JsonParser createParser(Reader r) throws IOException, JsonParseException {
|
||||
JSONReader jsonReader = JSONReader.of(r);
|
||||
return new JsonParser(jsonReader);
|
||||
}
|
||||
|
||||
public final JsonFactory configure(JsonParser.Feature f, boolean state) {
|
||||
return state ? enable(f) : disable(f);
|
||||
}
|
||||
|
||||
public JsonFactory enable(JsonParser.Feature f) {
|
||||
parserFeatures |= f.getMask();
|
||||
return this;
|
||||
}
|
||||
|
||||
public JsonFactory disable(JsonParser.Feature f) {
|
||||
parserFeatures &= ~f.getMask();
|
||||
return this;
|
||||
}
|
||||
|
||||
public final JsonFactory configure(JsonGenerator.Feature f, boolean state) {
|
||||
return state ? enable(f) : disable(f);
|
||||
}
|
||||
|
||||
public JsonFactory enable(JsonGenerator.Feature f) {
|
||||
generatorFeatures |= f.getMask();
|
||||
return this;
|
||||
}
|
||||
|
||||
public JsonFactory disable(JsonGenerator.Feature f) {
|
||||
generatorFeatures &= ~f.getMask();
|
||||
return this;
|
||||
}
|
||||
|
||||
public JsonFactory disable(Feature f) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public enum Feature
|
||||
implements JacksonFeature {
|
||||
INTERN_FIELD_NAMES(true),
|
||||
CANONICALIZE_FIELD_NAMES(true),
|
||||
FAIL_ON_SYMBOL_HASH_OVERFLOW(true),
|
||||
USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING(true);
|
||||
|
||||
private final boolean defaultState;
|
||||
|
||||
Feature(boolean defaultState) { this.defaultState = defaultState; }
|
||||
|
||||
public int getMask() { return (1 << ordinal()); }
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
|
||||
public class JsonFactoryBuilder {
|
||||
public JsonFactoryBuilder disable(JsonFactory.Feature f) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public JsonFactory build() {
|
||||
// TODO build
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
}
|
@ -1,349 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.util.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class JsonGenerator
|
||||
implements Closeable, Flushable {
|
||||
protected final JSONWriter jsonWriter;
|
||||
protected final OutputStream out;
|
||||
protected final Charset charset;
|
||||
protected final JsonEncoding encoding;
|
||||
protected final Writer writer;
|
||||
|
||||
public JsonGenerator() {
|
||||
this(JSONWriter.of(), null, JsonEncoding.UTF16_BE);
|
||||
}
|
||||
|
||||
public JsonGenerator(JSONWriter jsonWriter, OutputStream out, JsonEncoding encoding) {
|
||||
this.jsonWriter = jsonWriter;
|
||||
this.out = out;
|
||||
this.encoding = encoding;
|
||||
this.charset = Charset.forName(encoding.getJavaName());
|
||||
this.writer = null;
|
||||
}
|
||||
|
||||
public JsonGenerator(JSONWriter jsonWriter, Writer writer) {
|
||||
this.jsonWriter = jsonWriter;
|
||||
this.out = null;
|
||||
this.encoding = JsonEncoding.UTF16_BE;
|
||||
this.charset = StandardCharsets.UTF_16;
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public JSONWriter getJSONWriter() {
|
||||
return jsonWriter;
|
||||
}
|
||||
|
||||
public void writeNull() throws IOException {
|
||||
jsonWriter.writeNull();
|
||||
}
|
||||
|
||||
public void writeRaw(String text) {
|
||||
jsonWriter.writeRaw(text);
|
||||
}
|
||||
|
||||
public void writeRaw(char ch) {
|
||||
jsonWriter.writeRaw(ch);
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
if (out != null) {
|
||||
jsonWriter.flushTo(out, charset);
|
||||
} else if (writer != null) {
|
||||
jsonWriter.flushTo(writer);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeStartObject() {
|
||||
jsonWriter.startObject();
|
||||
}
|
||||
|
||||
public void writeEndObject() {
|
||||
jsonWriter.endObject();
|
||||
}
|
||||
|
||||
public void writeEndArray() {
|
||||
jsonWriter.endArray();
|
||||
}
|
||||
|
||||
public void writeFieldName(String name) {
|
||||
jsonWriter.writeName(name);
|
||||
jsonWriter.writeRaw(':');
|
||||
}
|
||||
|
||||
public void writeString(String text) {
|
||||
jsonWriter.writeString(text);
|
||||
}
|
||||
|
||||
public void writeNumber(int v) {
|
||||
jsonWriter.writeInt32(v);
|
||||
}
|
||||
|
||||
public void writeNumber(BigDecimal v) {
|
||||
jsonWriter.writeDecimal(v);
|
||||
}
|
||||
|
||||
public void writeNumber(long v) {
|
||||
jsonWriter.writeInt64(v);
|
||||
}
|
||||
|
||||
public void writeBinary(byte[] data) {
|
||||
jsonWriter.writeBinary(data);
|
||||
}
|
||||
|
||||
public void writeStringField(String fieldName, String value) throws IOException {
|
||||
writeFieldName(fieldName);
|
||||
writeString(value);
|
||||
}
|
||||
|
||||
public void writeNumberField(String fieldName, BigDecimal value) throws IOException {
|
||||
writeFieldName(fieldName);
|
||||
writeNumber(value);
|
||||
}
|
||||
|
||||
public void writeNumberField(String fieldName, long value) throws IOException {
|
||||
writeFieldName(fieldName);
|
||||
writeNumber(value);
|
||||
}
|
||||
|
||||
public void writeNumberField(String fieldName, float value) throws IOException {
|
||||
writeFieldName(fieldName);
|
||||
writeNumber(value);
|
||||
}
|
||||
|
||||
public void writeNumberField(String fieldName, double value) throws IOException {
|
||||
writeFieldName(fieldName);
|
||||
writeNumber(value);
|
||||
}
|
||||
|
||||
public void writeNumberField(String fieldName, int value) throws IOException {
|
||||
writeFieldName(fieldName);
|
||||
writeNumber(value);
|
||||
}
|
||||
|
||||
public void writeBinaryField(String fieldName, byte[] data) throws IOException {
|
||||
writeFieldName(fieldName);
|
||||
writeBinary(data);
|
||||
}
|
||||
|
||||
public void writeBooleanField(String fieldName, boolean value) throws IOException {
|
||||
writeFieldName(fieldName);
|
||||
writeBoolean(value);
|
||||
}
|
||||
|
||||
public void writeArrayFieldStart(String fieldName) throws IOException {
|
||||
writeFieldName(fieldName);
|
||||
writeStartArray();
|
||||
}
|
||||
|
||||
public void writeNullField(String fieldName) throws IOException {
|
||||
writeFieldName(fieldName);
|
||||
writeNull();
|
||||
}
|
||||
|
||||
public void writeStartArray() throws IOException {
|
||||
jsonWriter.startArray();
|
||||
}
|
||||
|
||||
public void writeRawValue(String text) throws IOException {
|
||||
jsonWriter.writeRaw(text);
|
||||
}
|
||||
|
||||
public void writeObject(Object pojo) throws IOException {
|
||||
jsonWriter.writeAny(pojo);
|
||||
}
|
||||
|
||||
public void writeObjectField(String fieldName, Object pojo) throws IOException {
|
||||
writeFieldName(fieldName);
|
||||
writeObject(pojo);
|
||||
}
|
||||
|
||||
public void writeObjectFieldStart(String fieldName) throws IOException {
|
||||
writeFieldName(fieldName);
|
||||
writeStartObject();
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
if (out != null) {
|
||||
jsonWriter.flushTo(out, charset);
|
||||
IOUtils.close(out);
|
||||
} else if (writer != null) {
|
||||
jsonWriter.flushTo(writer);
|
||||
IOUtils.close(writer);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Feature {
|
||||
// // Low-level I/O / content features
|
||||
|
||||
/**
|
||||
* Feature that determines whether generator will automatically
|
||||
* close underlying output target that is NOT owned by the
|
||||
* generator.
|
||||
* If disabled, calling application has to separately
|
||||
* close the underlying {@link OutputStream} and {@link Writer}
|
||||
* instances used to create the generator. If enabled, generator
|
||||
* will handle closing, as long as generator itself gets closed:
|
||||
* this happens when end-of-input is encountered, or generator
|
||||
* is closed by a call to {@link JsonGenerator#close}.
|
||||
* <p>
|
||||
* Feature is enabled by default.
|
||||
*/
|
||||
AUTO_CLOSE_TARGET(true),
|
||||
|
||||
AUTO_CLOSE_JSON_CONTENT(true),
|
||||
|
||||
/**
|
||||
* Feature that specifies that calls to {@link #flush} will cause
|
||||
* matching <code>flush()</code> to underlying {@link OutputStream}
|
||||
* or {@link Writer}; if disabled this will not be done.
|
||||
* Main reason to disable this feature is to prevent flushing at
|
||||
* generator level, if it is not possible to prevent method being
|
||||
* called by other code (like <code>ObjectMapper</code> or third
|
||||
* party libraries).
|
||||
* <p>
|
||||
* Feature is enabled by default.
|
||||
*/
|
||||
FLUSH_PASSED_TO_STREAM(true),
|
||||
|
||||
// // Quoting-related features
|
||||
|
||||
@Deprecated
|
||||
QUOTE_FIELD_NAMES(true),
|
||||
|
||||
@Deprecated
|
||||
QUOTE_NON_NUMERIC_NUMBERS(true),
|
||||
|
||||
// // Character escaping features
|
||||
|
||||
@Deprecated
|
||||
ESCAPE_NON_ASCII(false),
|
||||
|
||||
// // Datatype coercion features
|
||||
|
||||
@Deprecated
|
||||
WRITE_NUMBERS_AS_STRINGS(false),
|
||||
|
||||
/**
|
||||
* Feature that determines whether {@link BigDecimal} entries are
|
||||
* serialized using {@link BigDecimal#toPlainString()} to prevent
|
||||
* values to be written using scientific notation.
|
||||
* <p>
|
||||
* NOTE: only affects generators that serialize {@link BigDecimal}s
|
||||
* using textual representation (textual formats but potentially some binary
|
||||
* formats).
|
||||
* <p>
|
||||
* Feature is disabled by default, so default output mode is used; this generally
|
||||
* depends on how {@link BigDecimal} has been created.
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
WRITE_BIGDECIMAL_AS_PLAIN(false),
|
||||
|
||||
// // Schema/Validity support features
|
||||
|
||||
STRICT_DUPLICATE_DETECTION(false),
|
||||
|
||||
/**
|
||||
* Feature that determines what to do if the underlying data format requires knowledge
|
||||
* of all properties to output, and if no definition is found for a property that
|
||||
* caller tries to write. If enabled, such properties will be quietly ignored;
|
||||
* if disabled, a {@link JsonProcessingException} will be thrown to indicate the
|
||||
* problem.
|
||||
* Typically most textual data formats do NOT require schema information (although
|
||||
* some do, such as CSV), whereas many binary data formats do require definitions
|
||||
* (such as Avro, protobuf), although not all (Smile, CBOR, BSON and MessagePack do not).
|
||||
* <p>
|
||||
* Note that support for this feature is implemented by individual data format
|
||||
* module, if (and only if) it makes sense for the format in question. For JSON,
|
||||
* for example, this feature has no effect as properties need not be pre-defined.
|
||||
* <p>
|
||||
* Feature is disabled by default, meaning that if the underlying data format
|
||||
* requires knowledge of all properties to output, attempts to write an unknown
|
||||
* property will result in a {@link JsonProcessingException}
|
||||
*
|
||||
* @since 2.5
|
||||
*/
|
||||
IGNORE_UNKNOWN(false);
|
||||
|
||||
private final boolean defaultState;
|
||||
private final int mask;
|
||||
|
||||
/**
|
||||
* Method that calculates bit set (flags) of all features that
|
||||
* are enabled by default.
|
||||
*
|
||||
* @return Bit field of the features that are enabled by default
|
||||
*/
|
||||
public static int collectDefaults() {
|
||||
int flags = 0;
|
||||
for (Feature f : values()) {
|
||||
if (f.enabledByDefault()) {
|
||||
flags |= f.getMask();
|
||||
}
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
private Feature(boolean defaultState) {
|
||||
this.defaultState = defaultState;
|
||||
mask = (1 << ordinal());
|
||||
}
|
||||
|
||||
public boolean enabledByDefault() {
|
||||
return defaultState;
|
||||
}
|
||||
|
||||
// @since 2.3
|
||||
public boolean enabledIn(int flags) {
|
||||
return (flags & mask) != 0;
|
||||
}
|
||||
|
||||
public int getMask() {
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
|
||||
public void copyCurrentStructure(JsonParser p) throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public JsonGenerator setRootValueSeparator(SerializableString sep) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void writeBinary(Base64Variant bv, byte[] data, int offset, int len) throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public int writeBinary(InputStream data, int dataLength) throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public int writeBinary(Base64Variant bv, InputStream data, int dataLength) throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public void writeBoolean(boolean state) throws IOException {
|
||||
jsonWriter.writeBool(state);
|
||||
}
|
||||
|
||||
public void writeNumber(float v) throws IOException {
|
||||
jsonWriter.writeFloat(v);
|
||||
}
|
||||
|
||||
public void writeNumber(double v) throws IOException {
|
||||
jsonWriter.writeDouble(v);
|
||||
}
|
||||
|
||||
public void writeArray(int[] array, int offset, int length) throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
public class JsonLocation {
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
public class JsonParseException
|
||||
extends JsonProcessingException {
|
||||
public JsonParseException() {
|
||||
}
|
||||
|
||||
public JsonParseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JsonParseException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public JsonParseException(JsonParser p, String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
@ -1,311 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.type.TypeReference;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.ObjectCodecWrapper;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.node.ObjectNode;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.node.TreeNodeUtils;
|
||||
import com.alibaba.fastjson2.util.TypeUtils;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Base64;
|
||||
|
||||
public class JsonParser
|
||||
implements Closeable {
|
||||
protected final JSONReader jsonReader;
|
||||
protected String stringValue;
|
||||
protected Number number;
|
||||
protected JsonToken token;
|
||||
|
||||
public JsonParser(JSONReader jsonReader) {
|
||||
this.jsonReader = jsonReader;
|
||||
}
|
||||
|
||||
public JSONReader getJSONReader() {
|
||||
return jsonReader;
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return jsonReader.isEnd();
|
||||
}
|
||||
|
||||
public ObjectCodec getCodec() {
|
||||
return new ObjectCodecWrapper();
|
||||
}
|
||||
|
||||
public JsonLocation getCurrentLocation() {
|
||||
// TODO getCurrentLocation
|
||||
return new JsonLocation();
|
||||
}
|
||||
|
||||
public JsonToken nextValue() throws IOException {
|
||||
return nextToken();
|
||||
}
|
||||
|
||||
public <T> T readValueAs(Class<T> valueType) throws IOException {
|
||||
return jsonReader.read(valueType);
|
||||
}
|
||||
|
||||
public <T> T readValueAs(TypeReference<?> valueTypeRef) throws IOException {
|
||||
return jsonReader.read(valueTypeRef.getType());
|
||||
}
|
||||
|
||||
public <T extends TreeNode> T readValueAsTree() throws IOException {
|
||||
if (token == JsonToken.START_OBJECT) {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonReader.setTypeRedirect(true);
|
||||
jsonReader.readObject(jsonObject, 0L);
|
||||
return (T) new ObjectNode(jsonObject);
|
||||
}
|
||||
|
||||
Object any = jsonReader.readAny();
|
||||
return (T) TreeNodeUtils.as(any);
|
||||
}
|
||||
|
||||
public byte[] getBinaryValue() throws IOException {
|
||||
if (token == JsonToken.START_OBJECT) {
|
||||
stringValue = jsonReader.readString();
|
||||
jsonReader.nextIfMatch(':');
|
||||
} else if (stringValue == null) {
|
||||
char ch = jsonReader.current();
|
||||
if (ch == '"') {
|
||||
stringValue = jsonReader.readString();
|
||||
}
|
||||
}
|
||||
|
||||
String str = stringValue;
|
||||
stringValue = null;
|
||||
return Base64.getDecoder().decode(str);
|
||||
}
|
||||
|
||||
public String getValueAsString() {
|
||||
if (token == JsonToken.START_OBJECT) {
|
||||
stringValue = jsonReader.readString();
|
||||
jsonReader.nextIfMatch(':');
|
||||
} else if (stringValue == null) {
|
||||
char ch = jsonReader.current();
|
||||
if (ch == '"') {
|
||||
stringValue = jsonReader.readString();
|
||||
}
|
||||
}
|
||||
|
||||
String str = stringValue;
|
||||
stringValue = null;
|
||||
return str;
|
||||
}
|
||||
|
||||
public long getLongValue() {
|
||||
long value = number.longValue();
|
||||
number = null;
|
||||
return value;
|
||||
}
|
||||
|
||||
public double getDoubleValue() {
|
||||
double value = number.doubleValue();
|
||||
number = null;
|
||||
return value;
|
||||
}
|
||||
|
||||
public float getFloatValue() {
|
||||
float value = number.floatValue();
|
||||
number = null;
|
||||
return value;
|
||||
}
|
||||
|
||||
public BigDecimal getDecimalValue() {
|
||||
BigDecimal decimal = TypeUtils.toBigDecimal(number);
|
||||
number = null;
|
||||
return decimal;
|
||||
}
|
||||
|
||||
public NumberType getNumberType() throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public JsonToken nextToken() throws IOException {
|
||||
char current = jsonReader.current();
|
||||
if (current == ':' || current == ',') {
|
||||
jsonReader.next();
|
||||
current = jsonReader.current();
|
||||
}
|
||||
|
||||
switch (current) {
|
||||
case '{':
|
||||
token = JsonToken.START_OBJECT;
|
||||
jsonReader.next();
|
||||
break;
|
||||
case '}':
|
||||
token = JsonToken.END_OBJECT;
|
||||
jsonReader.next();
|
||||
jsonReader.nextIfMatch(',');
|
||||
break;
|
||||
case '[':
|
||||
token = JsonToken.START_ARRAY;
|
||||
jsonReader.next();
|
||||
break;
|
||||
case ']':
|
||||
token = JsonToken.END_ARRAY;
|
||||
jsonReader.next();
|
||||
jsonReader.nextIfMatch(',');
|
||||
break;
|
||||
case '"':
|
||||
stringValue = jsonReader.readString();
|
||||
if (jsonReader.current() == ':') {
|
||||
jsonReader.next();
|
||||
token = JsonToken.FIELD_NAME;
|
||||
} else {
|
||||
token = JsonToken.VALUE_STRING;
|
||||
}
|
||||
break;
|
||||
case '.':
|
||||
case '+':
|
||||
case '-':
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
number = jsonReader.readNumber();
|
||||
if (number instanceof Double || number instanceof Float || number instanceof BigDecimal) {
|
||||
token = JsonToken.VALUE_NUMBER_FLOAT;
|
||||
} else {
|
||||
token = JsonToken.VALUE_NUMBER_INT;
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (jsonReader.nextIfNull()) {
|
||||
token = JsonToken.VALUE_NULL;
|
||||
} else {
|
||||
throw new IOException("TODO");
|
||||
}
|
||||
break;
|
||||
case 't':
|
||||
if (!jsonReader.nextIfMatchIdent('t', 'r', 'u', 'e')) {
|
||||
throw new IOException("TODO");
|
||||
}
|
||||
token = JsonToken.VALUE_TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
if (!jsonReader.nextIfMatchIdent('f', 'a', 'l', 's', 'e')) {
|
||||
throw new IOException("TODO");
|
||||
}
|
||||
token = JsonToken.VALUE_FALSE;
|
||||
break;
|
||||
default:
|
||||
throw new IOException("TODO " + current);
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
jsonReader.close();
|
||||
}
|
||||
|
||||
public enum Feature {
|
||||
AUTO_CLOSE_SOURCE(true),
|
||||
ALLOW_COMMENTS(false),
|
||||
ALLOW_YAML_COMMENTS(false),
|
||||
ALLOW_UNQUOTED_FIELD_NAMES(false),
|
||||
ALLOW_SINGLE_QUOTES(false),
|
||||
@Deprecated
|
||||
ALLOW_UNQUOTED_CONTROL_CHARS(false),
|
||||
@Deprecated
|
||||
ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER(false),
|
||||
@Deprecated
|
||||
ALLOW_NUMERIC_LEADING_ZEROS(false),
|
||||
@Deprecated
|
||||
ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS(false),
|
||||
@Deprecated
|
||||
ALLOW_NON_NUMERIC_NUMBERS(false),
|
||||
@Deprecated
|
||||
ALLOW_MISSING_VALUES(false),
|
||||
@Deprecated
|
||||
ALLOW_TRAILING_COMMA(false),
|
||||
STRICT_DUPLICATE_DETECTION(false),
|
||||
IGNORE_UNDEFINED(false),
|
||||
INCLUDE_SOURCE_IN_LOCATION(true);
|
||||
|
||||
/**
|
||||
* Whether feature is enabled or disabled by default.
|
||||
*/
|
||||
private final boolean defaultState;
|
||||
|
||||
private final int mask;
|
||||
|
||||
/**
|
||||
* Method that calculates bit set (flags) of all features that
|
||||
* are enabled by default.
|
||||
*
|
||||
* @return Bit mask of all features that are enabled by default
|
||||
*/
|
||||
public static int collectDefaults() {
|
||||
int flags = 0;
|
||||
for (Feature f : values()) {
|
||||
if (f.enabledByDefault()) {
|
||||
flags |= f.getMask();
|
||||
}
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
Feature(boolean defaultState) {
|
||||
mask = (1 << ordinal());
|
||||
this.defaultState = defaultState;
|
||||
}
|
||||
|
||||
public boolean enabledByDefault() {
|
||||
return defaultState;
|
||||
}
|
||||
|
||||
public boolean enabledIn(int flags) {
|
||||
return (flags & mask) != 0;
|
||||
}
|
||||
|
||||
public int getMask() {
|
||||
return mask;
|
||||
}
|
||||
}
|
||||
|
||||
public enum NumberType {
|
||||
INT, LONG, BIG_INTEGER, FLOAT, DOUBLE, BIG_DECIMAL
|
||||
}
|
||||
|
||||
public boolean nextFieldName(SerializedString str) throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public boolean hasCurrentToken() {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public JsonToken getCurrentToken() {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public JsonParser skipChildren() throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public String getText() throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public byte[] getBinaryValue(Base64Variant bv) throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public JsonToken currentToken() {
|
||||
return getCurrentToken();
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
import com.alibaba.fastjson2.JSONPath;
|
||||
|
||||
public class JsonPointer {
|
||||
final JSONPath path;
|
||||
|
||||
JsonPointer(JSONPath path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public static JsonPointer compile(String expr) throws IllegalArgumentException {
|
||||
JSONPath jsonPath = JSONPath.of(expr);
|
||||
return new JsonPointer(jsonPath);
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
public class JsonProcessingException
|
||||
extends JacksonException {
|
||||
public JsonProcessingException() {
|
||||
}
|
||||
|
||||
public JsonProcessingException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JsonProcessingException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOriginalMessage() { return super.getMessage(); }
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
|
||||
public enum JsonToken {
|
||||
START_OBJECT("{", JsonTokenId.ID_START_OBJECT),
|
||||
END_OBJECT("}", JsonTokenId.ID_END_OBJECT),
|
||||
START_ARRAY("[", JsonTokenId.ID_START_ARRAY),
|
||||
END_ARRAY("]", JsonTokenId.ID_END_ARRAY),
|
||||
FIELD_NAME(null, JsonTokenId.ID_FIELD_NAME),
|
||||
VALUE_STRING(null, JsonTokenId.ID_STRING),
|
||||
VALUE_NUMBER_INT(null, JsonTokenId.ID_NUMBER_INT),
|
||||
VALUE_NUMBER_FLOAT(null, JsonTokenId.ID_NUMBER_FLOAT),
|
||||
VALUE_TRUE("true", JsonTokenId.ID_TRUE),
|
||||
VALUE_FALSE("false", JsonTokenId.ID_FALSE),
|
||||
VALUE_NULL("null", JsonTokenId.ID_NULL);
|
||||
|
||||
JsonToken(String token, int id) {
|
||||
// TODO isScalarValue
|
||||
}
|
||||
|
||||
public final boolean isScalarValue() {
|
||||
// TODO isScalarValue
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
public interface JsonTokenId {
|
||||
int ID_START_OBJECT = 1;
|
||||
int ID_END_OBJECT = 2;
|
||||
int ID_START_ARRAY = 3;
|
||||
int ID_END_ARRAY = 4;
|
||||
int ID_FIELD_NAME = 5;
|
||||
int ID_STRING = 6;
|
||||
int ID_NUMBER_INT = 7;
|
||||
int ID_NUMBER_FLOAT = 8;
|
||||
int ID_TRUE = 9;
|
||||
int ID_FALSE = 10;
|
||||
int ID_NULL = 11;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class ObjectCodec {
|
||||
public abstract <T extends TreeNode> T readTree(JsonParser p) throws IOException;
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
public interface PrettyPrinter {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
public interface SerializableString {
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
public class SerializedString {
|
||||
protected String value;
|
||||
public SerializedString(String v) {
|
||||
this.value = v;
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
public interface TreeNode {
|
||||
TreeNode get(String fieldName);
|
||||
|
||||
TreeNode get(int index);
|
||||
|
||||
JsonParser traverse(ObjectCodec codec);
|
||||
|
||||
boolean isMissingNode();
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core;
|
||||
|
||||
public class Version
|
||||
implements Comparable<Version>, java.io.Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final Version UNKNOWN_VERSION = new Version(0, 0, 0, null, null, null);
|
||||
|
||||
protected final int majorVersion;
|
||||
|
||||
protected final int minorVersion;
|
||||
|
||||
protected final int patchLevel;
|
||||
|
||||
protected final String groupId;
|
||||
|
||||
protected final String artifactId;
|
||||
|
||||
/**
|
||||
* Additional information for snapshot versions; null for non-snapshot
|
||||
* (release) versions.
|
||||
*/
|
||||
protected final String snapshotInfo;
|
||||
|
||||
/**
|
||||
* @param major Major version number
|
||||
* @param minor Minor version number
|
||||
* @param patchLevel patch level of version
|
||||
* @param snapshotInfo Optional additional string qualifier
|
||||
* @since 2.1
|
||||
* @deprecated Use variant that takes group and artifact ids
|
||||
*/
|
||||
@Deprecated
|
||||
public Version(int major, int minor, int patchLevel, String snapshotInfo) {
|
||||
this(major, minor, patchLevel, snapshotInfo, null, null);
|
||||
}
|
||||
|
||||
public Version(int major, int minor, int patchLevel, String snapshotInfo,
|
||||
String groupId, String artifactId) {
|
||||
majorVersion = major;
|
||||
minorVersion = minor;
|
||||
this.patchLevel = patchLevel;
|
||||
this.snapshotInfo = snapshotInfo;
|
||||
this.groupId = (groupId == null) ? "" : groupId;
|
||||
this.artifactId = (artifactId == null) ? "" : artifactId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method returns canonical "not known" version, which is used as version
|
||||
* in cases where actual version information is not known (instead of null).
|
||||
*
|
||||
* @return Version instance to use as a placeholder when actual version is not known
|
||||
* (or not relevant)
|
||||
*/
|
||||
public static Version unknownVersion() {
|
||||
return UNKNOWN_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code True} if this instance is the one returned by
|
||||
* call to {@link #unknownVersion()}
|
||||
* @since 2.7 to replace misspelled {@link #isUknownVersion()}
|
||||
*/
|
||||
public boolean isUnknownVersion() {
|
||||
return (this == UNKNOWN_VERSION);
|
||||
}
|
||||
|
||||
public boolean isSnapshot() {
|
||||
return (snapshotInfo != null && snapshotInfo.length() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code True} if this instance is the one returned by
|
||||
* call to {@link #unknownVersion()}
|
||||
* @deprecated Since 2.7 use correctly spelled method {@link #isUnknownVersion()}
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isUknownVersion() {
|
||||
return isUnknownVersion();
|
||||
}
|
||||
|
||||
public int getMajorVersion() {
|
||||
return majorVersion;
|
||||
}
|
||||
|
||||
public int getMinorVersion() {
|
||||
return minorVersion;
|
||||
}
|
||||
|
||||
public int getPatchLevel() {
|
||||
return patchLevel;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public String getArtifactId() {
|
||||
return artifactId;
|
||||
}
|
||||
|
||||
public String toFullString() {
|
||||
return groupId + '/' + artifactId + '/' + toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(majorVersion).append('.');
|
||||
sb.append(minorVersion).append('.');
|
||||
sb.append(patchLevel);
|
||||
if (isSnapshot()) {
|
||||
sb.append('-').append(snapshotInfo);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return artifactId.hashCode() ^ groupId.hashCode() + majorVersion - minorVersion + patchLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
if (o == null) {
|
||||
return false;
|
||||
}
|
||||
if (o.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
Version other = (Version) o;
|
||||
return (other.majorVersion == majorVersion)
|
||||
&& (other.minorVersion == minorVersion)
|
||||
&& (other.patchLevel == patchLevel)
|
||||
&& other.artifactId.equals(artifactId)
|
||||
&& other.groupId.equals(groupId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Version other) {
|
||||
if (other == this) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int diff = groupId.compareTo(other.groupId);
|
||||
if (diff == 0) {
|
||||
diff = artifactId.compareTo(other.artifactId);
|
||||
if (diff == 0) {
|
||||
diff = majorVersion - other.majorVersion;
|
||||
if (diff == 0) {
|
||||
diff = minorVersion - other.minorVersion;
|
||||
if (diff == 0) {
|
||||
diff = patchLevel - other.patchLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return diff;
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core.json;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.FormatFeature;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonParser;
|
||||
|
||||
public enum JsonReadFeature
|
||||
implements FormatFeature {
|
||||
ALLOW_UNESCAPED_CONTROL_CHARS(false, JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS);
|
||||
|
||||
final boolean defaultState;
|
||||
final int mask;
|
||||
final JsonParser.Feature mappedFeature;
|
||||
|
||||
JsonReadFeature(
|
||||
boolean defaultState,
|
||||
JsonParser.Feature mapTo
|
||||
) {
|
||||
this.defaultState = defaultState;
|
||||
mask = (1 << ordinal());
|
||||
mappedFeature = mapTo;
|
||||
}
|
||||
|
||||
public JsonParser.Feature mappedFeature() {
|
||||
return mappedFeature;
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core.type;
|
||||
|
||||
public abstract class ResolvedType {
|
||||
public abstract Class<?> getRawClass();
|
||||
|
||||
public abstract boolean isContainerType();
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core.type;
|
||||
|
||||
public abstract class TypeReference<T>
|
||||
extends com.alibaba.fastjson2.TypeReference<T> {
|
||||
protected TypeReference() {
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core.util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
public class ByteArrayBuilder
|
||||
extends ByteArrayOutputStream {
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core.util;
|
||||
|
||||
public class DefaultIndenter
|
||||
extends DefaultPrettyPrinter.NopIndenter {
|
||||
public static final String SYS_LF;
|
||||
|
||||
static {
|
||||
String lf;
|
||||
try {
|
||||
lf = System.getProperty("line.separator");
|
||||
} catch (Throwable t) {
|
||||
lf = "\n"; // fallback when security manager denies access
|
||||
}
|
||||
SYS_LF = lf;
|
||||
}
|
||||
|
||||
public static final DefaultIndenter SYSTEM_LINEFEED_INSTANCE = new DefaultIndenter(" ", SYS_LF);
|
||||
|
||||
private static final int INDENT_LEVELS = 16;
|
||||
private final char[] indents;
|
||||
private final int charsPerLevel;
|
||||
private final String eol;
|
||||
|
||||
public DefaultIndenter() {
|
||||
this(" ", SYS_LF);
|
||||
}
|
||||
|
||||
public DefaultIndenter(String indent, String eol) {
|
||||
charsPerLevel = indent.length();
|
||||
|
||||
indents = new char[indent.length() * INDENT_LEVELS];
|
||||
int offset = 0;
|
||||
for (int i = 0; i < INDENT_LEVELS; i++) {
|
||||
indent.getChars(0, indent.length(), indents, offset);
|
||||
offset += indent.length();
|
||||
}
|
||||
|
||||
this.eol = eol;
|
||||
}
|
||||
|
||||
public DefaultIndenter withLinefeed(String lf) {
|
||||
if (lf.equals(eol)) {
|
||||
return this;
|
||||
}
|
||||
return new DefaultIndenter(getIndent(), lf);
|
||||
}
|
||||
|
||||
public String getIndent() {
|
||||
return new String(indents, 0, charsPerLevel);
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core.util;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonGenerator;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.PrettyPrinter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class DefaultPrettyPrinter
|
||||
implements PrettyPrinter {
|
||||
protected Indenter objectIndenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE;
|
||||
|
||||
public DefaultPrettyPrinter withObjectIndenter(Indenter i) {
|
||||
if (i == null) {
|
||||
i = NopIndenter.instance;
|
||||
}
|
||||
if (objectIndenter == i) {
|
||||
return this;
|
||||
}
|
||||
DefaultPrettyPrinter pp = new DefaultPrettyPrinter(this);
|
||||
pp.objectIndenter = i;
|
||||
return pp;
|
||||
}
|
||||
|
||||
public DefaultPrettyPrinter() {
|
||||
}
|
||||
|
||||
public DefaultPrettyPrinter(DefaultPrettyPrinter base) {
|
||||
this.objectIndenter = base.objectIndenter;
|
||||
}
|
||||
|
||||
public interface Indenter {
|
||||
void writeIndentation(JsonGenerator g, int level) throws IOException;
|
||||
|
||||
boolean isInline();
|
||||
}
|
||||
|
||||
public static class NopIndenter
|
||||
implements Indenter, java.io.Serializable {
|
||||
public static final NopIndenter instance = new NopIndenter();
|
||||
|
||||
@Override
|
||||
public void writeIndentation(JsonGenerator g, int level) throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInline() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.core.util;
|
||||
|
||||
public interface JacksonFeature {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
public class BeanProperty {
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.type.TypeFactory;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public abstract class DatabindContext {
|
||||
public abstract Object getAttribute(Object key);
|
||||
|
||||
public abstract TypeFactory getTypeFactory();
|
||||
|
||||
public abstract JavaType constructSpecializedType(JavaType baseType, Class<?> subclass);
|
||||
|
||||
public JavaType constructType(Type type) {
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
return getTypeFactory().constructType(type);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonProcessingException;
|
||||
|
||||
public class DatabindException
|
||||
extends JsonProcessingException {
|
||||
public DatabindException() {
|
||||
}
|
||||
|
||||
public DatabindException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DatabindException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.JSONFactory;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.node.JsonNodeFactory;
|
||||
import com.alibaba.fastjson2.reader.ObjectReaderProvider;
|
||||
|
||||
import static com.alibaba.fastjson2.JSONReader.Feature.Base64StringAsByteArray;
|
||||
import static com.alibaba.fastjson2.adapter.jackson.databind.DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES;
|
||||
|
||||
public class DeserializationConfig {
|
||||
private int features;
|
||||
final ObjectReaderProvider readerProvider;
|
||||
|
||||
public DeserializationConfig() {
|
||||
this.readerProvider = new ObjectReaderProvider();
|
||||
}
|
||||
|
||||
public DeserializationConfig with(DeserializationFeature f) {
|
||||
features |= f.getMask();
|
||||
return this;
|
||||
}
|
||||
|
||||
public DeserializationConfig without(DeserializationFeature feature) {
|
||||
features &= ~feature.getMask();
|
||||
return this;
|
||||
}
|
||||
|
||||
JSONReader.Context createReaderContext() {
|
||||
JSONReader.Context context = JSONFactory.createReadContext(readerProvider, Base64StringAsByteArray);
|
||||
configTo(context);
|
||||
return context;
|
||||
}
|
||||
|
||||
public void configTo(JSONReader.Context context) {
|
||||
if ((features & FAIL_ON_NULL_FOR_PRIMITIVES.getMask()) != 0) {
|
||||
context.config(JSONReader.Feature.ErrorOnNullForPrimitives);
|
||||
}
|
||||
}
|
||||
|
||||
public final JsonNodeFactory getNodeFactory() {
|
||||
return new JsonNodeFactory();
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonParser;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.type.TypeFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class DeserializationContext
|
||||
extends DatabindContext {
|
||||
final Type fieldType;
|
||||
final Object fieldName;
|
||||
final long features;
|
||||
|
||||
public DeserializationContext(Type fieldType, Object fieldName, long features) {
|
||||
this.fieldType = fieldType;
|
||||
this.fieldName = fieldName;
|
||||
this.features = features;
|
||||
}
|
||||
|
||||
public <T> T readValue(JsonParser p, Class<T> type) throws IOException {
|
||||
if (JsonNode.class.isAssignableFrom(type)) {
|
||||
return p.readValueAsTree();
|
||||
}
|
||||
return p.getJSONReader().read(type);
|
||||
}
|
||||
|
||||
public <T> T readValue(JsonParser p, JavaType javaType) throws IOException {
|
||||
Type type = javaType.getType();
|
||||
if (type instanceof Class && JsonNode.class.isAssignableFrom((Class) type)) {
|
||||
return p.readValueAsTree();
|
||||
}
|
||||
return p.getJSONReader().read(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getAttribute(Object key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public final TypeFactory getTypeFactory() {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass)
|
||||
throws IllegalArgumentException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.cfg.ConfigFeature;
|
||||
|
||||
public enum DeserializationFeature
|
||||
implements ConfigFeature {
|
||||
USE_BIG_DECIMAL_FOR_FLOATS(false),
|
||||
USE_BIG_INTEGER_FOR_INTS(false),
|
||||
USE_LONG_FOR_INTS(false),
|
||||
USE_JAVA_ARRAY_FOR_JSON_ARRAY(false),
|
||||
FAIL_ON_UNKNOWN_PROPERTIES(true),
|
||||
FAIL_ON_NULL_FOR_PRIMITIVES(false),
|
||||
FAIL_ON_NUMBERS_FOR_ENUMS(false),
|
||||
FAIL_ON_INVALID_SUBTYPE(true),
|
||||
FAIL_ON_READING_DUP_TREE_KEY(false),
|
||||
FAIL_ON_IGNORED_PROPERTIES(false),
|
||||
FAIL_ON_UNRESOLVED_OBJECT_IDS(true),
|
||||
FAIL_ON_MISSING_CREATOR_PROPERTIES(false),
|
||||
FAIL_ON_NULL_CREATOR_PROPERTIES(false),
|
||||
FAIL_ON_MISSING_EXTERNAL_TYPE_ID_PROPERTY(true),
|
||||
FAIL_ON_TRAILING_TOKENS(false),
|
||||
WRAP_EXCEPTIONS(true),
|
||||
ACCEPT_SINGLE_VALUE_AS_ARRAY(false),
|
||||
UNWRAP_SINGLE_VALUE_ARRAYS(false),
|
||||
UNWRAP_ROOT_VALUE(false),
|
||||
ACCEPT_EMPTY_STRING_AS_NULL_OBJECT(false),
|
||||
ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT(false),
|
||||
ACCEPT_FLOAT_AS_INT(true),
|
||||
READ_ENUMS_USING_TO_STRING(false),
|
||||
READ_UNKNOWN_ENUM_VALUES_AS_NULL(false),
|
||||
READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE(false),
|
||||
READ_DATE_TIMESTAMPS_AS_NANOSECONDS(true),
|
||||
ADJUST_DATES_TO_CONTEXT_TIME_ZONE(true),
|
||||
EAGER_DESERIALIZER_FETCH(true);
|
||||
|
||||
private final boolean defaultState;
|
||||
private final int mask;
|
||||
|
||||
DeserializationFeature(boolean defaultState) {
|
||||
this.defaultState = defaultState;
|
||||
mask = (1 << ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enabledByDefault() {
|
||||
return defaultState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMask() {
|
||||
return mask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enabledIn(int flags) {
|
||||
return (flags & mask) != 0;
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
|
||||
public abstract class InjectableValues {
|
||||
public static class Std
|
||||
extends InjectableValues
|
||||
implements java.io.Serializable {
|
||||
public Std addValue(String key, Object value) {
|
||||
// TODO addValue
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.type.ResolvedType;
|
||||
import com.alibaba.fastjson2.util.TypeUtils;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
public class JavaType
|
||||
extends ResolvedType
|
||||
implements java.io.Serializable, // 2.1
|
||||
java.lang.reflect.Type // 2.2
|
||||
{
|
||||
protected final Type type;
|
||||
protected final Class clazz;
|
||||
|
||||
public JavaType(Type type) {
|
||||
this.type = type;
|
||||
this.clazz = TypeUtils.getClass(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Class<?> getRawClass() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContainerType() {
|
||||
return Map.class.isAssignableFrom(clazz)
|
||||
|| Collection.class.isAssignableFrom(clazz);
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JacksonException;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonParser;
|
||||
import com.alibaba.fastjson2.reader.ObjectReader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public abstract class JsonDeserializer<T>
|
||||
implements ObjectReader {
|
||||
public abstract T deserialize(JsonParser p, DeserializationContext ctx)
|
||||
throws IOException, JacksonException;
|
||||
|
||||
@Override
|
||||
public Object readObject(JSONReader jsonReader, Type fieldType, Object fieldName, long features) {
|
||||
JsonParser p = new JsonParser(jsonReader);
|
||||
DeserializationContext ctx = new DeserializationContext(fieldType, fieldName, features);
|
||||
T object = null;
|
||||
try {
|
||||
object = deserialize(p, ctx);
|
||||
} catch (JsonMappingException e) {
|
||||
throw new JSONException(e.getMessage(), e.getCause());
|
||||
} catch (IOException e) {
|
||||
throw new JSONException("deserialize error", e);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
public abstract static class None
|
||||
extends JsonDeserializer<Object> {
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
public class JsonMappingException
|
||||
extends DatabindException {
|
||||
public JsonMappingException() {
|
||||
}
|
||||
|
||||
public JsonMappingException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JsonMappingException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public JsonMappingException(Closeable processor, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public JsonMappingException(Closeable processor, String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -1,287 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.*;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.jsontype.TypeSerializer;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.node.JsonNodeType;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class JsonNode
|
||||
implements TreeNode, Iterable<JsonNode> {
|
||||
@Override
|
||||
public JsonNode get(String fieldName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract String asText();
|
||||
|
||||
public int asInt() {
|
||||
return asInt(0);
|
||||
}
|
||||
|
||||
public boolean asBoolean() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int asInt(int defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public long asLong() {
|
||||
return asLong(0L);
|
||||
}
|
||||
|
||||
public long asLong(long defaultValue) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return asText();
|
||||
}
|
||||
|
||||
public String toPrettyString() {
|
||||
return JSON.toJSONString(JSONWriter.Feature.PrettyFormat);
|
||||
}
|
||||
|
||||
public JsonNode path(String fieldName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isArray() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Iterator<Map.Entry<String, JsonNode>> fields() {
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<JsonNode> iterator() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Iterator<JsonNode> elements() {
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
public byte[] binaryValue() throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String textValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isTextual() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean has(int index) {
|
||||
return get(index) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode get(int index) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean has(String fieldName) {
|
||||
return get(fieldName) != null;
|
||||
}
|
||||
|
||||
public JsonParser.NumberType numberType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T extends JsonNode> T deepCopy() {
|
||||
// TODO deepCopy
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
@JSONField(serialize = false)
|
||||
public JsonNodeType getNodeType() {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public JsonNode path(int index) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public JsonParser traverse() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public JsonParser traverse(ObjectCodec codec) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
protected JsonNode _at(JsonPointer ptr) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public JsonNode findValue(String fieldName) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public JsonNode findPath(String fieldName) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public JsonNode findParent(String fieldName) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public List<JsonNode> findValues(String fieldName, List<JsonNode> foundSoFar) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public List<String> findValuesAsText(String fieldName, List<String> foundSoFar) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public List<JsonNode> findParents(String fieldName, List<JsonNode> foundSoFar) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void serialize(JsonGenerator gen, SerializerProvider serializers)
|
||||
throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void serializeWithType(JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer)
|
||||
throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean canConvertToLong() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public JsonToken asToken() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public long longValue() {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public int intValue() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean booleanValue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isObject() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public BigDecimal decimalValue() {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
public float floatValue() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public double doubleValue() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean canConvertToInt() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
public final boolean isValueNode() {
|
||||
switch (getNodeType()) {
|
||||
case ARRAY:
|
||||
case OBJECT:
|
||||
case MISSING:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean isNull() {
|
||||
return getNodeType() == JsonNodeType.NULL;
|
||||
}
|
||||
|
||||
public JsonNode required(String propertyName) throws IllegalArgumentException {
|
||||
return _reportRequiredViolation("Node of type `%s` has no fields", getClass().getName());
|
||||
}
|
||||
|
||||
protected <T> T _reportRequiredViolation(String msgTemplate, Object... args) {
|
||||
throw new IllegalArgumentException(String.format(msgTemplate, args));
|
||||
}
|
||||
|
||||
public boolean isMissingNode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean isBoolean() {
|
||||
return getNodeType() == JsonNodeType.BOOLEAN;
|
||||
}
|
||||
|
||||
public boolean hasNonNull(String fieldName) {
|
||||
JsonNode n = get(fieldName);
|
||||
return (n != null) && !n.isNull();
|
||||
}
|
||||
|
||||
public final JsonNode at(String jsonPtrExpr) {
|
||||
return at(JsonPointer.compile(jsonPtrExpr));
|
||||
}
|
||||
|
||||
public final JsonNode at(JsonPointer ptr) {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public boolean isFloat() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isDouble() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBigDecimal() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBigInteger() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public final boolean isContainerNode() {
|
||||
final JsonNodeType type = getNodeType();
|
||||
return type == JsonNodeType.OBJECT || type == JsonNodeType.ARRAY;
|
||||
}
|
||||
|
||||
public double asDouble() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public BigInteger bigIntegerValue() {
|
||||
return BigInteger.ZERO;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonGenerator;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.jsontype.TypeSerializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface JsonSerializable {
|
||||
void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException;
|
||||
|
||||
void serializeWithType(
|
||||
JsonGenerator gen,
|
||||
SerializerProvider serializers,
|
||||
TypeSerializer typeSer
|
||||
) throws IOException;
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonEncoding;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonGenerator;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.jsontype.TypeSerializer;
|
||||
import com.alibaba.fastjson2.writer.ObjectWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public abstract class JsonSerializer<T>
|
||||
implements ObjectWriter {
|
||||
public abstract void serialize(T value, JsonGenerator gen, SerializerProvider serializers)
|
||||
throws IOException;
|
||||
|
||||
@Override
|
||||
public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
|
||||
JsonGenerator gen = new JsonGenerator(jsonWriter, null, JsonEncoding.UTF8);
|
||||
try {
|
||||
serialize((T) object, gen, null);
|
||||
} catch (IOException e) {
|
||||
throw new JSONException("write error");
|
||||
}
|
||||
}
|
||||
|
||||
public Class<T> handledType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract static class None
|
||||
extends JsonSerializer<Object> {
|
||||
}
|
||||
|
||||
public void serializeWithType(
|
||||
T value,
|
||||
JsonGenerator gen,
|
||||
SerializerProvider serializers,
|
||||
TypeSerializer typeSer
|
||||
) throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public abstract class KeyDeserializer
|
||||
implements com.alibaba.fastjson2.reader.ObjectReader {
|
||||
@Override
|
||||
public Object readObject(JSONReader jsonReader, Type fieldType, Object fieldName, long features) {
|
||||
String str = jsonReader.readFieldName();
|
||||
DeserializationContext context = new DeserializationContext(fieldType, fieldName, features);
|
||||
try {
|
||||
return deserializeKey(str, context);
|
||||
} catch (IOException e) {
|
||||
throw new JSONException("deserializeKey error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Object deserializeKey(String key, DeserializationContext ctxt)
|
||||
throws IOException;
|
||||
|
||||
public abstract static class None
|
||||
extends KeyDeserializer {
|
||||
}
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.cfg.ConfigFeature;
|
||||
|
||||
public enum MapperFeature implements ConfigFeature {
|
||||
USE_ANNOTATIONS(true),
|
||||
USE_GETTERS_AS_SETTERS(true),
|
||||
PROPAGATE_TRANSIENT_MARKER(false),
|
||||
AUTO_DETECT_CREATORS(true),
|
||||
AUTO_DETECT_FIELDS(true),
|
||||
|
||||
/**
|
||||
* Feature that determines whether regular "getter" methods are
|
||||
* automatically detected based on standard Bean naming convention
|
||||
* or not. If yes, then all public zero-argument methods that
|
||||
* start with prefix "get"
|
||||
* are considered as getters.
|
||||
* If disabled, only methods explicitly annotated are considered getters.
|
||||
* <p>
|
||||
* Note that since version 1.3, this does <b>NOT</b> include
|
||||
* "is getters" (see {@link #AUTO_DETECT_IS_GETTERS} for details)
|
||||
* <p>
|
||||
* Note that this feature has lower precedence than per-class
|
||||
* annotations, and is only used if there isn't more granular
|
||||
* configuration available.
|
||||
* <p>
|
||||
* Feature is enabled by default.
|
||||
*/
|
||||
AUTO_DETECT_GETTERS(true),
|
||||
|
||||
/**
|
||||
* Feature that determines whether "is getter" methods are
|
||||
* automatically detected based on standard Bean naming convention
|
||||
* or not. If yes, then all public zero-argument methods that
|
||||
* start with prefix "is", and whose return type is boolean
|
||||
* are considered as "is getters".
|
||||
* If disabled, only methods explicitly annotated are considered getters.
|
||||
* <p>
|
||||
* Note that this feature has lower precedence than per-class
|
||||
* annotations, and is only used if there isn't more granular
|
||||
* configuration available.
|
||||
* <p>
|
||||
* Feature is enabled by default.
|
||||
*/
|
||||
AUTO_DETECT_IS_GETTERS(true),
|
||||
|
||||
/**
|
||||
* Feature that determines whether "setter" methods are
|
||||
* automatically detected based on standard Bean naming convention
|
||||
* or not. If yes, then all public one-argument methods that
|
||||
* start with prefix "set"
|
||||
* are considered setters. If disabled, only methods explicitly
|
||||
* annotated are considered setters.
|
||||
* <p>
|
||||
* Note that this feature has lower precedence than per-class
|
||||
* annotations, and is only used if there isn't more granular
|
||||
* configuration available.
|
||||
* <p>
|
||||
* Feature is enabled by default.
|
||||
*/
|
||||
AUTO_DETECT_SETTERS(true),
|
||||
|
||||
/**
|
||||
* Feature that determines whether getters (getter methods)
|
||||
* can be auto-detected if there is no matching mutator (setter,
|
||||
* constructor parameter or field) or not: if set to true,
|
||||
* only getters that match a mutator are auto-discovered; if
|
||||
* false, all auto-detectable getters can be discovered.
|
||||
* <p>
|
||||
* Feature is disabled by default.
|
||||
*/
|
||||
REQUIRE_SETTERS_FOR_GETTERS(false),
|
||||
|
||||
/**
|
||||
* Feature that determines whether member fields declared as 'final' may
|
||||
* be auto-detected to be used mutators (used to change value of the logical
|
||||
* property) or not. If enabled, 'final' access modifier has no effect, and
|
||||
* such fields may be detected according to usual visibility and inference
|
||||
* rules; if disabled, such fields are NOT used as mutators except if
|
||||
* explicitly annotated for such use.
|
||||
* <p>
|
||||
* Feature is enabled by default, for backwards compatibility reasons.
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
ALLOW_FINAL_FIELDS_AS_MUTATORS(true),
|
||||
|
||||
/**
|
||||
* Feature that determines whether member mutators (fields and
|
||||
* setters) may be "pulled in" even if they are not visible,
|
||||
* as long as there is a visible accessor (getter or field) with same name.
|
||||
* For example: field "value" may be inferred as mutator,
|
||||
* if there is visible or explicitly marked getter "getValue()".
|
||||
* If enabled, inferring is enabled; otherwise (disabled) only visible and
|
||||
* explicitly annotated accessors are ever used.
|
||||
* <p>
|
||||
* Note that 'getters' are never inferred and need to be either visible (including
|
||||
* bean-style naming) or explicitly annotated.
|
||||
* <p>
|
||||
* Feature is enabled by default.
|
||||
*
|
||||
* @since 2.2
|
||||
*/
|
||||
INFER_PROPERTY_MUTATORS(true),
|
||||
INFER_CREATOR_FROM_CONSTRUCTOR_PROPERTIES(true),
|
||||
ALLOW_VOID_VALUED_PROPERTIES(false),
|
||||
CAN_OVERRIDE_ACCESS_MODIFIERS(true),
|
||||
OVERRIDE_PUBLIC_ACCESS_MODIFIERS(true),
|
||||
|
||||
USE_STATIC_TYPING(false),
|
||||
USE_BASE_TYPE_AS_DEFAULT_IMPL(false),
|
||||
INFER_BUILDER_TYPE_BINDINGS(true),
|
||||
DEFAULT_VIEW_INCLUSION(true),
|
||||
SORT_PROPERTIES_ALPHABETICALLY(false),
|
||||
SORT_CREATOR_PROPERTIES_FIRST(true),
|
||||
ACCEPT_CASE_INSENSITIVE_PROPERTIES(false),
|
||||
ACCEPT_CASE_INSENSITIVE_ENUMS(false),
|
||||
ACCEPT_CASE_INSENSITIVE_VALUES(false),
|
||||
|
||||
USE_WRAPPER_NAME_AS_PROPERTY_NAME(false),
|
||||
USE_STD_BEAN_NAMING(false),
|
||||
ALLOW_EXPLICIT_PROPERTY_RENAMING(false),
|
||||
ALLOW_COERCION_OF_SCALARS(true),
|
||||
|
||||
/*
|
||||
/******************************************************
|
||||
/* Other features
|
||||
/******************************************************
|
||||
*/
|
||||
|
||||
IGNORE_DUPLICATE_MODULE_REGISTRATIONS(true),
|
||||
IGNORE_MERGE_FOR_UNMERGEABLE(true),
|
||||
|
||||
BLOCK_UNSAFE_POLYMORPHIC_BASE_TYPES(false),
|
||||
APPLY_DEFAULT_VALUES(true);
|
||||
|
||||
private final boolean defaultState;
|
||||
private final long mask;
|
||||
|
||||
// @since 2.13
|
||||
public static long collectLongDefaults() {
|
||||
long flags = 0;
|
||||
for (MapperFeature value : MapperFeature.values()) {
|
||||
if (value.enabledByDefault()) {
|
||||
flags |= value.getLongMask();
|
||||
}
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
private MapperFeature(boolean defaultState) {
|
||||
this.defaultState = defaultState;
|
||||
mask = (1L << ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enabledByDefault() {
|
||||
return defaultState;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated // 2.13
|
||||
public int getMask() {
|
||||
// 25-Feb-2021, tatu: Not 100% sure what to do here; should not be
|
||||
// called any more
|
||||
return (int) mask;
|
||||
}
|
||||
|
||||
// @since 2.13
|
||||
public long getLongMask() {
|
||||
return mask;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean enabledIn(int flags) {
|
||||
return (flags & mask) != 0;
|
||||
}
|
||||
|
||||
// @since 2.13
|
||||
public boolean enabledIn(long flags) {
|
||||
return (flags & mask) != 0;
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
public abstract class MappingIterator<T>
|
||||
implements Iterator<T>, Closeable {
|
||||
public T nextValue() throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonFactory;
|
||||
|
||||
public class MappingJsonFactory
|
||||
extends JsonFactory {
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.modules.ObjectReaderModule;
|
||||
import com.alibaba.fastjson2.modules.ObjectWriterModule;
|
||||
|
||||
public abstract class Module {
|
||||
public ObjectWriterModule getWriterModule() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public ObjectReaderModule getReaderModule() {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonParser;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.ObjectCodec;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.TreeNode;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.node.TreeNodeUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ObjectCodecWrapper
|
||||
extends ObjectCodec {
|
||||
public ObjectCodecWrapper() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends TreeNode> T readTree(JsonParser p) throws IOException {
|
||||
JSONReader jsonReader = p.getJSONReader();
|
||||
Object any = jsonReader.readAny();
|
||||
return (T) TreeNodeUtils.as(any);
|
||||
}
|
||||
}
|
@ -1,542 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.*;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.*;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.exc.StreamReadException;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.node.ArrayNode;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.node.JsonNodeFactory;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.node.ObjectNode;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.node.TreeNodeUtils;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.type.TypeFactory;
|
||||
import com.alibaba.fastjson2.modules.ObjectReaderModule;
|
||||
import com.alibaba.fastjson2.modules.ObjectWriterModule;
|
||||
import com.alibaba.fastjson2.reader.ObjectReader;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static com.alibaba.fastjson2.JSONReader.Feature.IgnoreCheckClose;
|
||||
|
||||
public class ObjectMapper
|
||||
extends ObjectCodec {
|
||||
protected final JsonFactory factory;
|
||||
protected TypeFactory typeFactory;
|
||||
protected SerializationConfig serializationConfig;
|
||||
protected DeserializationConfig deserializationConfig;
|
||||
|
||||
public ObjectMapper() {
|
||||
this(new JsonFactory());
|
||||
}
|
||||
|
||||
public ObjectMapper(JsonFactory factory) {
|
||||
this.factory = factory;
|
||||
this.typeFactory = new TypeFactory();
|
||||
|
||||
serializationConfig = new SerializationConfig();
|
||||
deserializationConfig = new DeserializationConfig();
|
||||
}
|
||||
|
||||
public String writeValueAsString(Object value) throws JsonProcessingException {
|
||||
JSONWriter.Context context = createWriterContext();
|
||||
|
||||
try (JSONWriter writer = JSONWriter.of(context)) {
|
||||
if (value == null) {
|
||||
writer.writeNull();
|
||||
} else {
|
||||
writer.setRootObject(value);
|
||||
|
||||
Class<?> valueClass = value.getClass();
|
||||
if (valueClass == JSONObject.class) {
|
||||
writer.write((JSONObject) value);
|
||||
} else {
|
||||
boolean fieldBased = (context.getFeatures() & JSONWriter.Feature.FieldBased.mask) != 0;
|
||||
com.alibaba.fastjson2.writer.ObjectWriter<?> objectWriter = serializationConfig.writerProvider.getObjectWriter(valueClass, valueClass, fieldBased);
|
||||
objectWriter.write(writer, value, null, null, 0);
|
||||
}
|
||||
}
|
||||
return writer.toString();
|
||||
}
|
||||
}
|
||||
|
||||
private JSONWriter.Context createWriterContext() {
|
||||
return serializationConfig.createWriterContext();
|
||||
}
|
||||
|
||||
public byte[] writeValueAsBytes(Object value) throws JsonProcessingException {
|
||||
JSONWriter.Context context = createWriterContext();
|
||||
|
||||
try (JSONWriter writer = JSONWriter.of(context)) {
|
||||
if (value == null) {
|
||||
writer.writeNull();
|
||||
} else {
|
||||
writer.setRootObject(value);
|
||||
|
||||
Class<?> valueClass = value.getClass();
|
||||
if (valueClass == JSONObject.class) {
|
||||
writer.write((JSONObject) value);
|
||||
} else {
|
||||
boolean fieldBased = (context.getFeatures() & JSONWriter.Feature.FieldBased.mask) != 0;
|
||||
com.alibaba.fastjson2.writer.ObjectWriter<?> objectWriter = serializationConfig.writerProvider.getObjectWriter(valueClass, valueClass, fieldBased);
|
||||
objectWriter.write(writer, value, null, null, 0);
|
||||
}
|
||||
}
|
||||
return writer.getBytes();
|
||||
}
|
||||
}
|
||||
|
||||
public void writeValue(OutputStream out, Object value) throws IOException {
|
||||
JSONWriter.Context context = createWriterContext();
|
||||
|
||||
try (JSONWriter writer = JSONWriter.of(context)) {
|
||||
if (value == null) {
|
||||
writer.writeNull();
|
||||
} else {
|
||||
writer.setRootObject(value);
|
||||
|
||||
Class<?> valueClass = value.getClass();
|
||||
if (valueClass == JSONObject.class) {
|
||||
writer.write((JSONObject) value);
|
||||
} else {
|
||||
boolean fieldBased = (context.getFeatures() & JSONWriter.Feature.FieldBased.mask) != 0;
|
||||
com.alibaba.fastjson2.writer.ObjectWriter<?> objectWriter = serializationConfig.writerProvider.getObjectWriter(valueClass, valueClass, fieldBased);
|
||||
objectWriter.write(writer, value, null, null, 0);
|
||||
}
|
||||
}
|
||||
writer.flushTo(out);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeValue(File resultFile, Object value) throws IOException {
|
||||
JSONWriter.Context context = createWriterContext();
|
||||
|
||||
try (JSONWriter writer = JSONWriter.of(context); FileOutputStream out = new FileOutputStream(resultFile)) {
|
||||
if (value == null) {
|
||||
writer.writeNull();
|
||||
} else {
|
||||
writer.setRootObject(value);
|
||||
|
||||
Class<?> valueClass = value.getClass();
|
||||
if (valueClass == JSONObject.class) {
|
||||
writer.write((JSONObject) value);
|
||||
} else {
|
||||
boolean fieldBased = (context.getFeatures() & JSONWriter.Feature.FieldBased.mask) != 0;
|
||||
com.alibaba.fastjson2.writer.ObjectWriter<?> objectWriter = serializationConfig.writerProvider.getObjectWriter(valueClass, valueClass, fieldBased);
|
||||
objectWriter.write(writer, value, null, null, 0);
|
||||
}
|
||||
}
|
||||
writer.flushTo(out);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeValue(Writer w, Object value)
|
||||
throws IOException, DatabindException {
|
||||
JSONWriter.Context context = createWriterContext();
|
||||
|
||||
try (JSONWriter writer = JSONWriter.of(context)) {
|
||||
if (value == null) {
|
||||
writer.writeNull();
|
||||
} else {
|
||||
writer.setRootObject(value);
|
||||
|
||||
Class<?> valueClass = value.getClass();
|
||||
if (valueClass == JSONObject.class) {
|
||||
writer.write((JSONObject) value);
|
||||
} else {
|
||||
boolean fieldBased = (context.getFeatures() & JSONWriter.Feature.FieldBased.mask) != 0;
|
||||
com.alibaba.fastjson2.writer.ObjectWriter<?> objectWriter = serializationConfig.writerProvider.getObjectWriter(valueClass, valueClass, fieldBased);
|
||||
objectWriter.write(writer, value, null, null, 0);
|
||||
}
|
||||
}
|
||||
writer.flushTo(w);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T readValue(String content, Class<T> valueType)
|
||||
throws JsonMappingException, JsonParseException {
|
||||
if (content == null || content.isEmpty()) {
|
||||
throw new JsonParseException("input is null or empty");
|
||||
}
|
||||
|
||||
JSONReader.Context context = createReaderContext();
|
||||
long features = context.getFeatures();
|
||||
|
||||
try (JSONReader reader = JSONReader.of(content, context)) {
|
||||
boolean fieldBased = (features & JSONReader.Feature.FieldBased.mask) != 0;
|
||||
ObjectReader<T> objectReader = deserializationConfig.readerProvider.getObjectReader(valueType, fieldBased);
|
||||
|
||||
T object = objectReader.readObject(reader, null, null, 0);
|
||||
reader.handleResolveTasks(object);
|
||||
if ((!reader.isEnd()) && (features & IgnoreCheckClose.mask) == 0) {
|
||||
throw new JSONException(reader.info("input not end"));
|
||||
}
|
||||
return object;
|
||||
} catch (JSONException e) {
|
||||
throw new JsonMappingException(e.getMessage(), e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T readValue(byte[] content, Class<T> valueType)
|
||||
throws JsonMappingException, JsonParseException {
|
||||
if (content == null || content.length == 0) {
|
||||
throw new JsonParseException("input is null or empty");
|
||||
}
|
||||
|
||||
JSONReader.Context context = createReaderContext();
|
||||
long features = context.getFeatures();
|
||||
|
||||
try (JSONReader reader = JSONReader.of(content, context)) {
|
||||
boolean fieldBased = (features & JSONReader.Feature.FieldBased.mask) != 0;
|
||||
ObjectReader<T> objectReader = deserializationConfig.readerProvider.getObjectReader(valueType, fieldBased);
|
||||
|
||||
T object = objectReader.readObject(reader, null, null, 0);
|
||||
reader.handleResolveTasks(object);
|
||||
if ((!reader.isEnd()) && (features & IgnoreCheckClose.mask) == 0) {
|
||||
throw new JSONException(reader.info("input not end"));
|
||||
}
|
||||
return object;
|
||||
} catch (JSONException e) {
|
||||
throw new JsonMappingException(e.getMessage(), e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
private JSONReader.Context createReaderContext() {
|
||||
return deserializationConfig.createReaderContext();
|
||||
}
|
||||
|
||||
public <T> T readValue(String content, TypeReference<T> valueTypeRef) {
|
||||
if (content == null) {
|
||||
throw new JSONException("content is null");
|
||||
}
|
||||
|
||||
return readValue(content, valueTypeRef.getType());
|
||||
}
|
||||
|
||||
public <T> T readValue(String content, Type valueType) {
|
||||
if (content == null || content.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (valueType instanceof JavaType) {
|
||||
valueType = ((JavaType) valueType).getType();
|
||||
}
|
||||
|
||||
JSONReader.Context context = createReaderContext();
|
||||
long features = context.getFeatures();
|
||||
|
||||
try (JSONReader reader = JSONReader.of(content, context)) {
|
||||
ObjectReader<T> objectReader = context.getObjectReader(valueType);
|
||||
|
||||
T object = objectReader.readObject(reader, valueType, null, 0);
|
||||
reader.handleResolveTasks(object);
|
||||
if ((!reader.isEnd()) && (features & IgnoreCheckClose.mask) == 0) {
|
||||
throw new JSONException(reader.info("input not end"));
|
||||
}
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T readValue(URL url, Class<T> valueType) {
|
||||
if (url == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try (InputStream is = url.openStream()) {
|
||||
return readValue(is, valueType);
|
||||
} catch (IOException e) {
|
||||
throw new JSONException("can not readValue '" + url + "' to '" + valueType + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T readValue(File file, Class<T> valueType) {
|
||||
if (file == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try (InputStream is = new FileInputStream(file)) {
|
||||
return readValue(is, valueType);
|
||||
} catch (IOException e) {
|
||||
throw new JSONException("can not readValue '" + file + "' to '" + valueType + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T readValue(InputStream input, Class<T> valueType)
|
||||
throws JsonMappingException, JsonParseException {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONReader.Context context = createReaderContext();
|
||||
long features = context.getFeatures();
|
||||
|
||||
try (JSONReader reader = JSONReader.of(input, StandardCharsets.UTF_8, context)) {
|
||||
if (reader.isEnd()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ObjectReader<T> objectReader = reader.getObjectReader(valueType);
|
||||
|
||||
T object = objectReader.readObject(reader, null, null, 0);
|
||||
reader.handleResolveTasks(object);
|
||||
if ((!reader.isEnd()) && (features & IgnoreCheckClose.mask) == 0) {
|
||||
throw new JSONException(reader.info("input not end"));
|
||||
}
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
||||
public <T> T readValue(JsonParser parser, JavaType javaType) throws IOException {
|
||||
Type type = javaType.getType();
|
||||
return parser.getJSONReader().read(type);
|
||||
}
|
||||
|
||||
public ObjectNode createObjectNode() {
|
||||
return new ObjectNode();
|
||||
}
|
||||
|
||||
public ArrayNode createArrayNode() {
|
||||
return new ArrayNode();
|
||||
}
|
||||
|
||||
public ObjectMapper configure(SerializationFeature f, boolean state) {
|
||||
serializationConfig = state
|
||||
? serializationConfig.with(f)
|
||||
: serializationConfig.without(f);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ObjectMapper configure(MapperFeature f, boolean state) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObjectMapper configure(DeserializationFeature f, boolean state) {
|
||||
deserializationConfig = state
|
||||
? deserializationConfig.with(f)
|
||||
: deserializationConfig.without(f);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObjectMapper configure(JsonParser.Feature f, boolean state) {
|
||||
factory.configure(f, state);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObjectMapper configure(JsonGenerator.Feature f, boolean state) {
|
||||
factory.configure(f, state);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObjectMapper registerModule(Module module) {
|
||||
ObjectWriterModule writerModule = module.getWriterModule();
|
||||
if (writerModule != null) {
|
||||
serializationConfig.writerProvider.register(writerModule);
|
||||
}
|
||||
ObjectReaderModule readerModule = module.getReaderModule();
|
||||
if (readerModule != null) {
|
||||
deserializationConfig.readerProvider.register(readerModule);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObjectMapper addMixIn(Class<?> target, Class<?> mixinSource) {
|
||||
deserializationConfig.readerProvider.mixIn(target, mixinSource);
|
||||
deserializationConfig.readerProvider.mixIn(target, mixinSource);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends TreeNode> T readTree(JsonParser p) throws IOException {
|
||||
Object any = p.getJSONReader().readAny();
|
||||
return (T) TreeNodeUtils.as(any);
|
||||
}
|
||||
|
||||
public JsonNode readTree(String content) throws JsonProcessingException, JsonMappingException {
|
||||
JSONReader jsonReader = JSONReader.of(content);
|
||||
Object any = jsonReader.readAny();
|
||||
return TreeNodeUtils.as(any);
|
||||
}
|
||||
|
||||
public JsonNode readTree(InputStream in) throws IOException {
|
||||
JSONReader jsonReader = JSONReader.of(in, StandardCharsets.UTF_8);
|
||||
Object any = jsonReader.readAny();
|
||||
return TreeNodeUtils.as(any);
|
||||
}
|
||||
|
||||
public JsonNode readTree(Reader r) throws IOException {
|
||||
JSONReader jsonReader = JSONReader.of(r);
|
||||
Object any = jsonReader.readAny();
|
||||
return TreeNodeUtils.as(any);
|
||||
}
|
||||
|
||||
public ObjectMapper disable(SerializationFeature f) {
|
||||
this.serializationConfig = this.serializationConfig.without(f);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObjectMapper disable(DeserializationFeature f) {
|
||||
this.deserializationConfig = this.deserializationConfig.without(f);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObjectMapper disable(MapperFeature f) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TypeFactory getTypeFactory() {
|
||||
return typeFactory;
|
||||
}
|
||||
|
||||
public ObjectMapper setTypeFactory(TypeFactory f) {
|
||||
this.typeFactory = f;
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T extends JsonNode> T valueToTree(Object fromValue)
|
||||
throws IllegalArgumentException {
|
||||
return (T) TreeNodeUtils.as(fromValue);
|
||||
}
|
||||
|
||||
public <T> T treeToValue(TreeNode n, Class<T> valueType)
|
||||
throws IllegalArgumentException,
|
||||
JsonProcessingException {
|
||||
if (n instanceof ObjectNode) {
|
||||
return ((ObjectNode) n).getJSONObject().to(valueType);
|
||||
}
|
||||
|
||||
if (n instanceof ArrayNode) {
|
||||
return ((ArrayNode) n).getJSONArray().to(valueType);
|
||||
}
|
||||
|
||||
// TODO treeToValue
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public JsonNode readTree(byte[] content) throws IOException {
|
||||
Object value = JSON.parse(content);
|
||||
return TreeNodeUtils.as(value);
|
||||
}
|
||||
|
||||
public ObjectWriter writer() {
|
||||
// TODO writer
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public ObjectWriter writer(PrettyPrinter pp) {
|
||||
// TODO writer
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public ObjectWriter writer(FormatSchema schema) {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public ObjectMapper enable(DeserializationFeature feature) {
|
||||
deserializationConfig.with(feature);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObjectMapper enable(MapperFeature feature) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObjectMapper enable(SerializationFeature feature) {
|
||||
serializationConfig.with(feature);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObjectMapper enable(DeserializationFeature first,
|
||||
DeserializationFeature... features) {
|
||||
deserializationConfig.with(first);
|
||||
for (DeserializationFeature feature : features) {
|
||||
deserializationConfig.with(feature);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public JsonParser treeAsTokens(TreeNode n) {
|
||||
String str = n.toString();
|
||||
JSONReader jsonReader = JSONReader.of(str);
|
||||
return new JsonParser(jsonReader);
|
||||
}
|
||||
|
||||
public JavaType constructType(Type t) {
|
||||
return typeFactory.constructType(t);
|
||||
}
|
||||
|
||||
public JsonNodeFactory getNodeFactory() {
|
||||
return deserializationConfig.getNodeFactory();
|
||||
}
|
||||
|
||||
public JsonFactory getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
public JsonParser createParser(String content) throws IOException {
|
||||
JSONReader jsonReader = JSONReader.of(content, createReaderContext());
|
||||
return new JsonParser(jsonReader);
|
||||
}
|
||||
|
||||
public JsonParser createParser(URL src) throws IOException {
|
||||
JSONReader jsonReader = JSONReader.of(src, createReaderContext());
|
||||
return new JsonParser(jsonReader);
|
||||
}
|
||||
|
||||
public JsonParser createParser(byte[] jsonBytes) throws IOException {
|
||||
JSONReader jsonReader = JSONReader.of(jsonBytes, createReaderContext());
|
||||
return new JsonParser(jsonReader);
|
||||
}
|
||||
|
||||
public JsonParser createParser(InputStream in) throws IOException {
|
||||
JSONReader.Context context = createReaderContext();
|
||||
JSONReader jsonReader = JSONReader.of(in, StandardCharsets.UTF_8, context);
|
||||
return new JsonParser(jsonReader);
|
||||
}
|
||||
|
||||
public com.alibaba.fastjson2.adapter.jackson.databind.ObjectReader reader() {
|
||||
return new com.alibaba.fastjson2.adapter.jackson.databind.ObjectReader(
|
||||
this,
|
||||
deserializationConfig, null
|
||||
);
|
||||
}
|
||||
|
||||
public com.alibaba.fastjson2.adapter.jackson.databind.ObjectReader reader(Class<?> type) {
|
||||
return new com.alibaba.fastjson2.adapter.jackson.databind.ObjectReader(
|
||||
this,
|
||||
deserializationConfig, type
|
||||
);
|
||||
}
|
||||
|
||||
public com.alibaba.fastjson2.adapter.jackson.databind.ObjectReader readerFor(Class type) {
|
||||
return new com.alibaba.fastjson2.adapter.jackson.databind.ObjectReader(
|
||||
this,
|
||||
deserializationConfig, type
|
||||
);
|
||||
}
|
||||
|
||||
public com.alibaba.fastjson2.adapter.jackson.databind.ObjectReader readerFor(JavaType type) {
|
||||
return new com.alibaba.fastjson2.adapter.jackson.databind.ObjectReader(
|
||||
this,
|
||||
deserializationConfig, type.getType()
|
||||
);
|
||||
}
|
||||
|
||||
public ObjectWriter writerWithDefaultPrettyPrinter() {
|
||||
return new ObjectWriter(this, serializationConfig, null);
|
||||
}
|
||||
|
||||
public JsonGenerator createGenerator(OutputStream out, JsonEncoding enc) throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public void writeTree(JsonGenerator g, JsonNode rootNode)
|
||||
throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public <T> T readValue(JsonParser p, Class<T> valueType)
|
||||
throws IOException, StreamReadException, DatabindException {
|
||||
return p.getJSONReader().read(valueType);
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.JSONReader;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.FormatSchema;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonFactory;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonParser;
|
||||
import com.alibaba.fastjson2.adapter.jackson.dataformat.csv.CSVMappingIterator;
|
||||
import com.alibaba.fastjson2.support.csv.CSVParser;
|
||||
import com.alibaba.fastjson2.util.TypeUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class ObjectReader {
|
||||
final ObjectMapper mapper;
|
||||
final DeserializationConfig config;
|
||||
Type objectType;
|
||||
Class objectClass;
|
||||
final JsonFactory jsonFactory;
|
||||
|
||||
public ObjectReader(ObjectMapper mapper, DeserializationConfig config, Type objectType) {
|
||||
this.mapper = mapper;
|
||||
this.config = config;
|
||||
this.objectType = objectType;
|
||||
this.objectClass = TypeUtils.getClass(objectType);
|
||||
this.jsonFactory = mapper.factory;
|
||||
}
|
||||
|
||||
public <T> T readValue(File src, Class<T> valueType) throws IOException {
|
||||
if (jsonFactory.isCSV()) {
|
||||
JSONReader.Context context = jsonFactory.createReaderContext();
|
||||
CSVParser csvParser = CSVParser.of(src, objectClass);
|
||||
return (T) csvParser.readLoneObject();
|
||||
}
|
||||
|
||||
JSONReader jsonReader = this.jsonFactory.createJSONReader(src);
|
||||
JSONReader.Context context = jsonReader.getContext();
|
||||
com.alibaba.fastjson2.reader.ObjectReader objectReader = context.getObjectReader(objectType);
|
||||
|
||||
Object object = objectReader
|
||||
.readObject(jsonReader, null, null, 0L);
|
||||
return (T) object;
|
||||
}
|
||||
|
||||
public <T> T readValue(String src, Class<T> valueType) throws IOException {
|
||||
if (jsonFactory.isCSV()) {
|
||||
CSVParser csvParser = CSVParser.of(src, valueType);
|
||||
return (T) csvParser.readLoneObject();
|
||||
}
|
||||
|
||||
JSONReader jsonReader = this.jsonFactory.createJSONReader(src);
|
||||
JSONReader.Context context = jsonReader.getContext();
|
||||
com.alibaba.fastjson2.reader.ObjectReader objectReader = context.getObjectReader(valueType);
|
||||
|
||||
Object object = objectReader
|
||||
.readObject(jsonReader, null, null, 0L);
|
||||
return (T) object;
|
||||
}
|
||||
|
||||
public <T> T readValue(JsonParser p) throws IOException {
|
||||
JSONReader jsonReader = p.getJSONReader();
|
||||
JSONReader.Context context = jsonReader.getContext();
|
||||
com.alibaba.fastjson2.reader.ObjectReader objectReader = context.getObjectReader(objectType);
|
||||
|
||||
Object object = objectReader
|
||||
.readObject(jsonReader, null, null, 0L);
|
||||
return (T) object;
|
||||
}
|
||||
|
||||
public ObjectReader with(FormatSchema schema) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> MappingIterator<T> readValues(Reader src) throws IOException {
|
||||
if (jsonFactory.isCSV()) {
|
||||
CSVParser parser = CSVParser.of(src, objectClass);
|
||||
return new CSVMappingIterator(parser, objectClass);
|
||||
}
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public <T> MappingIterator<T> readValues(InputStream src) throws IOException {
|
||||
if (jsonFactory.isCSV()) {
|
||||
CSVParser parser = CSVParser.of(src, objectClass);
|
||||
return new CSVMappingIterator(parser, objectClass);
|
||||
}
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public ObjectReader withAttribute(Object key, Object value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObjectReader with(InjectableValues values) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> T readValue(byte[] content) throws IOException {
|
||||
JSONReader.Context context = mapper.deserializationConfig.createReaderContext();
|
||||
JSONReader jsonReader = JSONReader.of(content, context);
|
||||
com.alibaba.fastjson2.reader.ObjectReader objectReader = context.getObjectReader(objectType);
|
||||
|
||||
Object object = objectReader
|
||||
.readObject(jsonReader, null, null, 0L);
|
||||
return (T) object;
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonFactory;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonProcessingException;
|
||||
import com.alibaba.fastjson2.support.csv.CSVWriter;
|
||||
import com.alibaba.fastjson2.util.TypeUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ObjectWriter {
|
||||
final SerializationConfig config;
|
||||
final Type objectType;
|
||||
final Class objectClass;
|
||||
final JsonFactory jsonFactory;
|
||||
|
||||
public ObjectWriter(
|
||||
ObjectMapper mapper,
|
||||
SerializationConfig config,
|
||||
Type objectType
|
||||
) {
|
||||
this.config = config;
|
||||
this.objectType = objectType;
|
||||
this.objectClass = TypeUtils.getClass(objectType);
|
||||
this.jsonFactory = mapper.factory;
|
||||
}
|
||||
|
||||
public String writeValueAsString(Object value)
|
||||
throws IOException {
|
||||
if (jsonFactory.isCSV()) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
CSVWriter writer = CSVWriter.of(out, CSVWriter.Feature.AlwaysQuoteStrings);
|
||||
writer.writeRowObject(value);
|
||||
writer.close();
|
||||
String str = new String(out.toByteArray(), StandardCharsets.UTF_8);
|
||||
return str;
|
||||
}
|
||||
|
||||
JSONWriter jsonWriter = jsonFactory.createJSONWriter();
|
||||
JSONWriter.Context context = jsonWriter.getContext();
|
||||
context.getObjectWriter(objectType, objectClass)
|
||||
.write(jsonWriter, value, null, null, 0L);
|
||||
return jsonWriter.toString();
|
||||
}
|
||||
|
||||
public void writeValue(File resultFile, Object value) throws IOException {
|
||||
try (FileOutputStream fileOut = new FileOutputStream(resultFile)) {
|
||||
if (jsonFactory.isCSV()) {
|
||||
CSVWriter writer = CSVWriter.of(fileOut, CSVWriter.Feature.AlwaysQuoteStrings);
|
||||
writer.writeRowObject(value);
|
||||
writer.close();
|
||||
return;
|
||||
}
|
||||
|
||||
JSONWriter jsonWriter = jsonFactory.createJSONWriter();
|
||||
JSONWriter.Context context = jsonWriter.getContext();
|
||||
context.getObjectWriter(objectType, objectClass)
|
||||
.write(jsonWriter, value, null, null, 0L);
|
||||
jsonWriter.flushTo(fileOut);
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectWriter withDefaultPrettyPrinter() {
|
||||
// TODO withDefaultPrettyPrinter
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObjectWriter withAttribute(Object key, Object value) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public byte[] writeValueAsBytes(Object value)
|
||||
throws JsonProcessingException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public void writeValue(OutputStream out, Object value)
|
||||
throws IOException, DatabindException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
public class PropertyNamingStrategy {
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.JSONFactory;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
import com.alibaba.fastjson2.writer.ObjectWriterProvider;
|
||||
|
||||
import static com.alibaba.fastjson2.JSONWriter.Feature.WriteByteArrayAsBase64;
|
||||
|
||||
public class SerializationConfig {
|
||||
private long serFeatures;
|
||||
protected int generatorFeatures;
|
||||
final ObjectWriterProvider writerProvider;
|
||||
|
||||
public SerializationConfig() {
|
||||
this(JSONFactory.getDefaultObjectWriterProvider());
|
||||
}
|
||||
|
||||
public SerializationConfig(ObjectWriterProvider writerProvider) {
|
||||
this.writerProvider = writerProvider;
|
||||
}
|
||||
|
||||
public final boolean isEnabled(SerializationFeature f) {
|
||||
return (serFeatures & f.getMask()) != 0;
|
||||
}
|
||||
|
||||
public SerializationConfig with(MapperFeature f) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public SerializationConfig without(MapperFeature f) {
|
||||
// TODO
|
||||
return this;
|
||||
}
|
||||
|
||||
public SerializationConfig with(SerializationFeature f) {
|
||||
serFeatures |= f.getMask();
|
||||
return this;
|
||||
}
|
||||
|
||||
public SerializationConfig without(SerializationFeature f) {
|
||||
serFeatures &= ~f.getMask();
|
||||
return this;
|
||||
}
|
||||
|
||||
protected JSONWriter.Context createWriterContext() {
|
||||
JSONWriter.Context context = JSONFactory.createWriteContext(writerProvider, WriteByteArrayAsBase64);
|
||||
|
||||
if ((serFeatures & SerializationFeature.INDENT_OUTPUT.getMask()) != 0) {
|
||||
context.config(JSONWriter.Feature.PrettyFormat);
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.cfg.ConfigFeature;
|
||||
|
||||
public enum SerializationFeature
|
||||
implements ConfigFeature {
|
||||
WRAP_ROOT_VALUE(false),
|
||||
INDENT_OUTPUT(false),
|
||||
FAIL_ON_EMPTY_BEANS(true),
|
||||
FAIL_ON_SELF_REFERENCES(true),
|
||||
WRAP_EXCEPTIONS(true),
|
||||
FAIL_ON_UNWRAPPED_TYPE_IDENTIFIERS(true),
|
||||
WRITE_SELF_REFERENCES_AS_NULL(false),
|
||||
CLOSE_CLOSEABLE(false),
|
||||
FLUSH_AFTER_WRITE_VALUE(true),
|
||||
WRITE_DATES_AS_TIMESTAMPS(true),
|
||||
WRITE_DATE_KEYS_AS_TIMESTAMPS(false),
|
||||
WRITE_DATES_WITH_ZONE_ID(false),
|
||||
WRITE_DATES_WITH_CONTEXT_TIME_ZONE(true),
|
||||
WRITE_DURATIONS_AS_TIMESTAMPS(true),
|
||||
WRITE_CHAR_ARRAYS_AS_JSON_ARRAYS(false),
|
||||
WRITE_ENUMS_USING_TO_STRING(false),
|
||||
WRITE_ENUMS_USING_INDEX(false),
|
||||
WRITE_ENUM_KEYS_USING_INDEX(false),
|
||||
@Deprecated
|
||||
WRITE_NULL_MAP_VALUES(true),
|
||||
@Deprecated
|
||||
WRITE_EMPTY_JSON_ARRAYS(true),
|
||||
WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED(false),
|
||||
@Deprecated
|
||||
WRITE_BIGDECIMAL_AS_PLAIN(false),
|
||||
WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS(true),
|
||||
ORDER_MAP_ENTRIES_BY_KEYS(false),
|
||||
EAGER_SERIALIZER_FETCH(true),
|
||||
USE_EQUALITY_FOR_OBJECT_ID(false);
|
||||
|
||||
private final boolean defaultState;
|
||||
private final int mask;
|
||||
|
||||
SerializationFeature(boolean defaultState) {
|
||||
this.defaultState = defaultState;
|
||||
mask = (1 << ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enabledByDefault() {
|
||||
return defaultState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMask() {
|
||||
return mask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean enabledIn(int flags) {
|
||||
return (flags & mask) != 0;
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonGenerator;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class SerializerProvider
|
||||
extends DatabindContext {
|
||||
public final void defaultSerializeField(String fieldName, Object value, JsonGenerator gen)
|
||||
throws IOException {
|
||||
// TODO defaultSerializeField
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public final void defaultSerializeNull(JsonGenerator gen) throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public final void defaultSerializeValue(Object value, JsonGenerator gen) throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public JavaType constructSpecializedType(JavaType baseType, Class<?> subclass)
|
||||
throws IllegalArgumentException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.annotation;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JsonDeserializer;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.KeyDeserializer;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.util.Converter;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonDeserialize {
|
||||
Class<? extends JsonDeserializer> using()
|
||||
default JsonDeserializer.None.class;
|
||||
|
||||
Class<? extends KeyDeserializer> keyUsing()
|
||||
default KeyDeserializer.None.class;
|
||||
|
||||
Class<? extends JsonDeserializer> contentUsing()
|
||||
default JsonDeserializer.None.class;
|
||||
|
||||
Class<? extends Converter> converter() default Converter.None.class;
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.annotation;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JsonSerializer;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.util.Converter;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonSerialize {
|
||||
Class<? extends JsonSerializer> using() default JsonSerializer.None.class;
|
||||
|
||||
Class<? extends JsonSerializer> keyUsing() default JsonSerializer.None.class;
|
||||
|
||||
Class<? extends JsonSerializer> contentUsing() default JsonSerializer.None.class;
|
||||
|
||||
Class<? extends Converter> converter() default Converter.None.class;
|
||||
|
||||
Class<? extends Converter> contentConverter() default Converter.None.class;
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.annotation;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.jsontype.TypeIdResolver;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface JsonTypeIdResolver {
|
||||
Class<? extends TypeIdResolver> value();
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.cfg;
|
||||
|
||||
public interface ConfigFeature {
|
||||
/**
|
||||
* Accessor for checking whether this feature is enabled by default.
|
||||
*/
|
||||
boolean enabledByDefault();
|
||||
|
||||
/**
|
||||
* Returns bit mask for this feature instance
|
||||
*/
|
||||
int getMask();
|
||||
|
||||
/**
|
||||
* Convenience method for checking whether feature is enabled in given bitmask
|
||||
*
|
||||
* @since 2.6
|
||||
*/
|
||||
boolean enabledIn(int flags);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.deser.std;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JacksonException;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonParser;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.DeserializationContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class FromStringDeserializer<T>
|
||||
extends StdScalarDeserializer<T> {
|
||||
protected FromStringDeserializer(Class vc) {
|
||||
super(vc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T deserialize(JsonParser p, DeserializationContext ctx) throws IOException, JacksonException {
|
||||
String str = p.getJSONReader().readString();
|
||||
return _deserialize(str, ctx);
|
||||
}
|
||||
|
||||
protected abstract T _deserialize(String value, DeserializationContext context);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.deser.std;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JavaType;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JsonDeserializer;
|
||||
|
||||
public abstract class StdDeserializer<T>
|
||||
extends JsonDeserializer<T> {
|
||||
protected final Class<?> valueClass;
|
||||
protected final JavaType valueType;
|
||||
|
||||
protected StdDeserializer(Class<?> vc) {
|
||||
valueClass = vc;
|
||||
valueType = null;
|
||||
}
|
||||
|
||||
protected StdDeserializer(JavaType valueType) {
|
||||
this.valueType = valueType;
|
||||
this.valueClass = valueType.getRawClass();
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.deser.std;
|
||||
|
||||
public abstract class StdScalarDeserializer<T>
|
||||
extends StdDeserializer<T> {
|
||||
protected StdScalarDeserializer(Class<?> vc) {
|
||||
super(vc);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.exc;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JavaType;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JsonMappingException;
|
||||
|
||||
public class InvalidDefinitionException
|
||||
extends JsonMappingException {
|
||||
protected final JavaType type;
|
||||
|
||||
public InvalidDefinitionException(JavaType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public JavaType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.exc;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonProcessingException;
|
||||
|
||||
public class StreamReadException
|
||||
extends JsonProcessingException {
|
||||
public StreamReadException() {
|
||||
}
|
||||
|
||||
public StreamReadException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public StreamReadException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.jsontype;
|
||||
|
||||
public class NamedType {
|
||||
private Class c;
|
||||
private String name;
|
||||
|
||||
public NamedType(Class c, String name) {
|
||||
this.c = c;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.jsontype;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonParser;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.DeserializationContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class TypeDeserializer {
|
||||
public abstract Object deserializeTypedFromAny(JsonParser p, DeserializationContext ctxt) throws IOException;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.jsontype;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.annotation.JsonTypeInfo;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.DatabindContext;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JavaType;
|
||||
|
||||
public interface TypeIdResolver {
|
||||
String idFromValue(Object value);
|
||||
|
||||
String idFromValueAndType(Object value, Class<?> suggestedType);
|
||||
|
||||
JavaType typeFromId(DatabindContext context, String id);
|
||||
|
||||
JsonTypeInfo.Id getMechanism();
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.jsontype;
|
||||
|
||||
public abstract class TypeSerializer {
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.jsontype.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.JsonParser;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.DeserializationContext;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.jsontype.TypeDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class AsArrayTypeDeserializer
|
||||
extends TypeDeserializer {
|
||||
@Override
|
||||
public Object deserializeTypedFromAny(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.jsontype.impl;
|
||||
|
||||
public class AsArrayTypeSerializer
|
||||
extends TypeSerializerBase {
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.jsontype.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.adapter.jackson.annotation.JsonTypeInfo;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JavaType;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.jsontype.TypeIdResolver;
|
||||
|
||||
public class AsPropertyTypeDeserializer
|
||||
extends AsArrayTypeDeserializer {
|
||||
public AsPropertyTypeDeserializer(
|
||||
JavaType bt,
|
||||
TypeIdResolver idRes,
|
||||
String typePropertyName,
|
||||
boolean typeIdVisible,
|
||||
JavaType defaultImpl
|
||||
) {
|
||||
this(bt, idRes, typePropertyName, typeIdVisible, defaultImpl, JsonTypeInfo.As.PROPERTY);
|
||||
}
|
||||
|
||||
public AsPropertyTypeDeserializer(
|
||||
JavaType bt,
|
||||
TypeIdResolver idRes,
|
||||
String typePropertyName,
|
||||
boolean typeIdVisible,
|
||||
JavaType defaultImpl,
|
||||
JsonTypeInfo.As inclusion
|
||||
) {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.jsontype.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.BeanProperty;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.jsontype.TypeIdResolver;
|
||||
|
||||
public class AsPropertyTypeSerializer
|
||||
extends AsArrayTypeSerializer {
|
||||
public AsPropertyTypeSerializer(TypeIdResolver idRes, BeanProperty property, String propName) {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.jsontype.impl;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JavaType;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.jsontype.TypeIdResolver;
|
||||
|
||||
public abstract class TypeIdResolverBase
|
||||
implements TypeIdResolver {
|
||||
public void init(JavaType bt) {
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.jsontype.impl;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.jsontype.TypeSerializer;
|
||||
|
||||
public class TypeSerializerBase
|
||||
extends TypeSerializer {
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.module;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JsonDeserializer;
|
||||
import com.alibaba.fastjson2.modules.ObjectReaderModule;
|
||||
import com.alibaba.fastjson2.reader.ObjectReader;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SimpleDeserializers
|
||||
implements ObjectReaderModule {
|
||||
protected HashMap<Type, JsonDeserializer<?>> classMappings;
|
||||
protected boolean hasEnumDeserializer;
|
||||
|
||||
public <T> void addDeserializer(Class<T> forClass, JsonDeserializer<? extends T> deser) {
|
||||
if (classMappings == null) {
|
||||
classMappings = new HashMap<>();
|
||||
}
|
||||
classMappings.put(forClass, deser);
|
||||
if (forClass == Enum.class) {
|
||||
hasEnumDeserializer = true;
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectReader getObjectReader(Type type) {
|
||||
JsonDeserializer<?> deserializer = classMappings.get(type);
|
||||
if (deserializer == null) {
|
||||
if (type instanceof ParameterizedType) {
|
||||
Type rawType = ((ParameterizedType) type).getRawType();
|
||||
deserializer = classMappings.get(rawType);
|
||||
}
|
||||
}
|
||||
return deserializer;
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.module;
|
||||
|
||||
import com.alibaba.fastjson2.JSONException;
|
||||
import com.alibaba.fastjson2.adapter.jackson.core.Version;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JsonDeserializer;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JsonSerializer;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.jsontype.NamedType;
|
||||
import com.alibaba.fastjson2.modules.ObjectReaderModule;
|
||||
import com.alibaba.fastjson2.modules.ObjectWriterModule;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class SimpleModule
|
||||
extends com.alibaba.fastjson2.adapter.jackson.databind.Module {
|
||||
private static final AtomicInteger MODULE_ID_SEQ = new AtomicInteger(1);
|
||||
|
||||
protected SimpleSerializers serializers;
|
||||
protected SimpleDeserializers deserializers;
|
||||
|
||||
protected final String name;
|
||||
protected final Version version;
|
||||
protected final boolean hasExplicitName;
|
||||
|
||||
public SimpleModule() {
|
||||
name = (getClass() == SimpleModule.class)
|
||||
? "SimpleModule-" + MODULE_ID_SEQ.getAndIncrement()
|
||||
: getClass().getName();
|
||||
version = Version.unknownVersion();
|
||||
// 07-Jun-2021, tatu: [databind#3110] Not passed explicitly so...
|
||||
hasExplicitName = false;
|
||||
}
|
||||
|
||||
public SimpleModule(String name) {
|
||||
this.name = name;
|
||||
version = Version.unknownVersion();
|
||||
// 07-Jun-2021, tatu: [databind#3110] Not passed explicitly so...
|
||||
hasExplicitName = false;
|
||||
}
|
||||
|
||||
public SimpleModule(String name, Version version) {
|
||||
this.name = name;
|
||||
this.version = version;
|
||||
hasExplicitName = true;
|
||||
}
|
||||
|
||||
public <T> SimpleModule addSerializer(Class<? extends T> type, JsonSerializer<T> ser) {
|
||||
if (serializers == null) {
|
||||
serializers = new SimpleSerializers();
|
||||
}
|
||||
serializers.addSerializer(type, ser);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleModule addSerializer(JsonSerializer<?> ser) {
|
||||
Class<?> handledType = ser.handledType();
|
||||
if (handledType == null) {
|
||||
throw new JSONException("not support null handledType");
|
||||
}
|
||||
|
||||
if (serializers == null) {
|
||||
serializers = new SimpleSerializers();
|
||||
}
|
||||
serializers.addSerializer(handledType, ser);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> SimpleModule addDeserializer(Class<T> type, JsonDeserializer<? extends T> deser) {
|
||||
if (deserializers == null) {
|
||||
deserializers = new SimpleDeserializers();
|
||||
}
|
||||
deserializers.addDeserializer(type, deser);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleModule setMixInAnnotation(Class<?> targetType, Class<?> mixinClass) {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
|
||||
public ObjectWriterModule getWriterModule() {
|
||||
return serializers;
|
||||
}
|
||||
|
||||
public ObjectReaderModule getReaderModule() {
|
||||
return deserializers;
|
||||
}
|
||||
|
||||
public SimpleModule registerSubtypes(NamedType... subtypes) {
|
||||
throw new JSONException("TODO");
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.module;
|
||||
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JsonSerializer;
|
||||
import com.alibaba.fastjson2.modules.ObjectWriterModule;
|
||||
import com.alibaba.fastjson2.writer.ObjectWriter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SimpleSerializers
|
||||
implements ObjectWriterModule {
|
||||
protected HashMap<Type, JsonSerializer<?>> classMappings;
|
||||
protected HashMap<Type, JsonSerializer<?>> interfaceMappings;
|
||||
|
||||
protected boolean hasEnumSerializer;
|
||||
|
||||
public void addSerializer(Class<?> cls, JsonSerializer<?> ser) {
|
||||
// Interface or class type?
|
||||
if (cls.isInterface()) {
|
||||
if (interfaceMappings == null) {
|
||||
interfaceMappings = new HashMap<>();
|
||||
}
|
||||
interfaceMappings.put(cls, ser);
|
||||
} else { // nope, class:
|
||||
if (classMappings == null) {
|
||||
classMappings = new HashMap<>();
|
||||
}
|
||||
classMappings.put(cls, ser);
|
||||
if (cls == Enum.class) {
|
||||
hasEnumSerializer = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectWriter getObjectWriter(Type objectType, Class objectClass) {
|
||||
return classMappings.get(objectType);
|
||||
}
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
package com.alibaba.fastjson2.adapter.jackson.databind.node;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.adapter.jackson.databind.JsonNode;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.alibaba.fastjson2.annotation.JSONType;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
@JSONType(includes = "jsonArray")
|
||||
public class ArrayNode
|
||||
extends ContainerNode<ArrayNode> {
|
||||
final JSONArray jsonArray;
|
||||
|
||||
public ArrayNode(JsonNodeFactory nf) {
|
||||
this.jsonArray = new JSONArray();
|
||||
}
|
||||
|
||||
public ArrayNode(JsonNodeFactory nf, Collection values) {
|
||||
this.jsonArray = new JSONArray(values);
|
||||
}
|
||||
|
||||
public ArrayNode() {
|
||||
this.jsonArray = new JSONArray();
|
||||
}
|
||||
|
||||
public ArrayNode(@JSONField(name = "jsonArray") JSONArray jsonArray) {
|
||||
this.jsonArray = jsonArray;
|
||||
}
|
||||
|
||||
@JSONField(name = "jsonArray", value = true)
|
||||
public JSONArray getJSONArray() {
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asText() {
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return jsonArray.size();
|
||||
}
|
||||
|
||||
public ArrayNode add(Float v) {
|
||||
jsonArray.add(v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayNode add(Double v) {
|
||||
jsonArray.add(v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayNode add(BigDecimal v) {
|
||||
jsonArray.add(v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayNode add(BigInteger v) {
|
||||
jsonArray.add(v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayNode add(Long v) {
|
||||
jsonArray.add(v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayNode add(Integer v) {
|
||||
jsonArray.add(v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayNode add(Short v) {
|
||||
jsonArray.add(v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayNode add(Byte v) {
|
||||
jsonArray.add(v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayNode add(String v) {
|
||||
jsonArray.add(v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayNode add(boolean v) {
|
||||
jsonArray.add(v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayNode add(Boolean v) {
|
||||
jsonArray.add(v);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArrayNode add(JsonNode value) {
|
||||
jsonArray.add(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return jsonArray.toString();
|
||||
}
|
||||
|
||||
public boolean isArray() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<JsonNode> iterator() {
|
||||
return new JsonNodeIterator(jsonArray.iterator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<JsonNode> elements() {
|
||||
return new JsonNodeIterator(this.iterator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNode get(int index) {
|
||||
if ((index >= 0) && (index < jsonArray.size())) {
|
||||
Object item = jsonArray.get(index);
|
||||
return TreeNodeUtils.as(item);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonNodeType getNodeType() {
|
||||
return JsonNodeType.ARRAY;
|
||||
}
|
||||
|
||||
public ArrayNode removeAll() {
|
||||
jsonArray.clear();
|
||||
return this;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user