本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.setVisibilityChecker方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.setVisibilityChecker方法的具体用法?Java ObjectMapper.setVisibilityChecker怎么用?Java ObjectMapper.setVisibilityChecker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.ObjectMapper
的用法示例。
在下文中一共展示了ObjectMapper.setVisibilityChecker方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@Before public void setUp() {
SimpleModule module = new SimpleModule();
module.addSerializer(AnInterface.class, new AnInterfaceSerializer());
module.addDeserializer(AnInterface.class, new AnInterfaceDeserializer());
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(module);
mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
mapper.configure(MapperFeature.AUTO_DETECT_IS_GETTERS, false);
mapper.setVisibilityChecker(mapper.getSerializationConfig()
.getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY));
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(JacksonConverterFactory.create(mapper))
.build();
service = retrofit.create(Service.class);
}
示例2: serializeFieldsOnly
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static String serializeFieldsOnly(Object value, boolean pretty) {
try {
ObjectMapper mapper = createMapper(pretty);
mapper.setVisibilityChecker(fieldsOnlyVisibilityChecker(mapper));
return mapper.writeValueAsString(value);
} catch (Exception e) {
LOGGER.error("JSON serialization error: ", e);
return "{}";
}
}
示例3: init
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
protected void init(ObjectMapper objectMapper) {
objectMapper.registerModule(new DefenceModule());
objectMapper.setSerializationInclusion(Include.NON_NULL);
objectMapper.setVisibilityChecker(objectMapper.getSerializationConfig().getDefaultVisibilityChecker()
.withFieldVisibility(JsonAutoDetect.Visibility.ANY).withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE)
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN, true);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
objectMapper.addMixIn(Throwable.class, ThrowableMixIn.class);
}
示例4: exportJson
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
public static void exportJson(Map<Method, Set<Invocation>> data) {
try {
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibilityChecker(mapper.getVisibilityChecker().withFieldVisibility(Visibility.ANY));
String formatted = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(data);
LOGGER.debug("Dereferences: {}", formatted);
} catch (JsonProcessingException exception) {
LOGGER.warn("Export of dereferences failed", exception);
}
}
示例5: getPage
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private static MobileScreen getPage(File file) throws Throwable {
MobileScreen mobileScreen;
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
try {
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
mapper.setVisibilityChecker(VisibilityChecker.Std.defaultInstance().withFieldVisibility(JsonAutoDetect.Visibility.ANY));
mobileScreen = mapper.readValue(file, MobileScreen.class);
} catch (Exception e) {
e.printStackTrace();
throw e.getCause();
}
return mobileScreen;
}