├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── sample
│ │ ├── App.java
│ │ └── MainActivity.java
│ ├── res
│ ├── layout
│ │ └── activity_main.xml
│ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ ├── values-w820dp
│ │ └── dimens.xml
│ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── resources
│ ├── classes2.dex
│ └── classes3.dex
├── build.gradle
├── dexlibrary
├── .gitignore
├── build.gradle
├── classes.jar
├── classes3.dex
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ ├── alibaba
│ └── fastjson
│ │ ├── JSON.java
│ │ ├── JSONArray.java
│ │ ├── JSONAware.java
│ │ ├── JSONException.java
│ │ ├── JSONObject.java
│ │ ├── JSONReader.java
│ │ ├── JSONStreamAware.java
│ │ ├── JSONStreamContext.java
│ │ ├── JSONWriter.java
│ │ ├── TypeReference.java
│ │ ├── annotation
│ │ ├── JSONCreator.java
│ │ ├── JSONField.java
│ │ └── JSONType.java
│ │ ├── parser
│ │ ├── AbstractJSONParser.java
│ │ ├── DefaultJSONParser.java
│ │ ├── Feature.java
│ │ ├── JSONLexer.java
│ │ ├── JSONLexerBase.java
│ │ ├── JSONReaderScanner.java
│ │ ├── JSONScanner.java
│ │ ├── JSONToken.java
│ │ ├── ParseContext.java
│ │ ├── ParserConfig.java
│ │ ├── SymbolTable.java
│ │ └── deserializer
│ │ │ ├── AbstractDateDeserializer.java
│ │ │ ├── ArrayDeserializer.java
│ │ │ ├── ArrayListTypeFieldDeserializer.java
│ │ │ ├── BooleanFieldDeserializer.java
│ │ │ ├── CharArrayDeserializer.java
│ │ │ ├── ClassDerializer.java
│ │ │ ├── CollectionDeserializer.java
│ │ │ ├── CollectionResolveFieldDeserializer.java
│ │ │ ├── DateDeserializer.java
│ │ │ ├── DateFormatDeserializer.java
│ │ │ ├── DefaultFieldDeserializer.java
│ │ │ ├── EnumDeserializer.java
│ │ │ ├── ExtraProcessor.java
│ │ │ ├── ExtraTypeProvider.java
│ │ │ ├── FieldDeserializer.java
│ │ │ ├── IntegerFieldDeserializer.java
│ │ │ ├── JSONArrayDeserializer.java
│ │ │ ├── JSONObjectDeserializer.java
│ │ │ ├── JavaBeanDeserializer.java
│ │ │ ├── JavaObjectDeserializer.java
│ │ │ ├── ListResolveFieldDeserializer.java
│ │ │ ├── LongFieldDeserializer.java
│ │ │ ├── MapDeserializer.java
│ │ │ ├── MapResolveFieldDeserializer.java
│ │ │ ├── NumberDeserializer.java
│ │ │ ├── ObjectDeserializer.java
│ │ │ ├── ParseProcess.java
│ │ │ ├── SqlDateDeserializer.java
│ │ │ ├── StackTraceElementDeserializer.java
│ │ │ ├── StringFieldDeserializer.java
│ │ │ ├── ThrowableDeserializer.java
│ │ │ ├── TimeDeserializer.java
│ │ │ └── TimestampDeserializer.java
│ │ ├── serializer
│ │ ├── AfterFilter.java
│ │ ├── ArraySerializer.java
│ │ ├── BeforeFilter.java
│ │ ├── BigDecimalCodec.java
│ │ ├── BigIntegerCodec.java
│ │ ├── BooleanArraySerializer.java
│ │ ├── BooleanCodec.java
│ │ ├── ByteArraySerializer.java
│ │ ├── CalendarCodec.java
│ │ ├── CharArraySerializer.java
│ │ ├── CharacterCodec.java
│ │ ├── CharsetCodec.java
│ │ ├── ClassSerializer.java
│ │ ├── CollectionSerializer.java
│ │ ├── CurrencyCodec.java
│ │ ├── DateFormatSerializer.java
│ │ ├── DateSerializer.java
│ │ ├── DoubleArraySerializer.java
│ │ ├── DoubleSerializer.java
│ │ ├── EnumSerializer.java
│ │ ├── EnumerationSeriliazer.java
│ │ ├── ExceptionSerializer.java
│ │ ├── FieldSerializer.java
│ │ ├── FilterUtils.java
│ │ ├── FloatArraySerializer.java
│ │ ├── FloatCodec.java
│ │ ├── InetAddressCodec.java
│ │ ├── InetSocketAddressCodec.java
│ │ ├── IntArraySerializer.java
│ │ ├── IntegerCodec.java
│ │ ├── JSONAwareSerializer.java
│ │ ├── JSONLibDataFormatSerializer.java
│ │ ├── JSONSerializable.java
│ │ ├── JSONSerializableSerializer.java
│ │ ├── JSONSerializer.java
│ │ ├── JSONSerializerContext.java
│ │ ├── JSONStreamAwareSerializer.java
│ │ ├── JavaBeanSerializer.java
│ │ ├── ListSerializer.java
│ │ ├── LocaleCodec.java
│ │ ├── LongArraySerializer.java
│ │ ├── LongCodec.java
│ │ ├── MapSerializer.java
│ │ ├── NameFilter.java
│ │ ├── NumberFieldSerializer.java
│ │ ├── ObjectArraySerializer.java
│ │ ├── ObjectFieldSerializer.java
│ │ ├── ObjectSerializer.java
│ │ ├── PascalNameFilter.java
│ │ ├── PatternCodec.java
│ │ ├── PropertyFilter.java
│ │ ├── PropertyPreFilter.java
│ │ ├── SerialContext.java
│ │ ├── SerializeConfig.java
│ │ ├── SerializeFilter.java
│ │ ├── SerializeWriter.java
│ │ ├── SerializerFeature.java
│ │ ├── ShortArraySerializer.java
│ │ ├── SimpleDateFormatSerializer.java
│ │ ├── SimplePropertyPreFilter.java
│ │ ├── StringCodec.java
│ │ ├── TimeZoneCodec.java
│ │ ├── URICodec.java
│ │ ├── URLCodec.java
│ │ ├── UUIDCodec.java
│ │ └── ValueFilter.java
│ │ └── util
│ │ ├── Base64.java
│ │ ├── DeserializeBeanInfo.java
│ │ ├── FieldInfo.java
│ │ ├── IOUtils.java
│ │ ├── IdentityHashMap.java
│ │ ├── ParameterizedTypeImpl.java
│ │ └── TypeUtils.java
│ └── sample
│ └── Core.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── cpp
│ ├── CMakeLists.txt
│ ├── include
│ │ └── log.h
│ └── multidex.c
│ └── java
│ └── com
│ └── android
│ └── quickmultidex
│ ├── IncrementalClassLoader.java
│ └── Multidex.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # QuickMultidex
2 | 一种在Dalvik虚拟机上多Dex首次加载的优化方案,支持4.1~4.4
3 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | buildToolsVersion "28.0.3"
6 | defaultConfig {
7 | applicationId "com.vdian.android.sample"
8 | minSdkVersion 14
9 | targetSdkVersion 23
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | ndk {
14 | abiFilters 'armeabi', 'x86'
15 | }
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 |
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | compile fileTree(include: ['*.jar'], dir: 'libs')
29 | compile 'com.android.support:appcompat-v7:23.0.1'
30 | compile project(':library')
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/lizhangqu/AndroidSDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sample/App.java:
--------------------------------------------------------------------------------
1 | package com.sample;
2 |
3 | import android.app.Application;
4 | import android.content.Context;
5 |
6 | import com.android.quickmultidex.Multidex;
7 |
8 |
9 | /**
10 | * @version V1.0
11 | * @author: lizhangqu
12 | * @date: 2016-11-25 20:59
13 | */
14 | public class App extends Application {
15 |
16 | @Override
17 | protected final void attachBaseContext(Context context) {
18 | super.attachBaseContext(context);
19 | boolean install = Multidex.install(context);
20 | }
21 |
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.sample;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 |
10 |
11 | import java.lang.reflect.Method;
12 |
13 | public class MainActivity extends AppCompatActivity {
14 |
15 |
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_main);
20 |
21 |
22 | try {
23 | Class> hello = Class.forName("Hello");
24 | Method main = hello.getDeclaredMethod("main", String[].class);
25 | main.setAccessible(true);
26 | Log.e("TAG", "method:" + main);
27 | Object args = new String[]{"a", "b", "c"};
28 | main.invoke(null, args);
29 | } catch (Throwable e) {
30 | e.printStackTrace();
31 | }
32 |
33 | Button btn = (Button) findViewById(R.id.btn);
34 | btn.setOnClickListener(new View.OnClickListener() {
35 | @Override
36 | public void onClick(View v) {
37 | //以下代码在4.4上如果不调用 dexOrJar->pRawDexFile->pDvmDex->dex_object = dex_object; 会奔溃
38 | try {
39 | Class> hello = Class.forName("com.sample.Core");
40 | Method parse = hello.getDeclaredMethod("parse");
41 | parse.setAccessible(true);
42 | Log.e("TAG", "method:" + parse);
43 | parse.invoke(null);
44 | } catch (Throwable e) {
45 | e.printStackTrace();
46 | }
47 | }
48 | });
49 | }
50 |
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lizhangqu/QuickMultidex/a177e30945044d117c1834ef10bcd1ad9f1105dd/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lizhangqu/QuickMultidex/a177e30945044d117c1834ef10bcd1ad9f1105dd/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lizhangqu/QuickMultidex/a177e30945044d117c1834ef10bcd1ad9f1105dd/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lizhangqu/QuickMultidex/a177e30945044d117c1834ef10bcd1ad9f1105dd/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lizhangqu/QuickMultidex/a177e30945044d117c1834ef10bcd1ad9f1105dd/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Multidex
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/resources/classes2.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lizhangqu/QuickMultidex/a177e30945044d117c1834ef10bcd1ad9f1105dd/app/src/main/resources/classes2.dex
--------------------------------------------------------------------------------
/app/src/main/resources/classes3.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lizhangqu/QuickMultidex/a177e30945044d117c1834ef10bcd1ad9f1105dd/app/src/main/resources/classes3.dex
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.2'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/dexlibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/dexlibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 | buildToolsVersion "28.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 23
10 | }
11 | buildTypes {
12 | release {
13 | minifyEnabled false
14 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
15 | }
16 | }
17 | }
18 |
19 | dependencies {
20 | compile fileTree(dir: 'libs', include: ['*.jar'])
21 | }
22 |
--------------------------------------------------------------------------------
/dexlibrary/classes.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lizhangqu/QuickMultidex/a177e30945044d117c1834ef10bcd1ad9f1105dd/dexlibrary/classes.jar
--------------------------------------------------------------------------------
/dexlibrary/classes3.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lizhangqu/QuickMultidex/a177e30945044d117c1834ef10bcd1ad9f1105dd/dexlibrary/classes3.dex
--------------------------------------------------------------------------------
/dexlibrary/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/lizhangqu/AndroidSDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/JSONAware.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 1999-2101 Alibaba Group.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.alibaba.fastjson;
17 |
18 | /**
19 | * Beans that support customized output of JSON text shall implement this interface.
20 | *
21 | * @author wenshao[szujobs@hotmail.com]
22 | */
23 | public interface JSONAware {
24 |
25 | /**
26 | * @return JSON text
27 | */
28 | String toJSONString();
29 | }
30 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/JSONException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 1999-2101 Alibaba Group.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.alibaba.fastjson;
17 |
18 | /**
19 | * @author wenshao[szujobs@hotmail.com]
20 | */
21 | public class JSONException extends RuntimeException {
22 |
23 | private static final long serialVersionUID = 1L;
24 |
25 | public JSONException(){
26 | super();
27 | }
28 |
29 | public JSONException(String message){
30 | super(message);
31 | }
32 |
33 | public JSONException(String message, Throwable cause){
34 | super(message, cause);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/JSONStreamAware.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 1999-2101 Alibaba Group.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.alibaba.fastjson;
17 |
18 | import java.io.IOException;
19 |
20 | /**
21 | * Beans that support customized output of JSON text to a writer shall implement this interface.
22 | *
23 | * @author wenshao[szujobs@hotmail.com]
24 | */
25 | public interface JSONStreamAware {
26 |
27 | /**
28 | * write JSON string to out.
29 | */
30 | void writeJSONString(Appendable out) throws IOException;
31 | }
32 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/JSONStreamContext.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson;
2 |
3 | class JSONStreamContext {
4 |
5 | final static int StartObject = 1001;
6 | final static int PropertyKey = 1002;
7 | final static int PropertyValue = 1003;
8 | final static int StartArray = 1004;
9 | final static int ArrayValue = 1005;
10 |
11 | private final JSONStreamContext parent;
12 |
13 | private int state;
14 |
15 | public JSONStreamContext(JSONStreamContext parent, int state){
16 | this.parent = parent;
17 | this.state = state;
18 | }
19 |
20 | public JSONStreamContext getParent() {
21 | return parent;
22 | }
23 |
24 | public int getState() {
25 | return state;
26 | }
27 |
28 | public void setState(int state) {
29 | this.state = state;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/TypeReference.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson;
2 |
3 | import java.lang.reflect.ParameterizedType;
4 | import java.lang.reflect.Type;
5 | import java.util.List;
6 |
7 | public class TypeReference {
8 |
9 | private final Type type;
10 |
11 | protected TypeReference(){
12 | Type superClass = getClass().getGenericSuperclass();
13 |
14 | type = ((ParameterizedType) superClass).getActualTypeArguments()[0];
15 | }
16 |
17 | public Type getType() {
18 | return type;
19 | }
20 |
21 | public final static Type LIST_STRING = new TypeReference>() {}.getType();
22 | }
23 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/annotation/JSONCreator.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target({ ElementType.CONSTRUCTOR, ElementType.METHOD })
10 | public @interface JSONCreator {
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/annotation/JSONField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 1999-2101 Alibaba Group.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.alibaba.fastjson.annotation;
17 |
18 | import java.lang.annotation.ElementType;
19 | import java.lang.annotation.Retention;
20 | import java.lang.annotation.RetentionPolicy;
21 | import java.lang.annotation.Target;
22 |
23 | import com.alibaba.fastjson.parser.Feature;
24 | import com.alibaba.fastjson.serializer.SerializerFeature;
25 |
26 | /**
27 | * @author wenshao[szujobs@hotmail.com]
28 | */
29 | @Retention(RetentionPolicy.RUNTIME)
30 | @Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER })
31 | public @interface JSONField {
32 | /**
33 | * config encode/decode ordinal
34 | * @since 1.1.42
35 | * @return
36 | */
37 | int ordinal() default 0;
38 |
39 | String name() default "";
40 |
41 | String format() default "";
42 |
43 | boolean serialize() default true;
44 |
45 | boolean deserialize() default true;
46 |
47 | SerializerFeature[] serialzeFeatures() default {};
48 |
49 | Feature[] parseFeatures() default {};
50 | }
51 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/annotation/JSONType.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.annotation;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | import com.alibaba.fastjson.parser.Feature;
9 | import com.alibaba.fastjson.serializer.SerializerFeature;
10 |
11 | /**
12 | * @author wenshao[szujobs@hotmail.com]
13 | */
14 | @Retention(RetentionPolicy.RUNTIME)
15 | @Target({ ElementType.TYPE })
16 | public @interface JSONType {
17 |
18 | boolean asm() default true;
19 |
20 | String[] orders() default {};
21 |
22 | String[] ignores() default {};
23 |
24 | SerializerFeature[] serialzeFeatures() default {};
25 | Feature[] parseFeatures() default {};
26 |
27 | boolean alphabetic() default true;
28 |
29 | Class> mappingTo() default Void.class;
30 | }
31 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/AbstractJSONParser.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser;
2 |
3 | public abstract class AbstractJSONParser {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/Feature.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 1999-2101 Alibaba Group.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.alibaba.fastjson.parser;
17 |
18 |
19 | /**
20 | * @author wenshao[szujobs@hotmail.com]
21 | */
22 | public enum Feature {
23 | /**
24 | *
25 | */
26 | AutoCloseSource,
27 | /**
28 | *
29 | */
30 | AllowComment,
31 | /**
32 | *
33 | */
34 | AllowUnQuotedFieldNames,
35 | /**
36 | *
37 | */
38 | AllowSingleQuotes,
39 | /**
40 | *
41 | */
42 | InternFieldNames,
43 | /**
44 | *
45 | */
46 | AllowISO8601DateFormat,
47 |
48 | /**
49 | * {"a":1,,,"b":2}
50 | */
51 | AllowArbitraryCommas,
52 |
53 | /**
54 | *
55 | */
56 | UseBigDecimal,
57 |
58 | /**
59 | * @since 1.1.2
60 | */
61 | IgnoreNotMatch,
62 |
63 | /**
64 | * @since 1.1.3
65 | */
66 | SortFeidFastMatch,
67 |
68 | /**
69 | * @since 1.1.3
70 | */
71 | DisableASM,
72 |
73 | /**
74 | * @since 1.1.7
75 | */
76 | DisableCircularReferenceDetect,
77 |
78 | /**
79 | * @since 1.1.10
80 | */
81 | InitStringFieldAsEmpty,
82 |
83 | /**
84 | * @since 1.1.35
85 | *
86 | */
87 | SupportArrayToBean
88 | ;
89 |
90 | private Feature(){
91 | mask = (1 << ordinal());
92 | }
93 |
94 | private final int mask;
95 |
96 | public final int getMask() {
97 | return mask;
98 | }
99 |
100 | public static boolean isEnabled(int features, Feature feature) {
101 | return (features & feature.getMask()) != 0;
102 | }
103 |
104 | public static int config(int features, Feature feature, boolean state) {
105 | if (state) {
106 | features |= feature.getMask();
107 | } else {
108 | features &= ~feature.getMask();
109 | }
110 |
111 | return features;
112 | }
113 |
114 | public static int of(Feature[] features) {
115 | if (features == null) {
116 | return 0;
117 | }
118 |
119 | int value = 0;
120 |
121 | for (Feature feature: features) {
122 | value |= feature.getMask();
123 | }
124 |
125 | return value;
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/JSONLexer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public interface JSONLexer {
6 |
7 | public final static byte EOI = 0x1A;
8 | public final static int NOT_MATCH = -1;
9 | public final static int NOT_MATCH_NAME = -2;
10 | public final static int UNKOWN = 0;
11 | public final static int OBJECT = 1;
12 | public final static int ARRAY = 2;
13 | public final static int VALUE = 3;
14 | public final static int END = 4;
15 |
16 | int token();
17 |
18 | String tokenName();
19 |
20 | void skipWhitespace();
21 |
22 | void nextToken();
23 |
24 | void nextToken(int expect);
25 |
26 | char getCurrent();
27 |
28 | char next();
29 |
30 | String scanSymbol(final SymbolTable symbolTable);
31 |
32 | String scanSymbol(final SymbolTable symbolTable, final char quote);
33 |
34 | void resetStringPosition();
35 |
36 | void scanNumber();
37 |
38 | int pos();
39 |
40 | Number integerValue();
41 |
42 | BigDecimal decimalValue();
43 |
44 | Number decimalValue(boolean decimal);
45 |
46 | String scanSymbolUnQuoted(final SymbolTable symbolTable);
47 |
48 | String stringVal();
49 |
50 | boolean isEnabled(Feature feature);
51 |
52 | void config(Feature feature, boolean state);
53 |
54 | void scanString();
55 |
56 | int intValue();
57 |
58 | void nextTokenWithColon();
59 |
60 | void nextTokenWithColon(int expect);
61 |
62 | boolean isBlankInput();
63 |
64 | int getBufferPosition();
65 |
66 | void close();
67 |
68 | long longValue();
69 |
70 | boolean isRef();
71 |
72 | String numberString();
73 |
74 | byte[] bytesValue();
75 |
76 | float floatValue();
77 |
78 | long scanLong(char expectNextChar);
79 |
80 | int scanInt(char expectNext);
81 |
82 | String scanString(char expectNextChar);
83 |
84 | Enum> scanEnum(Class> enumClass, final SymbolTable symbolTable, char serperator);
85 |
86 | String scanSymbolWithSeperator(final SymbolTable symbolTable, char serperator);
87 |
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/JSONToken.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 1999-2101 Alibaba Group.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.alibaba.fastjson.parser;
17 |
18 | /**
19 | * @author wenshao[szujobs@hotmail.com]
20 | */
21 | public class JSONToken {
22 |
23 | //
24 | public final static int ERROR = 1;
25 | //
26 | public final static int LITERAL_INT = 2;
27 | //
28 | public final static int LITERAL_FLOAT = 3;
29 | //
30 | public final static int LITERAL_STRING = 4;
31 | //
32 | public final static int LITERAL_ISO8601_DATE = 5;
33 |
34 | public final static int TRUE = 6;
35 | //
36 | public final static int FALSE = 7;
37 | //
38 | public final static int NULL = 8;
39 | //
40 | public final static int NEW = 9;
41 | //
42 | public final static int LPAREN = 10; // ("("),
43 | //
44 | public final static int RPAREN = 11; // (")"),
45 | //
46 | public final static int LBRACE = 12; // ("{"),
47 | //
48 | public final static int RBRACE = 13; // ("}"),
49 | //
50 | public final static int LBRACKET = 14; // ("["),
51 | //
52 | public final static int RBRACKET = 15; // ("]"),
53 | //
54 | public final static int COMMA = 16; // (","),
55 | //
56 | public final static int COLON = 17; // (":"),
57 | //
58 | public final static int IDENTIFIER = 18;
59 | //
60 | public final static int FIELD_NAME = 19;
61 |
62 | public final static int EOF = 20;
63 |
64 | public final static int SET = 21;
65 | public final static int TREE_SET = 22;
66 |
67 | public final static int UNDEFINED = 23; // undefined
68 |
69 | public static String name(int value) {
70 | switch (value) {
71 | case ERROR:
72 | return "error";
73 | case LITERAL_INT:
74 | return "int";
75 | case LITERAL_FLOAT:
76 | return "float";
77 | case LITERAL_STRING:
78 | return "string";
79 | case LITERAL_ISO8601_DATE:
80 | return "iso8601";
81 | case TRUE:
82 | return "true";
83 | case FALSE:
84 | return "false";
85 | case NULL:
86 | return "null";
87 | case NEW:
88 | return "new";
89 | case LPAREN:
90 | return "(";
91 | case RPAREN:
92 | return ")";
93 | case LBRACE:
94 | return "{";
95 | case RBRACE:
96 | return "}";
97 | case LBRACKET:
98 | return "[";
99 | case RBRACKET:
100 | return "]";
101 | case COMMA:
102 | return ",";
103 | case COLON:
104 | return ":";
105 | case IDENTIFIER:
106 | return "ident";
107 | case FIELD_NAME:
108 | return "fieldName";
109 | case EOF:
110 | return "EOF";
111 | case SET:
112 | return "Set";
113 | case TREE_SET:
114 | return "TreeSet";
115 | case UNDEFINED:
116 | return "undefined";
117 | default:
118 | return "Unkown";
119 | }
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/ParseContext.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser;
2 |
3 | import java.lang.reflect.Type;
4 |
5 | public class ParseContext {
6 |
7 | private Object object;
8 | private final ParseContext parent;
9 | private final Object fieldName;
10 | private Type type;
11 |
12 | public ParseContext(ParseContext parent, Object object, Object fieldName){
13 | super();
14 | this.parent = parent;
15 | this.object = object;
16 | this.fieldName = fieldName;
17 | }
18 |
19 | public Type getType() {
20 | return type;
21 | }
22 |
23 | public void setType(Type type) {
24 | this.type = type;
25 | }
26 |
27 | public Object getObject() {
28 | return object;
29 | }
30 |
31 | public void setObject(Object object) {
32 | this.object = object;
33 | }
34 |
35 | public ParseContext getParentContext() {
36 | return parent;
37 | }
38 |
39 | public String getPath() {
40 | if (parent == null) {
41 | return "$";
42 | } else {
43 | if (fieldName instanceof Integer) {
44 | return parent.getPath() + "[" + fieldName + "]";
45 | } else {
46 | return parent.getPath() + "." + fieldName;
47 | }
48 |
49 | }
50 | }
51 |
52 | public String toString() {
53 | return this.getPath();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/AbstractDateDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Type;
4 |
5 | import com.alibaba.fastjson.JSON;
6 | import com.alibaba.fastjson.JSONException;
7 | import com.alibaba.fastjson.parser.DefaultJSONParser;
8 | import com.alibaba.fastjson.parser.Feature;
9 | import com.alibaba.fastjson.parser.JSONLexer;
10 | import com.alibaba.fastjson.parser.JSONScanner;
11 | import com.alibaba.fastjson.parser.JSONToken;
12 | import com.alibaba.fastjson.util.TypeUtils;
13 |
14 | public abstract class AbstractDateDeserializer implements ObjectDeserializer {
15 |
16 | @SuppressWarnings("unchecked")
17 | public T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
18 | JSONLexer lexer = parser.getLexer();
19 |
20 | Object val;
21 | if (lexer.token() == JSONToken.LITERAL_INT) {
22 | val = lexer.longValue();
23 | lexer.nextToken(JSONToken.COMMA);
24 | } else if (lexer.token() == JSONToken.LITERAL_STRING) {
25 | String strVal = lexer.stringVal();
26 | val = strVal;
27 | lexer.nextToken(JSONToken.COMMA);
28 |
29 | if (lexer.isEnabled(Feature.AllowISO8601DateFormat)) {
30 | JSONScanner iso8601Lexer = new JSONScanner(strVal);
31 | if (iso8601Lexer.scanISO8601DateIfMatch()) {
32 | val = iso8601Lexer.getCalendar().getTime();
33 | }
34 | iso8601Lexer.close();
35 | }
36 | } else if (lexer.token() == JSONToken.NULL) {
37 | lexer.nextToken();
38 | val = null;
39 | } else if (lexer.token() == JSONToken.LBRACE) {
40 | lexer.nextToken();
41 |
42 | String key;
43 | if (lexer.token() == JSONToken.LITERAL_STRING) {
44 | key = lexer.stringVal();
45 |
46 | if (JSON.DEFAULT_TYPE_KEY.equals(key)) {
47 | lexer.nextToken();
48 | parser.accept(JSONToken.COLON);
49 |
50 | String typeName = lexer.stringVal();
51 | Class> type = TypeUtils.loadClass(typeName);
52 | if (type != null) {
53 | clazz = type;
54 | }
55 |
56 | parser.accept(JSONToken.LITERAL_STRING);
57 | parser.accept(JSONToken.COMMA);
58 | }
59 |
60 | lexer.nextTokenWithColon(JSONToken.LITERAL_INT);
61 | } else {
62 | throw new JSONException("syntax error");
63 | }
64 |
65 | long timeMillis;
66 | if (lexer.token() == JSONToken.LITERAL_INT) {
67 | timeMillis = lexer.longValue();
68 | lexer.nextToken();
69 | } else {
70 | throw new JSONException("syntax error : " + lexer.tokenName());
71 | }
72 |
73 | val = timeMillis;
74 |
75 | parser.accept(JSONToken.RBRACE);
76 | } else if (parser.getResolveStatus() == DefaultJSONParser.TypeNameRedirect) {
77 | parser.setResolveStatus(DefaultJSONParser.NONE);
78 | parser.accept(JSONToken.COMMA);
79 |
80 | if (lexer.token() == JSONToken.LITERAL_STRING) {
81 | if (!"val".equals(lexer.stringVal())) {
82 | throw new JSONException("syntax error");
83 | }
84 | lexer.nextToken();
85 | } else {
86 | throw new JSONException("syntax error");
87 | }
88 |
89 | parser.accept(JSONToken.COLON);
90 |
91 | val = parser.parse();
92 |
93 | parser.accept(JSONToken.RBRACE);
94 | } else {
95 | val = parser.parse();
96 | }
97 |
98 | return (T) cast(parser, clazz, fieldName, val);
99 | }
100 |
101 | protected abstract T cast(DefaultJSONParser parser, Type clazz, Object fieldName, Object value);
102 | }
103 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/BooleanFieldDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Type;
4 | import java.util.Map;
5 |
6 | import com.alibaba.fastjson.parser.DefaultJSONParser;
7 | import com.alibaba.fastjson.parser.JSONLexer;
8 | import com.alibaba.fastjson.parser.JSONToken;
9 | import com.alibaba.fastjson.parser.ParserConfig;
10 | import com.alibaba.fastjson.util.FieldInfo;
11 | import com.alibaba.fastjson.util.TypeUtils;
12 |
13 | public class BooleanFieldDeserializer extends FieldDeserializer {
14 |
15 | public BooleanFieldDeserializer(ParserConfig mapping, Class> clazz, FieldInfo fieldInfo){
16 | super(clazz, fieldInfo);
17 | }
18 |
19 | @Override
20 | public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map fieldValues) {
21 | Boolean value;
22 |
23 | final JSONLexer lexer = parser.getLexer();
24 | if (lexer.token() == JSONToken.TRUE) {
25 | lexer.nextToken(JSONToken.COMMA);
26 | if (object == null) {
27 | fieldValues.put(fieldInfo.getName(), Boolean.TRUE);
28 | } else {
29 | setValue(object, true);
30 | }
31 | return;
32 | }
33 |
34 | if (lexer.token() == JSONToken.LITERAL_INT) {
35 | int val = lexer.intValue();
36 | lexer.nextToken(JSONToken.COMMA);
37 | boolean booleanValue = val == 1;
38 | if (object == null) {
39 | fieldValues.put(fieldInfo.getName(), booleanValue);
40 | } else {
41 | setValue(object, booleanValue);
42 | }
43 | return;
44 | }
45 |
46 | if (lexer.token() == JSONToken.NULL) {
47 | value = null;
48 | lexer.nextToken(JSONToken.COMMA);
49 |
50 | if (getFieldClass() == boolean.class) {
51 | // skip
52 | return;
53 | }
54 |
55 | if (object != null) {
56 | setValue(object, null);
57 | }
58 | return;
59 | }
60 |
61 | if (lexer.token() == JSONToken.FALSE) {
62 | lexer.nextToken(JSONToken.COMMA);
63 | if (object == null) {
64 | fieldValues.put(fieldInfo.getName(), Boolean.FALSE);
65 | } else {
66 | setValue(object, false);
67 | }
68 | return;
69 | }
70 |
71 | Object obj = parser.parse();
72 |
73 | value = TypeUtils.castToBoolean(obj);
74 |
75 | if (value == null && getFieldClass() == boolean.class) {
76 | // skip
77 | return;
78 | }
79 |
80 | if (object == null) {
81 | fieldValues.put(fieldInfo.getName(), value);
82 | } else {
83 | setValue(object, value);
84 | }
85 | }
86 |
87 | public int getFastMatchToken() {
88 | return JSONToken.TRUE;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/CharArrayDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Type;
4 |
5 | import com.alibaba.fastjson.JSON;
6 | import com.alibaba.fastjson.parser.DefaultJSONParser;
7 | import com.alibaba.fastjson.parser.JSONLexer;
8 | import com.alibaba.fastjson.parser.JSONToken;
9 |
10 | public class CharArrayDeserializer implements ObjectDeserializer {
11 |
12 | public final static CharArrayDeserializer instance = new CharArrayDeserializer();
13 |
14 | @SuppressWarnings("unchecked")
15 | public T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
16 | return (T) deserialze(parser);
17 | }
18 |
19 | @SuppressWarnings("unchecked")
20 | public static T deserialze(DefaultJSONParser parser) {
21 | final JSONLexer lexer = parser.getLexer();
22 | if (lexer.token() == JSONToken.LITERAL_STRING) {
23 | String val = lexer.stringVal();
24 | lexer.nextToken(JSONToken.COMMA);
25 | return (T) val.toCharArray();
26 | }
27 |
28 | if (lexer.token() == JSONToken.LITERAL_INT) {
29 | Number val = lexer.integerValue();
30 | lexer.nextToken(JSONToken.COMMA);
31 | return (T) val.toString().toCharArray();
32 | }
33 |
34 | Object value = parser.parse();
35 |
36 | if (value == null) {
37 | return null;
38 | }
39 |
40 | return (T) JSON.toJSONString(value).toCharArray();
41 | }
42 |
43 | public int getFastMatchToken() {
44 | return JSONToken.LITERAL_STRING;
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/ClassDerializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Type;
4 |
5 | import com.alibaba.fastjson.JSONException;
6 | import com.alibaba.fastjson.parser.DefaultJSONParser;
7 | import com.alibaba.fastjson.parser.JSONLexer;
8 | import com.alibaba.fastjson.parser.JSONToken;
9 | import com.alibaba.fastjson.util.TypeUtils;
10 |
11 | public class ClassDerializer implements ObjectDeserializer {
12 |
13 | public final static ClassDerializer instance = new ClassDerializer();
14 |
15 | public ClassDerializer(){
16 | }
17 |
18 | @SuppressWarnings("unchecked")
19 | public T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
20 | JSONLexer lexer = parser.getLexer();
21 |
22 | if (lexer.token() == JSONToken.NULL) {
23 | lexer.nextToken();
24 | return null;
25 | }
26 |
27 | if (lexer.token() != JSONToken.LITERAL_STRING) {
28 | throw new JSONException("expect className");
29 | }
30 | String className = lexer.stringVal();
31 | lexer.nextToken(JSONToken.COMMA);
32 |
33 | return (T) TypeUtils.loadClass(className);
34 | }
35 |
36 | public int getFastMatchToken() {
37 | return JSONToken.LITERAL_STRING;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/CollectionDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.ParameterizedType;
4 | import java.lang.reflect.Type;
5 | import java.util.AbstractCollection;
6 | import java.util.ArrayList;
7 | import java.util.Collection;
8 | import java.util.EnumSet;
9 | import java.util.HashSet;
10 | import java.util.LinkedHashSet;
11 | import java.util.TreeSet;
12 |
13 | import com.alibaba.fastjson.JSONException;
14 | import com.alibaba.fastjson.parser.DefaultJSONParser;
15 | import com.alibaba.fastjson.parser.JSONToken;
16 |
17 | public class CollectionDeserializer implements ObjectDeserializer {
18 |
19 | public final static CollectionDeserializer instance = new CollectionDeserializer();
20 |
21 | @SuppressWarnings({ "unchecked", "rawtypes" })
22 | public T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
23 | if (parser.getLexer().token() == JSONToken.NULL) {
24 | parser.getLexer().nextToken(JSONToken.COMMA);
25 | return null;
26 | }
27 |
28 | Class> rawClass = getRawClass(type);
29 |
30 | Collection list;
31 | if (rawClass == AbstractCollection.class) {
32 | list = new ArrayList();
33 | } else if (rawClass.isAssignableFrom(HashSet.class)) {
34 | list = new HashSet();
35 | } else if (rawClass.isAssignableFrom(LinkedHashSet.class)) {
36 | list = new LinkedHashSet();
37 | } else if (rawClass.isAssignableFrom(TreeSet.class)) {
38 | list = new TreeSet();
39 | } else if (rawClass.isAssignableFrom(ArrayList.class)) {
40 | list = new ArrayList();
41 | } else if (rawClass.isAssignableFrom(EnumSet.class)) {
42 | Type itemType;
43 | if (type instanceof ParameterizedType) {
44 | itemType = ((ParameterizedType) type).getActualTypeArguments()[0];
45 | } else {
46 | itemType = Object.class;
47 | }
48 | list = EnumSet.noneOf((Class)itemType);
49 | } else {
50 | try {
51 | list = (Collection) rawClass.newInstance();
52 | } catch (Exception e) {
53 | throw new JSONException("create instane error, class " + rawClass.getName());
54 | }
55 | }
56 |
57 | Type itemType;
58 | if (type instanceof ParameterizedType) {
59 | itemType = ((ParameterizedType) type).getActualTypeArguments()[0];
60 | } else {
61 | itemType = Object.class;
62 | }
63 | parser.parseArray(itemType, list, fieldName);
64 |
65 | return (T) list;
66 | }
67 |
68 | public Class> getRawClass(Type type) {
69 |
70 | if (type instanceof Class>) {
71 | return (Class>) type;
72 | } else if (type instanceof ParameterizedType) {
73 | return getRawClass(((ParameterizedType) type).getRawType());
74 | } else {
75 | throw new JSONException("TODO");
76 | }
77 | }
78 |
79 | public int getFastMatchToken() {
80 | return JSONToken.LBRACKET;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/CollectionResolveFieldDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Type;
4 | import java.util.Collection;
5 | import java.util.Map;
6 |
7 | import com.alibaba.fastjson.parser.DefaultJSONParser;
8 |
9 | @SuppressWarnings("rawtypes")
10 | public final class CollectionResolveFieldDeserializer extends FieldDeserializer {
11 |
12 | private final Collection collection;
13 |
14 | public CollectionResolveFieldDeserializer(DefaultJSONParser parser, Collection collection){
15 | super(null, null);
16 | this.collection = collection;
17 | }
18 |
19 | @SuppressWarnings("unchecked")
20 | public void setValue(Object object, Object value) {
21 | collection.add(value);
22 | }
23 |
24 | public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map fieldValues) {
25 |
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/DateDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Type;
4 | import java.text.DateFormat;
5 | import java.text.ParseException;
6 | import java.util.Calendar;
7 |
8 | import com.alibaba.fastjson.JSONException;
9 | import com.alibaba.fastjson.parser.DefaultJSONParser;
10 | import com.alibaba.fastjson.parser.JSONScanner;
11 | import com.alibaba.fastjson.parser.JSONToken;
12 |
13 | public class DateDeserializer extends AbstractDateDeserializer implements ObjectDeserializer {
14 |
15 | public final static DateDeserializer instance = new DateDeserializer();
16 |
17 | @SuppressWarnings("unchecked")
18 | protected T cast(DefaultJSONParser parser, Type clazz, Object fieldName, Object val) {
19 |
20 | if (val == null) {
21 | return null;
22 | }
23 |
24 | if (val instanceof java.util.Date) {
25 | return (T) val;
26 | } else if (val instanceof Number) {
27 | return (T) new java.util.Date(((Number) val).longValue());
28 | } else if (val instanceof String) {
29 | String strVal = (String) val;
30 | if (strVal.length() == 0) {
31 | return null;
32 | }
33 |
34 | JSONScanner dateLexer = new JSONScanner(strVal);
35 | try {
36 | if (dateLexer.scanISO8601DateIfMatch(false)) {
37 | Calendar calendar = dateLexer.getCalendar();
38 |
39 | if (clazz == Calendar.class) {
40 | return (T) calendar;
41 | }
42 |
43 | return (T) calendar.getTime();
44 | }
45 | } finally {
46 | dateLexer.close();
47 | }
48 |
49 | DateFormat dateFormat = parser.getDateFormat();
50 | try {
51 | return (T) dateFormat.parse(strVal);
52 | } catch (ParseException e) {
53 | // skip
54 | }
55 |
56 | long longVal = Long.parseLong(strVal);
57 | return (T) new java.util.Date(longVal);
58 | }
59 |
60 | throw new JSONException("parse error");
61 | }
62 |
63 | public int getFastMatchToken() {
64 | return JSONToken.LITERAL_INT;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/DateFormatDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Type;
4 | import java.text.SimpleDateFormat;
5 |
6 | import com.alibaba.fastjson.JSONException;
7 | import com.alibaba.fastjson.parser.DefaultJSONParser;
8 | import com.alibaba.fastjson.parser.JSONToken;
9 |
10 | public class DateFormatDeserializer extends AbstractDateDeserializer implements ObjectDeserializer {
11 |
12 | public final static DateFormatDeserializer instance = new DateFormatDeserializer();
13 |
14 | @SuppressWarnings("unchecked")
15 | protected T cast(DefaultJSONParser parser, Type clazz, Object fieldName, Object val) {
16 |
17 | if (val == null) {
18 | return null;
19 | }
20 |
21 | if (val instanceof String) {
22 | String strVal = (String) val;
23 | if (strVal.length() == 0) {
24 | return null;
25 | }
26 |
27 | return (T) new SimpleDateFormat(strVal);
28 | }
29 |
30 | throw new JSONException("parse error");
31 | }
32 |
33 | public int getFastMatchToken() {
34 | return JSONToken.LITERAL_STRING;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/DefaultFieldDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.ParameterizedType;
4 | import java.lang.reflect.Type;
5 | import java.util.Map;
6 |
7 | import com.alibaba.fastjson.parser.DefaultJSONParser;
8 | import com.alibaba.fastjson.parser.DefaultJSONParser.ResolveTask;
9 | import com.alibaba.fastjson.parser.JSONToken;
10 | import com.alibaba.fastjson.parser.ParseContext;
11 | import com.alibaba.fastjson.parser.ParserConfig;
12 | import com.alibaba.fastjson.util.FieldInfo;
13 |
14 | public class DefaultFieldDeserializer extends FieldDeserializer {
15 |
16 | private ObjectDeserializer fieldValueDeserilizer;
17 |
18 | public DefaultFieldDeserializer(ParserConfig mapping, Class> clazz, FieldInfo fieldInfo){
19 | super(clazz, fieldInfo);
20 | }
21 |
22 | @Override
23 | public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map fieldValues) {
24 | if (fieldValueDeserilizer == null) {
25 | fieldValueDeserilizer = parser.getConfig().getDeserializer(fieldInfo);
26 | }
27 |
28 | if (objectType instanceof ParameterizedType) {
29 | ParseContext objContext = parser.getContext();
30 | objContext.setType(objectType);
31 | }
32 |
33 | Object value = fieldValueDeserilizer.deserialze(parser, getFieldType(), fieldInfo.getName());
34 | if (parser.getResolveStatus() == DefaultJSONParser.NeedToResolve) {
35 | ResolveTask task = parser.getLastResolveTask();
36 | task.setFieldDeserializer(this);
37 | task.setOwnerContext(parser.getContext());
38 | parser.setResolveStatus(DefaultJSONParser.NONE);
39 | } else {
40 | if (object == null) {
41 | fieldValues.put(fieldInfo.getName(), value);
42 | } else {
43 | setValue(object, value);
44 | }
45 | }
46 | }
47 |
48 | public int getFastMatchToken() {
49 | if (fieldValueDeserilizer != null) {
50 | return fieldValueDeserilizer.getFastMatchToken();
51 | }
52 |
53 | return JSONToken.LITERAL_INT;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/EnumDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Method;
4 | import java.lang.reflect.Type;
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | import com.alibaba.fastjson.JSONException;
9 | import com.alibaba.fastjson.parser.DefaultJSONParser;
10 | import com.alibaba.fastjson.parser.JSONLexer;
11 | import com.alibaba.fastjson.parser.JSONToken;
12 |
13 | @SuppressWarnings("rawtypes")
14 | public class EnumDeserializer implements ObjectDeserializer {
15 |
16 | private final Class> enumClass;
17 |
18 | private final Map ordinalMap = new HashMap();
19 | private final Map nameMap = new HashMap();
20 |
21 | public EnumDeserializer(Class> enumClass){
22 | this.enumClass = enumClass;
23 |
24 | try {
25 | Method valueMethod = enumClass.getMethod("values");
26 | Object[] values = (Object[]) valueMethod.invoke(null);
27 | for (Object value : values) {
28 | Enum e = (Enum) value;
29 | ordinalMap.put(e.ordinal(), e);
30 | nameMap.put(e.name(), e);
31 | }
32 | } catch (Exception ex) {
33 | throw new JSONException("init enum values error, " + enumClass.getName());
34 | }
35 | }
36 |
37 | @SuppressWarnings("unchecked")
38 | public T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
39 | try {
40 | Object value;
41 | final JSONLexer lexer = parser.getLexer();
42 | if (lexer.token() == JSONToken.LITERAL_INT) {
43 | value = lexer.intValue();
44 | lexer.nextToken(JSONToken.COMMA);
45 |
46 | T e = (T) ordinalMap.get(value);
47 | if (e == null) {
48 | throw new JSONException("parse enum " + enumClass.getName() + " error, value : " + value);
49 | }
50 | return e;
51 | } else if (lexer.token() == JSONToken.LITERAL_STRING) {
52 | String strVal = lexer.stringVal();
53 | lexer.nextToken(JSONToken.COMMA);
54 |
55 | if (strVal.length() == 0) {
56 | return (T) null;
57 | }
58 |
59 | value = nameMap.get(strVal);
60 |
61 | return (T) Enum.valueOf((Class) enumClass, strVal);
62 | } else if (lexer.token() == JSONToken.NULL) {
63 | value = null;
64 | lexer.nextToken(JSONToken.COMMA);
65 |
66 | return null;
67 | } else {
68 | value = parser.parse();
69 | }
70 |
71 | throw new JSONException("parse enum " + enumClass.getName() + " error, value : " + value);
72 | } catch (JSONException e) {
73 | throw e;
74 | } catch (Throwable e) {
75 | throw new JSONException(e.getMessage(), e);
76 | }
77 | }
78 |
79 | public int getFastMatchToken() {
80 | return JSONToken.LITERAL_INT;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/ExtraProcessor.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | /**
4 | *
5 | * @author wenshao[szujobs@hotmail.com]
6 | * @since 1.1.34
7 | */
8 | public interface ExtraProcessor extends ParseProcess {
9 |
10 | void processExtra(Object object, String key, Object value);
11 | }
12 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/ExtraTypeProvider.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Type;
4 |
5 | /**
6 | * @author wenshao[szujobs@hotmail.com]
7 | * @since 1.1.34
8 | */
9 | public interface ExtraTypeProvider extends ParseProcess {
10 |
11 | Type getExtraType(Object object, String key);
12 | }
13 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/FieldDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Field;
4 | import java.lang.reflect.Method;
5 | import java.lang.reflect.Type;
6 | import java.util.Collection;
7 | import java.util.Map;
8 |
9 | import com.alibaba.fastjson.JSONException;
10 | import com.alibaba.fastjson.parser.DefaultJSONParser;
11 | import com.alibaba.fastjson.util.FieldInfo;
12 |
13 | public abstract class FieldDeserializer {
14 |
15 | protected final FieldInfo fieldInfo;
16 |
17 | protected final Class> clazz;
18 |
19 | public FieldDeserializer(Class> clazz, FieldInfo fieldInfo){
20 | this.clazz = clazz;
21 | this.fieldInfo = fieldInfo;
22 | }
23 |
24 | public Method getMethod() {
25 | return fieldInfo.getMethod();
26 | }
27 |
28 | public Field getField() {
29 | return fieldInfo.getField();
30 | }
31 |
32 | public Class> getFieldClass() {
33 | return fieldInfo.getFieldClass();
34 | }
35 |
36 | public Type getFieldType() {
37 | return fieldInfo.getFieldType();
38 | }
39 |
40 | public abstract void parseField(DefaultJSONParser parser, Object object, Type objectType,
41 | Map fieldValues);
42 |
43 | public int getFastMatchToken() {
44 | return 0;
45 | }
46 |
47 | public void setValue(Object object, boolean value) {
48 | setValue(object, Boolean.valueOf(value));
49 | }
50 |
51 | public void setValue(Object object, int value) {
52 | setValue(object, Integer.valueOf(value));
53 | }
54 |
55 | public void setValue(Object object, long value) {
56 | setValue(object, Long.valueOf(value));
57 | }
58 |
59 | public void setValue(Object object, String value) {
60 | setValue(object, (Object) value);
61 | }
62 |
63 | @SuppressWarnings({ "rawtypes", "unchecked" })
64 | public void setValue(Object object, Object value) {
65 | Method method = fieldInfo.getMethod();
66 | if (method != null) {
67 | try {
68 | if (fieldInfo.isGetOnly()) {
69 | if (Map.class.isAssignableFrom(method.getReturnType())) {
70 | Map map = (Map) method.invoke(object);
71 | if (map != null) {
72 | map.putAll((Map) value);
73 | }
74 | } else {
75 | Collection collection = (Collection) method.invoke(object);
76 | if (collection != null) {
77 | collection.addAll((Collection) value);
78 | }
79 | }
80 | } else {
81 | if (value == null && fieldInfo.getFieldClass().isPrimitive()) {
82 | return;
83 | }
84 | method.invoke(object, value);
85 | }
86 | } catch (Exception e) {
87 | throw new JSONException("set property error, " + fieldInfo.getName(), e);
88 | }
89 | return;
90 | }
91 |
92 | final Field field = fieldInfo.getField();
93 | if (field != null) {
94 | try {
95 | field.set(object, value);
96 | } catch (Exception e) {
97 | throw new JSONException("set property error, " + fieldInfo.getName(), e);
98 | }
99 | }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/IntegerFieldDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Type;
4 | import java.util.Map;
5 |
6 | import com.alibaba.fastjson.parser.DefaultJSONParser;
7 | import com.alibaba.fastjson.parser.JSONLexer;
8 | import com.alibaba.fastjson.parser.JSONToken;
9 | import com.alibaba.fastjson.parser.ParserConfig;
10 | import com.alibaba.fastjson.util.FieldInfo;
11 | import com.alibaba.fastjson.util.TypeUtils;
12 |
13 | public class IntegerFieldDeserializer extends FieldDeserializer {
14 |
15 | public IntegerFieldDeserializer(ParserConfig mapping, Class> clazz, FieldInfo fieldInfo){
16 | super(clazz, fieldInfo);
17 | }
18 |
19 | @Override
20 | public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map fieldValues) {
21 | Integer value;
22 |
23 | final JSONLexer lexer = parser.getLexer();
24 | if (lexer.token() == JSONToken.LITERAL_INT) {
25 | int val = lexer.intValue();
26 | lexer.nextToken(JSONToken.COMMA);
27 | if (object == null) {
28 | fieldValues.put(fieldInfo.getName(), val);
29 | } else {
30 | setValue(object, val);
31 | }
32 | return;
33 | } else if (lexer.token() == JSONToken.NULL) {
34 | value = null;
35 | lexer.nextToken(JSONToken.COMMA);
36 | } else {
37 | Object obj = parser.parse();
38 |
39 | value = TypeUtils.castToInt(obj);
40 | }
41 |
42 | if (value == null && getFieldClass() == int.class) {
43 | // skip
44 | return;
45 | }
46 |
47 | if (object == null) {
48 | fieldValues.put(fieldInfo.getName(), value);
49 | } else {
50 | setValue(object, value);
51 | }
52 | }
53 |
54 | public int getFastMatchToken() {
55 | return JSONToken.LITERAL_INT;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/JSONArrayDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Type;
4 |
5 | import com.alibaba.fastjson.JSONArray;
6 | import com.alibaba.fastjson.parser.DefaultJSONParser;
7 | import com.alibaba.fastjson.parser.JSONToken;
8 |
9 | public class JSONArrayDeserializer implements ObjectDeserializer {
10 | public final static JSONArrayDeserializer instance = new JSONArrayDeserializer();
11 |
12 | @SuppressWarnings("unchecked")
13 | public T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
14 | JSONArray array = new JSONArray();
15 | parser.parseArray(array);
16 | return (T) array;
17 | }
18 |
19 | public int getFastMatchToken() {
20 | return JSONToken.LBRACKET;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/JSONObjectDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Type;
4 |
5 | import com.alibaba.fastjson.parser.DefaultJSONParser;
6 | import com.alibaba.fastjson.parser.JSONToken;
7 |
8 | public class JSONObjectDeserializer implements ObjectDeserializer {
9 | public final static JSONObjectDeserializer instance = new JSONObjectDeserializer();
10 |
11 | @SuppressWarnings("unchecked")
12 | public T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
13 | return (T) parser.parseObject();
14 | }
15 |
16 | public int getFastMatchToken() {
17 | return JSONToken.LBRACE;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/dexlibrary/src/main/java/com/alibaba/fastjson/parser/deserializer/JavaObjectDeserializer.java:
--------------------------------------------------------------------------------
1 | package com.alibaba.fastjson.parser.deserializer;
2 |
3 | import java.lang.reflect.Array;
4 | import java.lang.reflect.GenericArrayType;
5 | import java.lang.reflect.Type;
6 | import java.lang.reflect.TypeVariable;
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | import com.alibaba.fastjson.parser.DefaultJSONParser;
11 | import com.alibaba.fastjson.parser.JSONToken;
12 | import com.alibaba.fastjson.util.TypeUtils;
13 |
14 | public class JavaObjectDeserializer implements ObjectDeserializer {
15 |
16 | public final static JavaObjectDeserializer instance = new JavaObjectDeserializer();
17 |
18 | @SuppressWarnings("unchecked")
19 | public T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
20 | if (type instanceof GenericArrayType) {
21 | Type componentType = ((GenericArrayType) type).getGenericComponentType();
22 | if (componentType instanceof TypeVariable) {
23 | TypeVariable> componentVar = (TypeVariable>) componentType;
24 | componentType = componentVar.getBounds()[0];
25 | }
26 |
27 | List