本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.enable方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.enable方法的具体用法?Java ObjectMapper.enable怎么用?Java ObjectMapper.enable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.ObjectMapper
的用法示例。
在下文中一共展示了ObjectMapper.enable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJsonSchema
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public String getJsonSchema() {
ObjectMapper mapper = new ObjectMapper();
try {
mapper.enable(SerializationFeature.INDENT_OUTPUT);
return mapper.writeValueAsString(jsonSchema);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
示例2: writeTypescriptConfig
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private void writeTypescriptConfig() throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
ObjectNode root = mapper.createObjectNode();
ObjectNode compilerOptions = root.putObject("compilerOptions");
compilerOptions.put("baseUrl", "");
compilerOptions.put("declaration", true);
compilerOptions.put("emitDecoratorMetadata", true);
compilerOptions.put("experimentalDecorators", true);
compilerOptions.put("module", "es6");
compilerOptions.put("moduleResolution", "node");
compilerOptions.put("sourceMap", true);
compilerOptions.put("target", "es5");
ArrayNode typeArrays = compilerOptions.putArray("typeRoots");
typeArrays.add("node_modules/@types");
ArrayNode libs = compilerOptions.putArray("lib");
libs.add("es6");
libs.add("dom");
File outputSourceDir = new File(outputDir, config.getSourceDirectoryName());
File file = new File(outputSourceDir, "tsconfig.json");
file.getParentFile().mkdirs();
mapper.writer().writeValue(file, root);
}
示例3: configure
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
public void configure(Map configs, boolean isKey) {
String documentBasePackage = (String) configs.get("documentBasePackage");
SimpleModule module = new SimpleModule();
Set<Class<?>> annotatedClasses = ClassUtils.getAnnotatedClasses(documentBasePackage, Document.class);
annotatedClasses.forEach(aClass -> module.addSerializer(aClass, new MetaableJkesJsonSerializer<>()));
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);
// mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.enable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); // Feature is enabled by default, so that date/time are by default serialized as timestamps.
mapper.disable(SerializationFeature.WRITE_NULL_MAP_VALUES);
this.mapper = mapper;
}
示例4: generate
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Override
public void generate(Object obj, OutputStream os, boolean prettyPrint) {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.CLOSE_CLOSEABLE, false);
mapper.configure(SerializationFeature.FLUSH_AFTER_WRITE_VALUE, false);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
if (prettyPrint) {
mapper.enable(SerializationFeature.INDENT_OUTPUT);
}
SimpleModule module = new SimpleModule();
module.addSerializer(CfnObject.class, new CfnObjectSerializer(resourceSpecificationService));
module.addSerializer(IntrinsicFunction.class, new IntrinsicFunctionSerializer());
mapper.registerModule(module);
try {
mapper.writeValue(os, obj);
os.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例5: DebugEndpoint
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public DebugEndpoint() {
om = new ObjectMapper();
om.enable(SerializationFeature.INDENT_OUTPUT);
}
示例6: loadJson
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private JsonNode loadJson(InputStream inputStream) throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(JsonParser.Feature.ALLOW_COMMENTS);
return objectMapper.readTree(inputStream);
}
示例7: jsonBeautify
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private static String jsonBeautify(String input) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.setDefaultPrettyPrinter(PrettyPrinter.instance);
JsonNode tree;
String output;
try {
tree = objectMapper.readTree(input);
output = objectMapper.writeValueAsString(tree);
} catch (IOException e) {
return input;
}
return output;
}
示例8: toJson
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private String toJson(final Object object) throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
String jsonRep = "";
jsonRep = mapper.writeValueAsString(object);
return jsonRep;
}
示例9: writeDataToFile
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private void writeDataToFile() throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.enable(SerializationFeature.INDENT_OUTPUT);
File recordFile = getRecordFile(testName);
recordFile.createNewFile();
mapper.writeValue(recordFile, recordedData);
}
示例10: fromJson
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
default ConfigurationType fromJson(InputStream inputStream) throws IOException {
TypeReference<ConfigurationType> typeReference = new TypeReference<ConfigurationType>() {
};
ObjectMapper mapper = new ObjectMapper();
mapper.enable(JsonParser.Feature.ALLOW_COMMENTS);
return mapper.readValue(inputStream, typeReference);
}
示例11: createMapper
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static ObjectMapper createMapper(boolean pretty) {
ObjectMapper mapper = new ObjectMapper();
if (pretty) {
mapper.enable(SerializationFeature.INDENT_OUTPUT);
}
return mapper;
}
示例12: DrillConfig
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@VisibleForTesting
public DrillConfig(Config config, boolean enableServerConfigs) {
super(config);
logger.debug("Setting up DrillConfig object.");
logger.trace("Given Config object is:\n{}",
config.root().render(ConfigRenderOptions.defaults()));
mapper = new ObjectMapper();
if (enableServerConfigs) {
SimpleModule deserModule = new SimpleModule("LogicalExpressionDeserializationModule")
.addDeserializer(LogicalExpression.class, new LogicalExpression.De(this))
.addDeserializer(SchemaPath.class, new SchemaPath.De());
mapper.registerModule(deserModule);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mapper.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true);
mapper.configure(Feature.ALLOW_COMMENTS, true);
mapper.registerSubtypes(LogicalOperatorBase.getSubTypes(this));
mapper.registerSubtypes(StoragePluginConfigBase.getSubTypes(this));
mapper.registerSubtypes(FormatPluginConfigBase.getSubTypes(this));
}
RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
this.startupArguments = ImmutableList.copyOf(bean.getInputArguments());
logger.debug("DrillConfig object initialized.");
}
示例13: toJson
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Test
public void toJson() throws Exception {
String expected = "{\"accessControlType\":\"READ_ONLY\",\"databasePrefix\":\"name_\",\"federationType\":\"FEDERATED\",\"mappedDatabases\":[],\"metastoreTunnel\":null,\"name\":\"name\",\"remoteMetaStoreUris\":\"uri\",\"status\":\"UNKNOWN\"}";
ObjectMapper mapper = new ObjectMapper();
// Sorting to get deterministic test behaviour
mapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
String json = mapper.writerFor(FederatedMetaStore.class).writeValueAsString(metaStore);
assertThat(json, is(expected));
}
示例14: getInstance
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static ProjectServices getInstance() {
if(instance == null) {
instance = new ProjectServices();
mapper = new ObjectMapper();
mapper.registerModule(new HueSerDeModule());
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.enable(JsonParser.Feature.ALLOW_COMMENTS);
mapper.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
mapper.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);
}
return instance;
}
示例15: setup
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Before
public void setup(){
mapper = new ObjectMapper();
mapper.registerModule(new HueSerDeModule());
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.enable(JsonParser.Feature.ALLOW_COMMENTS);
mapper.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES);
mapper.enable(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES);
}