Example usage for com.fasterxml.jackson.core JsonFactory setOutputDecorator

List of usage examples for com.fasterxml.jackson.core JsonFactory setOutputDecorator

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonFactory setOutputDecorator.

Prototype

public JsonFactory setOutputDecorator(OutputDecorator d) 

Source Link

Document

Method for overriding currently configured output decorator

Usage

From source file:org.jberet.support.io.JsonItemWriter.java

protected static JsonGenerator configureJsonGenerator(final JsonFactory jsonFactory,
        final OutputStream outputStream, final Class<?> outputDecorator,
        final Map<String, String> jsonGeneratorFeatures) throws Exception {
    if (outputDecorator != null) {
        jsonFactory.setOutputDecorator((OutputDecorator) outputDecorator.newInstance());
    }//  www.  j a  v a 2  s . c  o  m
    final JsonGenerator jsonGenerator = jsonFactory.createGenerator(outputStream);

    if (jsonGeneratorFeatures != null) {
        for (final Map.Entry<String, String> e : jsonGeneratorFeatures.entrySet()) {
            final String key = e.getKey();
            final String value = e.getValue();
            final JsonGenerator.Feature feature;
            try {
                feature = JsonGenerator.Feature.valueOf(key);
            } catch (final Exception e1) {
                throw SupportMessages.MESSAGES.unrecognizedReaderWriterProperty(key, value);
            }
            if ("true".equals(value)) {
                if (!feature.enabledByDefault()) {
                    jsonGenerator.configure(feature, true);
                }
            } else if ("false".equals(value)) {
                if (feature.enabledByDefault()) {
                    jsonGenerator.configure(feature, false);
                }
            } else {
                throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, value, key);
            }
        }
    }

    return jsonGenerator;
}

From source file:org.jberet.support.io.NoMappingJsonFactoryObjectFactory.java

static void configureInputDecoratorAndOutputDecorator(final JsonFactory jsonFactory,
        final Hashtable<?, ?> environment) throws Exception {
    final Object inputDecorator = environment.get("inputDecorator");
    if (inputDecorator != null) {
        final Class<?> inputDecoratorClass = NoMappingJsonFactoryObjectFactory.class.getClassLoader()
                .loadClass((String) inputDecorator);
        jsonFactory.setInputDecorator((InputDecorator) inputDecoratorClass.newInstance());
    }//from  w  w w .ja v  a  2s  .  c  o  m

    final Object outputDecorator = environment.get("outputDecorator");
    if (outputDecorator != null) {
        final Class<?> outputDecoratorClass = NoMappingJsonFactoryObjectFactory.class.getClassLoader()
                .loadClass((String) outputDecorator);
        jsonFactory.setOutputDecorator((OutputDecorator) outputDecoratorClass.newInstance());
    }
}