Java 类com.alibaba.fastjson.parser.deserializer.ExtraProcessor 实例源码

项目:GitHub    文件:Issue1271.java   
public void test_for_issue() throws Exception {

        String json = "{\"a\":1,\"b\":2}";

        final AtomicInteger count = new AtomicInteger(0);
        ExtraProcessor extraProcessor = new ExtraProcessor() {
            public void processExtra(Object object, String key, Object value) {
                System.out.println("setter not found, class " + object.getClass().getName() + ", property " + key);
                count.incrementAndGet();
            }
        };


        A a = JSON.parseObject(json,A.class,extraProcessor);
        assertEquals(1,a.a);
        assertEquals(1, count.intValue());

        B b = JSON.parseObject(json,B.class,extraProcessor);
        assertEquals(1,b.a);
        assertEquals(2, count.intValue());

    }
项目:boohee_v5.6    文件:JSON.java   
public static final <T> T parseObject(String input, Type clazz, ParserConfig config, ParseProcess processor, int featureValues, Feature... features) {
    if (input == null) {
        return null;
    }
    for (Feature featrue : features) {
        featureValues = Feature.config(featureValues, featrue, true);
    }
    DefaultJSONParser parser = new DefaultJSONParser(input, config, featureValues);
    if (processor instanceof ExtraTypeProvider) {
        parser.getExtraTypeProviders().add((ExtraTypeProvider) processor);
    }
    if (processor instanceof ExtraProcessor) {
        parser.getExtraProcessors().add((ExtraProcessor) processor);
    }
    T value = parser.parseObject(clazz);
    parser.handleResovleTask(value);
    parser.close();
    return value;
}
项目:GitHub    文件:JSON.java   
@SuppressWarnings("unchecked")
public static <T> T parseObject(String input, Type clazz, ParserConfig config, ParseProcess processor,
                                      int featureValues, Feature... features) {
    if (input == null) {
        return null;
    }

    if (features != null) {
        for (Feature feature : features) {
            featureValues |= feature.mask;
        }
    }

    DefaultJSONParser parser = new DefaultJSONParser(input, config, featureValues);

    if (processor != null) {
        if (processor instanceof ExtraTypeProvider) {
            parser.getExtraTypeProviders().add((ExtraTypeProvider) processor);
        }

        if (processor instanceof ExtraProcessor) {
            parser.getExtraProcessors().add((ExtraProcessor) processor);
        }

        if (processor instanceof FieldTypeResolver) {
            parser.setFieldTypeResolver((FieldTypeResolver) processor);
        }
    }

    T value = (T) parser.parseObject(clazz, null);

    parser.handleResovleTask(value);

    parser.close();

    return (T) value;
}
项目:boohee_v5.6    文件:FilterUtils.java   
public static void processExtra(DefaultJSONParser parser, Object object, String key, Object value) {
    List<ExtraProcessor> extraProcessors = parser.getExtraProcessorsDirect();
    if (extraProcessors != null) {
        for (ExtraProcessor process : extraProcessors) {
            process.processExtra(object, key, value);
        }
    }
}
项目:uavstack    文件:FilterUtils.java   
public static void processExtra(DefaultJSONParser parser, Object object, String key, Object value) {
    List<ExtraProcessor> extraProcessors = parser.getExtraProcessorsDirect();
    if (extraProcessors == null) {
        return;
    }
    for (ExtraProcessor process : extraProcessors) {
        process.processExtra(object, key, value);
    }
}
项目:uavstack    文件:JSON.java   
@SuppressWarnings("unchecked")
public static final <T> T parseObject(String input, Type clazz, ParserConfig config, ParseProcess processor,
                                      int featureValues, Feature... features) {
    if (input == null) {
        return null;
    }

    for (Feature featrue : features) {
        featureValues = Feature.config(featureValues, featrue, true);
    }

    DefaultJSONParser parser = new DefaultJSONParser(input, config, featureValues);

    if (processor instanceof ExtraTypeProvider) {
        parser.getExtraTypeProviders().add((ExtraTypeProvider) processor);
    }

    if (processor instanceof ExtraProcessor) {
        parser.getExtraProcessors().add((ExtraProcessor) processor);
    }

    T value = (T) parser.parseObject(clazz);

    parser.handleResovleTask(value);

    parser.close();

    return (T) value;
}
项目:itmarry    文件:FilterUtils.java   
public static void processExtra(DefaultJSONParser parser, Object object, String key, Object value) {
    List<ExtraProcessor> extraProcessors = parser.getExtraProcessorsDirect();
    if (extraProcessors == null) {
        return;
    }
    for (ExtraProcessor process : extraProcessors) {
        process.processExtra(object, key, value);
    }
}
项目:itmarry    文件:JSON.java   
@SuppressWarnings("unchecked")
public static final <T> T parseObject(String input, Type clazz, ParserConfig config, ParseProcess processor,
                                      int featureValues, Feature... features) {
    if (input == null) {
        return null;
    }

    for (Feature featrue : features) {
        featureValues = Feature.config(featureValues, featrue, true);
    }

    DefaultJSONParser parser = new DefaultJSONParser(input, config, featureValues);

    if (processor instanceof ExtraTypeProvider) {
        parser.getExtraTypeProviders().add((ExtraTypeProvider) processor);
    }

    if (processor instanceof ExtraProcessor) {
        parser.getExtraProcessors().add((ExtraProcessor) processor);
    }

    T value = (T) parser.parseObject(clazz);

    handleResovleTask(parser, value);

    parser.close();

    return (T) value;
}
项目:boohee_v5.6    文件:DefaultJSONParser.java   
public List<ExtraProcessor> getExtraProcessors() {
    if (this.extraProcessors == null) {
        this.extraProcessors = new ArrayList(2);
    }
    return this.extraProcessors;
}
项目:boohee_v5.6    文件:DefaultJSONParser.java   
public List<ExtraProcessor> getExtraProcessorsDirect() {
    return this.extraProcessors;
}
项目:uavstack    文件:DefaultJSONParser.java   
public List<ExtraProcessor> getExtraProcessors() {
    if (extraProcessors == null) {
        extraProcessors = new ArrayList<ExtraProcessor>(2);
    }
    return extraProcessors;
}
项目:uavstack    文件:DefaultJSONParser.java   
public List<ExtraProcessor> getExtraProcessorsDirect() {
    return extraProcessors;
}
项目:itmarry    文件:DefaultJSONParser.java   
public List<ExtraProcessor> getExtraProcessors() {
    if (extraProcessors == null) {
        extraProcessors = new ArrayList<ExtraProcessor>(2);
    }
    return extraProcessors;
}
项目:itmarry    文件:DefaultJSONParser.java   
public List<ExtraProcessor> getExtraProcessorsDirect() {
    return extraProcessors;
}