android.net.Uri support.

This commit is contained in:
wenshao
2017-03-20 18:36:36 +08:00
parent ca5f8a3c4c
commit e1bd579bb5
3 changed files with 36 additions and 2 deletions
@@ -208,7 +208,13 @@ public class ParserConfig {
} else if (Throwable.class.isAssignableFrom(clazz)) {
deserializer = new ThrowableDeserializer(this, clazz);
} else {
deserializer = new JavaBeanDeserializer(this, clazz, type);
String clazzName = clazz.getName();
if (clazzName.equals("android.net.Uri")) {
deserializer = MiscCodec.instance;
} else {
deserializer = new JavaBeanDeserializer(this, clazz, type);
}
}
putDeserializer(type, deserializer);
@@ -762,6 +762,10 @@ public class TypeUtils {
if (className == null || className.length() == 0) {
return null;
}
if (className.length() >= 256) {
throw new JSONException("className too long. " + className);
}
Class<?> clazz = mappings.get(className);
@@ -795,7 +799,7 @@ public class TypeUtils {
try {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if (contextClassLoader != null) {
if (contextClassLoader != null && contextClassLoader != classLoader) {
clazz = contextClassLoader.loadClass(className);
mappings.put(className, clazz);
@@ -0,0 +1,24 @@
package com.alibaba.json.bvt.android;
import android.net.Uri;
import com.alibaba.fastjson.JSON;
import junit.framework.TestCase;
/**
* Created by wenshao on 23/02/2017.
*/
public class UriTest extends TestCase {
public void test_android_uri() throws Exception {
Uri uri = Uri.parse("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png");
String str = JSON.toJSONString(uri);
assertEquals("\"https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png\"", str);
Uri uri2 = JSON.parseObject(str, Uri.class);
}
public static class Model {
}
}