本文整理汇总了Java中com.alibaba.fastjson.parser.ParserConfig类的典型用法代码示例。如果您正苦于以下问题:Java ParserConfig类的具体用法?Java ParserConfig怎么用?Java ParserConfig使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ParserConfig类属于com.alibaba.fastjson.parser包,在下文中一共展示了ParserConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_autoTypeDeny
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
public void test_autoTypeDeny() throws Exception {
ParserConfig config = new ParserConfig();
assertFalse(config.isAutoTypeSupport());
config.setAutoTypeSupport(true);
assertTrue(config.isAutoTypeSupport());
Properties properties = new Properties();
properties.put(ParserConfig.AUTOTYPE_SUPPORT_PROPERTY, "false");
config.configFromPropety(properties);
assertFalse(config.isAutoTypeSupport());
Exception error = null;
try {
Object obj = JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest7$Model\"}", Object.class, config);
System.out.println(obj.getClass());
} catch (JSONException ex) {
error = ex;
}
assertNotNull(error);
}
示例2: test_autoTypeDeny
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
public void test_autoTypeDeny() throws Exception {
ParserConfig config = new ParserConfig();
assertFalse(config.isAutoTypeSupport());
config.setAutoTypeSupport(true);
assertTrue(config.isAutoTypeSupport());
config.addDeny("com.alibaba.json.bvt.parser.deser.deny.DenyTest6");
config.setAutoTypeSupport(false);
Exception error = null;
try {
Object obj = JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest6$Model\"}", Object.class, config);
System.out.println(obj.getClass());
} catch (JSONException ex) {
error = ex;
}
assertNotNull(error);
}
示例3: _getFieldDeser
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
private void _getFieldDeser(Context context, MethodVisitor mw, FieldInfo fieldInfo) {
Label notNull_ = new Label();
mw.visitVarInsn(ALOAD, 0);
mw.visitFieldInsn(GETFIELD, context.className, fieldInfo.name + "_asm_deser__", desc(ObjectDeserializer.class));
mw.visitJumpInsn(IFNONNULL, notNull_);
mw.visitVarInsn(ALOAD, 0);
mw.visitVarInsn(ALOAD, 1);
mw.visitMethodInsn(INVOKEVIRTUAL, DefaultJSONParser, "getConfig", "()" + desc(ParserConfig.class));
mw.visitLdcInsn(com.alibaba.fastjson.asm.Type.getType(desc(fieldInfo.fieldClass)));
mw.visitMethodInsn(INVOKEVIRTUAL, type(ParserConfig.class), "getDeserializer",
"(Ljava/lang/reflect/Type;)" + desc(ObjectDeserializer.class));
mw.visitFieldInsn(PUTFIELD, context.className, fieldInfo.name + "_asm_deser__", desc(ObjectDeserializer.class));
mw.visitLabel(notNull_);
mw.visitVarInsn(ALOAD, 0);
mw.visitFieldInsn(GETFIELD, context.className, fieldInfo.name + "_asm_deser__", desc(ObjectDeserializer.class));
}
示例4: parseObject
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static final <T> T parseObject(String input, Type clazz, int featureValues, Feature... features) {
if (input == null) {
return null;
}
for (Feature featrue : features) {
featureValues = Feature.config(featureValues, featrue, true);
}
DefaultJSONParser parser = new DefaultJSONParser(input, ParserConfig.getGlobalInstance(), featureValues);
T value = (T) parser.parseObject(clazz);
parser.handleResovleTask(value);
parser.close();
return (T) value;
}
示例5: resolveJsonString
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
public boolean resolveJsonString(Class className) {
boolean re = false;
try {
//先调用不带参数的方法解析HttpJson的内部成员变量
re = resolveJsonString();
//将对于JodaTime的逆序列化支持加载进来
ParserConfig.getGlobalInstance().putDeserializer(LocalDate.class, JodaTimeDeserializer.instance);
//将附加传递的classObjectString 先从org.json中解析出来
this.classObjectString = jsonObject.getString("classObjectString");
//确认有类传过来才执行类解析
if (!(classObjectString.equals("") || classObjectString.equals("{}"))) {
this.classObject = JSON.parseObject(classObjectString, className);
}
} catch (Exception e) {
e.printStackTrace();
}
return re;
}
示例6: parseObject
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T parseObject(String input, Type clazz, int featureValues, Feature... features) {
if (input == null) {
return null;
}
for (Feature feature : features) {
featureValues = Feature.config(featureValues, feature, true);
}
DefaultJSONParser parser = new DefaultJSONParser(input, ParserConfig.getGlobalInstance(), featureValues);
T value = (T) parser.parseObject(clazz);
parser.handleResovleTask(value);
parser.close();
return (T) value;
}
示例7: parseArray
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
public static <T> List<T> parseArray(String text, Class<T> clazz) {
if (text == null) {
return null;
}
List<T> list;
DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
JSONLexer lexer = parser.lexer;
int token = lexer.token();
if (token == JSONToken.NULL) {
lexer.nextToken();
list = null;
} else if (token == JSONToken.EOF && lexer.isBlankInput()) {
list = null;
} else {
list = new ArrayList<T>();
parser.parseArray(clazz, list);
parser.handleResovleTask(list);
}
parser.close();
return list;
}
示例8: parseArray
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
public static final List<Object> parseArray(String text, Type[] types) {
if (text == null) {
return null;
}
List<Object> list;
DefaultJSONParser parser = new DefaultJSONParser(text, ParserConfig.getGlobalInstance());
Object[] objectArray = parser.parseArray(types);
if (objectArray == null) {
list = null;
} else {
list = Arrays.asList(objectArray);
}
parser.handleResovleTask(list);
parser.close();
return list;
}
示例9: cast
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T cast(Object obj, Type type, ParserConfig mapping){
if(obj == null){
return null;
}
if(type instanceof Class){
return (T) cast(obj, (Class<T>) type, mapping);
}
if(type instanceof ParameterizedType){
return (T) cast(obj, (ParameterizedType) type, mapping);
}
if(obj instanceof String){
String strVal = (String) obj;
if(strVal.length() == 0 //
|| "null".equals(strVal) //
|| "NULL".equals(strVal)){
return null;
}
}
if(type instanceof TypeVariable){
return (T) obj;
}
throw new JSONException("can not cast to : " + type);
}
示例10: test_abc
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
public void test_abc() throws Exception {
Field field = ParserConfig.class.getDeclaredField("denyList");
field.setAccessible(true);
String[] denyList = (String[]) field.get(ParserConfig.getGlobalInstance());
Arrays.sort(denyList);
for (int i = 0; i < denyList.length; ++i) {
if (i != 0) {
System.out.print(",");
}
System.out.print(denyList[i]);
}
for (int i = 0; i < denyList.length; ++i) {
// System.out.println("\"" + denyList[i] + "\",");
System.out.println(denyList[i]);
}
System.out.println();
System.out.println(Base64.encodeToString("\"@type".getBytes(), true));
}
示例11: createFieldDeserializer
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
public FieldDeserializer createFieldDeserializer(ParserConfig mapping, //
JavaBeanInfo beanInfo, //
FieldInfo fieldInfo) {
Class<?> clazz = beanInfo.clazz;
Class<?> fieldClass = fieldInfo.fieldClass;
Class<?> deserializeUsing = null;
JSONField annotation = fieldInfo.getAnnotation();
if (annotation != null) {
deserializeUsing = annotation.deserializeUsing();
if (deserializeUsing == Void.class) {
deserializeUsing = null;
}
}
if (deserializeUsing == null && (fieldClass == List.class || fieldClass == ArrayList.class)) {
return new ArrayListTypeFieldDeserializer(mapping, clazz, fieldInfo);
}
return new DefaultFieldDeserializerBug569(mapping, clazz, fieldInfo);
}
示例12: test_camel
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
public void test_camel() throws Exception {
SerializeConfig config = new SerializeConfig();
config.propertyNamingStrategy = PropertyNamingStrategy.CamelCase;
Model model = new Model();
model.personId = 1001;
String text = JSON.toJSONString(model, config);
Assert.assertEquals("{\"personId\":1001}", text);
ParserConfig parserConfig = new ParserConfig();
parserConfig.propertyNamingStrategy = PropertyNamingStrategy.CamelCase;
Model model2 = JSON.parseObject(text, Model.class, parserConfig);
Assert.assertEquals(model.personId, model2.personId);
Model model3 = JSON.parseObject(text, Model.class);
Assert.assertEquals(model.personId, model3.personId);
}
示例13: test_parseObject
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
public void test_parseObject() {
new DefaultJSONParser("".toCharArray(), 0, ParserConfig.getGlobalInstance(), 0).close();
User user = new User();
user.setName("校长");
user.setAge(3);
user.setSalary(new BigDecimal("123456789.0123"));
String jsonString = JSON.toJSONString(user);
System.out.println(jsonString);
JSON.parseObject(jsonString);
DefaultJSONParser parser = new DefaultJSONParser(jsonString);
User user1 = new User();
parser.parseObject(user1);
Assert.assertEquals(user.getAge(), user1.getAge());
Assert.assertEquals(user.getName(), user1.getName());
Assert.assertEquals(user.getSalary(), user1.getSalary());
}
示例14: test_list
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
public void test_list() throws Exception {
A a = new A();
Set<B> set = new LinkedHashSet<B>();
set.add(new B());
set.add(new B1());
a.setList(set);
String text = JSON.toJSONString(a, SerializerFeature.WriteClassName);
System.out.println(text);
// Assert.assertEquals("{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set2$A\",\"list\":[{},{\"@type\":\"com.alibaba.json.bvt.writeClassName.WriteClassNameTest_Set2$B1\"}]}",
// text);
ParserConfig parserConfig = new ParserConfig();
parserConfig.addAccept("com.alibaba.json.bvt");
A a1 = (A) JSON.parseObject(text, Object.class, parserConfig);
Assert.assertEquals(2, a1.getList().size());
Assert.assertTrue("B", new ArrayList<B>(a1.getList()).get(0) instanceof B || new ArrayList<B>(a1.getList()).get(0) instanceof B1);
Assert.assertTrue("B1", new ArrayList<B>(a1.getList()).get(1) instanceof B || new ArrayList<B>(a1.getList()).get(1) instanceof B1);
}
示例15: test_for_issue
import com.alibaba.fastjson.parser.ParserConfig; //导入依赖的package包/类
public void test_for_issue() throws Exception {
ParserConfig config = new ParserConfig();
config.setAutoTypeSupport(true);
Map<Long, Bean> map = new HashMap<Long, Bean>();
map.put(null, new Bean());
Map<Long, Bean> rmap = (Map<Long, Bean>) JSON.parse(JSON.toJSONString(map, SerializerFeature.WriteClassName), config);
System.out.println(rmap);
}