com.fasterxml.jackson.core.JsonFactory#configure ( )源码实例Demo

下面列出了com.fasterxml.jackson.core.JsonFactory#configure ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Bats   文件: Metadata.java
/**
 * Serialize parquet metadata to json and write to a file.
 *
 * @param parquetMetadata parquet table or directory metadata
 * @param p file path
 * @param fs Drill file system
 * @throws IOException if metadata can't be serialized
 */
private void writeFile(Object parquetMetadata, Path p, FileSystem fs) throws IOException {
  JsonFactory jsonFactory = new JsonFactory();
  jsonFactory.configure(Feature.AUTO_CLOSE_TARGET, false);
  jsonFactory.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false);
  ObjectMapper mapper = new ObjectMapper(jsonFactory);
  SimpleModule module = new SimpleModule();
  module.addSerializer(Path.class, new PathSerDe.Se());
  if (parquetMetadata instanceof Metadata_V4.FileMetadata) {
    module.addSerializer(ColumnMetadata_v4.class, new ColumnMetadata_v4.Serializer());
  }
  mapper.registerModule(module);
  OutputStream os = fs.create(p);
  mapper.writerWithDefaultPrettyPrinter().writeValue(os, parquetMetadata);
  os.flush();
  os.close();
}
 
源代码2 项目: ojai   文件: JsonDocumentStream.java
public JsonDocumentStream(InputStream in,
    Map<FieldPath, Type> fieldPathTypeMap, Events.Delegate eventDelegate) {
  inputStream = in;
  readStarted = false;
  iteratorOpened = false;
  this.eventDelegate = eventDelegate;
  this.fieldPathTypeMap = fieldPathTypeMap;
  try {
    JsonFactory jFactory = new JsonFactory();
    /* setting explicitly AUTO_CLOSE_SOURCE = false to ensure that
     * jsonParser.close() do not close the underlying inputstream.
     * It has to be closed by the owner of the stream.
     */
    jFactory.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false);
    jsonParser = jFactory.createParser(inputStream);
  } catch (IOException e) {
    throw new DecodingException(e);
  }
}
 
源代码3 项目: biweekly   文件: JCalRawWriter.java
private void init() throws IOException {
	JsonFactory factory = new JsonFactory();
	factory.configure(Feature.AUTO_CLOSE_TARGET, false);
	generator = factory.createGenerator(writer);

	if (prettyPrint) {
		if (prettyPrinter == null) {
			prettyPrinter = new JCalPrettyPrinter();
		}
		generator.setPrettyPrinter(prettyPrinter);
	}

	if (wrapInArray) {
		generator.writeStartArray();
	}
}
 
源代码4 项目: pulsar-flink   文件: JSONOptions.java
/** Sets config options on a Jackson [[JsonFactory]]. */
public void setJacksonOptions(JsonFactory factory) {
    factory.configure(JsonParser.Feature.ALLOW_COMMENTS, allowComments);
    factory.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, allowUnquotedFieldNames);
    factory.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, allowSingleQuotes);
    factory.configure(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS, allowNumericLeadingZeros);
    factory.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS, allowNonNumericNumbers);
    factory.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, allowBackslashEscapingAnyCharacter);
    factory.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, allowUnquotedControlChars);
}
 
/**
 * Creates an ObjectMapper that doesn't close output streams
 *
 * @return a preconfigured ObjectMapper
 */
private static ObjectMapper createObjectMapper() {
	JsonFactory jsonFactory = new JsonFactory();
	// Don't close underlying streams
	jsonFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
	ObjectMapper mapper = new ObjectMapper(jsonFactory);
	mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
	return mapper;
}
 
private ObjectMapper createMapper() {
    JsonFactory jsonFactory = new JsonFactory();
    jsonFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
    ObjectMapper mapper = new ObjectMapper(jsonFactory);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.registerModule(new Jdk8Module());
    return mapper;
}
 
源代码7 项目: syndesis   文件: DataVirtualizationService.java
/**
 * Create an export of the current workspace.  Optionally including the full vdb.
 */
private StreamingResponseBody createExportStream(DataVirtualization dv, VDBMetaData theVdb, Long revision)
        {
    DataVirtualizationV1Adapter adapter = new DataVirtualizationV1Adapter(dv);

    List<? extends ViewDefinition> views = getWorkspaceManager().findViewDefinitions(dv.getName());

    Map<String, SourceV1> sources = new LinkedHashMap<>();

    for (ViewDefinition view : views) {
        adapter.getViews().add(new ViewDefinitionV1Adapter(view));
        for (String path : view.getSourcePaths()) {
            String connection = PathUtils.getOptions(path).get(0).getSecond();
            if (sources.containsKey(connection)) {
                continue;
            }
            TeiidDataSource tds = this.metadataService.findTeiidDatasource(connection);
            if (tds != null) {
                SourceV1 source = new SourceV1();
                source.setSourceId(tds.getSyndesisId());
                source.setName(tds.getName());
                sources.put(connection, source);
            }
        }
    }

    List<TablePrivileges> tablePrivileges = getWorkspaceManager().findAllTablePrivileges(dv.getName());
    for (TablePrivileges privileges : tablePrivileges) {
        adapter.getTablePriveleges().add(new TablePrivilegeV1Adapter(privileges));
    }

    adapter.setSources(new ArrayList<>(sources.values()));

    return out -> {
        ZipOutputStream zos = new ZipOutputStream(out);

        JsonFactory jsonFactory = new JsonFactory();
        jsonFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
        ObjectMapper mapper = new ObjectMapper(jsonFactory);

        zos.putNextEntry(new ZipEntry(DV_JSON));
        mapper.writerWithDefaultPrettyPrinter().writeValue(zos, adapter);
        zos.closeEntry();

        zos.putNextEntry(new ZipEntry("dv-info.json")); //$NON-NLS-1$
        String json = String.format("{\"exportVersion\":%s,%n" //$NON-NLS-1$
                + "\"revision\":%s,%n" //$NON-NLS-1$
                + "\"entityVersion\":%s}", 1, //$NON-NLS-1$
                revision == null ? "\"draft\"" : revision, dv.getVersion()); //$NON-NLS-1$
        zos.write(json.getBytes("UTF-8")); //$NON-NLS-1$
        zos.closeEntry();

        if (theVdb != null) {
            zos.putNextEntry(new ZipEntry(DV_VDB_XML));
            try {
                VDBMetadataParser.marshall(theVdb, zos);
            } catch (XMLStreamException e) {
                throw new IOException(e);
            }
            //the marshal closes automatically
            //zos.closeEntry();
        }

        zos.close();
    };
}
 
源代码8 项目: rdf4j   文件: AbstractSPARQLJSONParser.java
/**
 * Get an instance of JsonFactory configured using the settings from {@link #getParserConfig()}.
 *
 * @return A newly configured JsonFactory based on the currently enabled settings
 */
private JsonFactory configureNewJsonFactory() {
	final JsonFactory nextJsonFactory = new JsonFactory();
	// Disable features that may work for most JSON where the field names are
	// in limited supply,
	// but does not work for SPARQL/JSON where a wide range of URIs are used for
	// subjects and predicates
	nextJsonFactory.disable(JsonFactory.Feature.INTERN_FIELD_NAMES);
	nextJsonFactory.disable(JsonFactory.Feature.CANONICALIZE_FIELD_NAMES);
	nextJsonFactory.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);

	if (getParserConfig().isSet(JSONSettings.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER,
				getParserConfig().get(JSONSettings.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_COMMENTS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_COMMENTS,
				getParserConfig().get(JSONSettings.ALLOW_COMMENTS));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_NON_NUMERIC_NUMBERS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS,
				getParserConfig().get(JSONSettings.ALLOW_NON_NUMERIC_NUMBERS));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_NUMERIC_LEADING_ZEROS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS,
				getParserConfig().get(JSONSettings.ALLOW_NUMERIC_LEADING_ZEROS));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_SINGLE_QUOTES)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES,
				getParserConfig().get(JSONSettings.ALLOW_SINGLE_QUOTES));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_UNQUOTED_CONTROL_CHARS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS,
				getParserConfig().get(JSONSettings.ALLOW_UNQUOTED_CONTROL_CHARS));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_UNQUOTED_FIELD_NAMES)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES,
				getParserConfig().get(JSONSettings.ALLOW_UNQUOTED_FIELD_NAMES));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_YAML_COMMENTS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS,
				getParserConfig().get(JSONSettings.ALLOW_YAML_COMMENTS));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_TRAILING_COMMA)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_TRAILING_COMMA,
				getParserConfig().get(JSONSettings.ALLOW_TRAILING_COMMA));
	}
	if (getParserConfig().isSet(JSONSettings.INCLUDE_SOURCE_IN_LOCATION)) {
		nextJsonFactory.configure(JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION,
				getParserConfig().get(JSONSettings.INCLUDE_SOURCE_IN_LOCATION));
	}
	if (getParserConfig().isSet(JSONSettings.STRICT_DUPLICATE_DETECTION)) {
		nextJsonFactory.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION,
				getParserConfig().get(JSONSettings.STRICT_DUPLICATE_DETECTION));
	}
	return nextJsonFactory;
}
 
源代码9 项目: rdf4j   文件: RDFJSONParser.java
/**
 * Get an instance of JsonFactory configured using the settings from {@link #getParserConfig()}.
 *
 * @return A newly configured JsonFactory based on the currently enabled settings
 */
private JsonFactory configureNewJsonFactory() {
	final JsonFactory nextJsonFactory = new JsonFactory();
	// Disable features that may work for most JSON where the field names are
	// in limited supply,
	// but does not work for RDF/JSON where a wide range of URIs are used for
	// subjects and predicates
	nextJsonFactory.disable(JsonFactory.Feature.INTERN_FIELD_NAMES);
	nextJsonFactory.disable(JsonFactory.Feature.CANONICALIZE_FIELD_NAMES);
	nextJsonFactory.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);

	if (getParserConfig().isSet(JSONSettings.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER,
				getParserConfig().get(JSONSettings.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_COMMENTS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_COMMENTS,
				getParserConfig().get(JSONSettings.ALLOW_COMMENTS));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_NON_NUMERIC_NUMBERS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS,
				getParserConfig().get(JSONSettings.ALLOW_NON_NUMERIC_NUMBERS));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_NUMERIC_LEADING_ZEROS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS,
				getParserConfig().get(JSONSettings.ALLOW_NUMERIC_LEADING_ZEROS));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_SINGLE_QUOTES)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES,
				getParserConfig().get(JSONSettings.ALLOW_SINGLE_QUOTES));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_UNQUOTED_CONTROL_CHARS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS,
				getParserConfig().get(JSONSettings.ALLOW_UNQUOTED_CONTROL_CHARS));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_UNQUOTED_FIELD_NAMES)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES,
				getParserConfig().get(JSONSettings.ALLOW_UNQUOTED_FIELD_NAMES));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_YAML_COMMENTS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS,
				getParserConfig().get(JSONSettings.ALLOW_YAML_COMMENTS));
	}
	if (getParserConfig().isSet(JSONSettings.ALLOW_TRAILING_COMMA)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_TRAILING_COMMA,
				getParserConfig().get(JSONSettings.ALLOW_TRAILING_COMMA));
	}
	if (getParserConfig().isSet(JSONSettings.INCLUDE_SOURCE_IN_LOCATION)) {
		nextJsonFactory.configure(JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION,
				getParserConfig().get(JSONSettings.INCLUDE_SOURCE_IN_LOCATION));
	}
	if (getParserConfig().isSet(JSONSettings.STRICT_DUPLICATE_DETECTION)) {
		nextJsonFactory.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION,
				getParserConfig().get(JSONSettings.STRICT_DUPLICATE_DETECTION));
	}
	return nextJsonFactory;
}
 
源代码10 项目: rdf4j   文件: JSONLDParser.java
/**
 * Get an instance of JsonFactory configured using the settings from {@link #getParserConfig()}.
 *
 * @return A newly configured JsonFactory based on the currently enabled settings
 */
private JsonFactory configureNewJsonFactory() {
	final JsonFactory nextJsonFactory = new JsonFactory(JSON_MAPPER);
	ParserConfig parserConfig = getParserConfig();

	if (parserConfig.isSet(JSONSettings.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER,
				parserConfig.get(JSONSettings.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
	}
	if (parserConfig.isSet(JSONSettings.ALLOW_COMMENTS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_COMMENTS,
				parserConfig.get(JSONSettings.ALLOW_COMMENTS));
	}
	if (parserConfig.isSet(JSONSettings.ALLOW_NON_NUMERIC_NUMBERS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS,
				parserConfig.get(JSONSettings.ALLOW_NON_NUMERIC_NUMBERS));
	}
	if (parserConfig.isSet(JSONSettings.ALLOW_NUMERIC_LEADING_ZEROS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS,
				parserConfig.get(JSONSettings.ALLOW_NUMERIC_LEADING_ZEROS));
	}
	if (parserConfig.isSet(JSONSettings.ALLOW_SINGLE_QUOTES)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES,
				parserConfig.get(JSONSettings.ALLOW_SINGLE_QUOTES));
	}
	if (parserConfig.isSet(JSONSettings.ALLOW_UNQUOTED_CONTROL_CHARS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS,
				parserConfig.get(JSONSettings.ALLOW_UNQUOTED_CONTROL_CHARS));
	}
	if (parserConfig.isSet(JSONSettings.ALLOW_UNQUOTED_FIELD_NAMES)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES,
				parserConfig.get(JSONSettings.ALLOW_UNQUOTED_FIELD_NAMES));
	}
	if (parserConfig.isSet(JSONSettings.ALLOW_YAML_COMMENTS)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_YAML_COMMENTS,
				parserConfig.get(JSONSettings.ALLOW_YAML_COMMENTS));
	}
	if (parserConfig.isSet(JSONSettings.ALLOW_TRAILING_COMMA)) {
		nextJsonFactory.configure(JsonParser.Feature.ALLOW_TRAILING_COMMA,
				parserConfig.get(JSONSettings.ALLOW_TRAILING_COMMA));
	}
	if (parserConfig.isSet(JSONSettings.INCLUDE_SOURCE_IN_LOCATION)) {
		nextJsonFactory.configure(JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION,
				parserConfig.get(JSONSettings.INCLUDE_SOURCE_IN_LOCATION));
	}
	if (parserConfig.isSet(JSONSettings.STRICT_DUPLICATE_DETECTION)) {
		nextJsonFactory.configure(JsonParser.Feature.STRICT_DUPLICATE_DETECTION,
				parserConfig.get(JSONSettings.STRICT_DUPLICATE_DETECTION));
	}
	return nextJsonFactory;
}
 
private static ObjectMapper objectMapper() {
    JsonFactory jf = new JsonFactory();
    jf.configure(JsonParser.Feature.INCLUDE_SOURCE_IN_LOCATION, false);
    return new ObjectMapper(jf);
}