简体   繁体   English

为什么不在com.fasterxml.jackson.databind.ObjectMapper static中创建一些方法呢?

[英]Why not make some methods in com.fasterxml.jackson.databind.ObjectMapper static?

In my project i used a lot com.fasterxml.jackson.databind.ObjectMapper to deal with JSON, for example: 在我的项目中,我使用了很多com.fasterxml.jackson.databind.ObjectMapper来处理JSON,例如:

ObjectMapper mapper = new ObjectMapper();
A a = mapper.readValue(file.getBytes(), A.class);

At first sight I think it's better it's better to make the readValue method static, then we can use it as ObjectMapper.readValue(), much more clear. 乍一看,我认为最好将readValue方法设为静态,然后我们可以将它用作ObjectMapper.readValue(),更加清晰。 But I know there must be some reasons that it shouldn't, does anyone know it? 但我知道必须有一些理由不应该,有人知道吗?

Other reason is with each instance of ObjectMapper you bind certain specific confuguration ready by ObjectMapper while serialization and desrialization process somethinglike below. 其他原因是ObjectMapper的每个实例都绑定了ObjectMapper准备好的特定配置,而序列化和反序列化过程则类似于下面的内容。 So you can configure different startegies while object conversion process. 因此,您可以在对象转换过程中配置不同的startegies。

 ObjectMapper mapper = new ObjectMapper();
   mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
   String json = mapper.writeValueAsString(new MyBean());

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法解析导入com.fasterxml.jackson.databind.ObjectMapper - The import com.fasterxml.jackson.databind.ObjectMapper cannot be resolved Flink作业:获取InvalidClassException:com.fasterxml.jackson.databind.ObjectMapper - Flink Job : Getting InvalidClassException: com.fasterxml.jackson.databind.ObjectMapper 使用com.fasterxml.jackson.databind.ObjectMapper序列化接口字段 - serialize interface fields using com.fasterxml.jackson.databind.ObjectMapper com.fasterxml.jackson.databind.ObjectMapper编码用于本地化字符 - com.fasterxml.jackson.databind.ObjectMapper encoding for localised characters 如何使用 com.fasterxml.jackson.databind.ObjectMapper 解析和对象包含在数字数组中 - How to parse and object that have inside an array of numbers using com.fasterxml.jackson.databind.ObjectMapper Proguard:java.lang.ClassNotFoundException:com.fasterxml.jackson.databind.ObjectMapper - Proguard: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper Spring Boot/@JDBCTest - 没有可用的“com.fasterxml.jackson.databind.ObjectMapper”类型的合格 bean - Spring Boot/@JDBCTest - No qualifying bean of type 'com.fasterxml.jackson.databind.ObjectMapper' available java.lang.ClassNotFoundException:Java 11中的com.fasterxml.jackson.databind.ObjectMapper - java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper in Java 11 Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper in IntelliJ after upgrading to Java 11 - Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ObjectMapper in IntelliJ after upgrading to Java 11 com / fasterxml / jackson / databind / ObjectMapper的Android NoClassDefFoundError - Android NoClassDefFoundError for com/fasterxml/jackson/databind/ObjectMapper
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM