本文整理匯總了Java中com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility類的典型用法代碼示例。如果您正苦於以下問題:Java Visibility類的具體用法?Java Visibility怎麽用?Java Visibility使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Visibility類屬於com.fasterxml.jackson.annotation.JsonAutoDetect包,在下文中一共展示了Visibility類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: additionalPropertiesWorkWithAllVisibility
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
@Test
public void additionalPropertiesWorkWithAllVisibility() throws ClassNotFoundException, SecurityException, NoSuchMethodException, JsonProcessingException, IOException {
mapper.configure(MapperFeature.AUTO_DETECT_GETTERS, false);
mapper.configure(MapperFeature.AUTO_DETECT_SETTERS, false);
mapper.setVisibility(mapper.getVisibilityChecker().with(Visibility.ANY));
ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/additionalProperties/defaultAdditionalProperties.json", "com.example");
Class<?> classWithAdditionalProperties = resultsClassLoader.loadClass("com.example.DefaultAdditionalProperties");
String jsonWithAdditionalProperties = "{\"a\":1, \"b\":2};";
Object instanceWithAdditionalProperties = mapper.readValue(jsonWithAdditionalProperties, classWithAdditionalProperties);
JsonNode jsonNode = mapper.readTree(mapper.writeValueAsString(instanceWithAdditionalProperties));
assertThat(jsonNode.path("a").asText(), is("1"));
assertThat(jsonNode.path("b").asInt(), is(2));
assertThat(jsonNode.has("additionalProperties"), is(false));
}
示例2: testFactoryMethods
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
public void testFactoryMethods() {
JsonAutoDetect.Value v = JsonAutoDetect.Value.construct(PropertyAccessor.FIELD,
Visibility.ANY);
assertEquals(Visibility.ANY, v.getFieldVisibility());
assertEquals(Visibility.DEFAULT, v.getGetterVisibility());
assertEquals(Visibility.DEFAULT, v.getIsGetterVisibility());
assertEquals(Visibility.DEFAULT, v.getSetterVisibility());
assertEquals(Visibility.DEFAULT, v.getCreatorVisibility());
assertEquals(Visibility.DEFAULT, v.getScalarConstructorVisibility());
JsonAutoDetect.Value all = JsonAutoDetect.Value.construct(PropertyAccessor.ALL,
Visibility.NONE);
assertEquals(Visibility.NONE, all.getFieldVisibility());
assertEquals(Visibility.NONE, all.getGetterVisibility());
assertEquals(Visibility.NONE, all.getIsGetterVisibility());
assertEquals(Visibility.NONE, all.getSetterVisibility());
assertEquals(Visibility.NONE, all.getCreatorVisibility());
assertEquals(Visibility.NONE, all.getScalarConstructorVisibility());
}
示例3: testSimpleChanges
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
public void testSimpleChanges() {
assertSame(NO_OVERRIDES, NO_OVERRIDES.withFieldVisibility(Visibility.DEFAULT));
JsonAutoDetect.Value v = NO_OVERRIDES.withCreatorVisibility(Visibility.PUBLIC_ONLY);
assertNotSame(NO_OVERRIDES, v);
assertEquals(Visibility.PUBLIC_ONLY, v.getCreatorVisibility());
v = NO_OVERRIDES.withFieldVisibility(Visibility.ANY);
assertEquals(Visibility.ANY, v.getFieldVisibility());
v = NO_OVERRIDES.withGetterVisibility(Visibility.NON_PRIVATE);
assertEquals(Visibility.NON_PRIVATE, v.getGetterVisibility());
v = NO_OVERRIDES.withIsGetterVisibility(Visibility.PROTECTED_AND_PUBLIC);
assertEquals(Visibility.PROTECTED_AND_PUBLIC, v.getIsGetterVisibility());
v = NO_OVERRIDES.withSetterVisibility(Visibility.PUBLIC_ONLY);
assertEquals(Visibility.PUBLIC_ONLY, v.getSetterVisibility());
v = NO_OVERRIDES.withScalarConstructorVisibility(Visibility.PUBLIC_ONLY);
assertEquals(Visibility.PUBLIC_ONLY, v.getScalarConstructorVisibility());
}
示例4: DebugPanel
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
public DebugPanel(Worlds worlds) {
mapper.setVisibility(mapper.getSerializationConfig()
.getDefaultVisibilityChecker()
.withFieldVisibility(Visibility.ANY));
this.worlds = worlds;
worlds.addPropertyChangeListener(e -> {
SwingUtilities.invokeLater(this::update);
});
this.setSize(Toolkit.getDefaultToolkit().getScreenSize());
JScrollPane scroller = new JScrollPane(label,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
this.setLayout(new BorderLayout());
this.add(scroller, BorderLayout.CENTER);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
update();
}
示例5: readJsonManifest
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
/**
* Reads a JSON manifest file into a JSON manifest object.
*
* @param jsonManifestFile the JSON manifest file.
*
* @return the manifest object.
* @throws java.io.IOException if any errors were encountered reading the JSON file.
* @throws IllegalArgumentException if the manifest file has validation errors.
*/
public M readJsonManifest(File jsonManifestFile) throws IOException, IllegalArgumentException
{
// Verify that the file exists and can be read.
HerdFileUtils.verifyFileExistsAndReadable(jsonManifestFile);
// Deserialize the JSON manifest.
BufferedInputStream buffer = new BufferedInputStream(new FileInputStream(jsonManifestFile));
BufferedReader reader = new BufferedReader(new InputStreamReader(buffer, Charsets.UTF_8));
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
objectMapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
objectMapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
M manifest = getManifestFromReader(reader, objectMapper);
// Validate the manifest and return it.
validateManifest(manifest);
return manifest;
}
示例6: JsonIO
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
public JsonIO() {
JsonFactory jsonFactory = new JsonFactory();
// All field names will be intern()ed
jsonFactory.enable(JsonFactory.Feature.CANONICALIZE_FIELD_NAMES);
jsonFactory.enable(JsonFactory.Feature.INTERN_FIELD_NAMES);
jsonFactory.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
objectMapper = new ObjectMapper(jsonFactory);
// Use setters and getters to be able use String.intern(). This reduces the amount of memory needed to load a State file.
objectMapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE);
objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.NONE);
objectMapper.setVisibility(PropertyAccessor.CREATOR, Visibility.NONE);
objectMapper.setVisibility(PropertyAccessor.GETTER, Visibility.ANY);
objectMapper.setVisibility(PropertyAccessor.SETTER, Visibility.ANY);
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.setSerializationInclusion(Include.NON_NULL);
JsonPrettyPrinter prettyPrinter = new JsonPrettyPrinter();
objectWriter = objectMapper.writer(prettyPrinter);
}
示例7: getObjectMapper
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
/***
* 初始化ObjectMapper
*
* @return ObjectMapper
*/
public static ObjectMapper getObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper().setVisibility(PropertyAccessor.FIELD,
Visibility.ANY);
// 去除不存在的屬性
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// 空字符串轉換null對象
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
// 去除值為null的值
objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);
// 默認時間戳改成自定義日期格式
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
DateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
objectMapper.setDateFormat(dFormat);
return objectMapper;
}
示例8: getObjectMapperWithNull
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
/***
* 保留空值的ObjectMapper
*
* @return ObjectMapper
*/
public static ObjectMapper getObjectMapperWithNull() {
ObjectMapper objectMapper = new ObjectMapper().setVisibility(PropertyAccessor.FIELD,
Visibility.ANY);
objectMapper.setSerializationInclusion(Include.ALWAYS);
// 去除不存在的屬性
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
// 空字符串轉換null對象
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
// 不去除值為null的值
objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, true);
// 默認時間戳改成自定義日期格式
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
DateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
objectMapper.setDateFormat(dFormat);
return objectMapper;
}
示例9: Std
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
public Std(JsonAutoDetect.Visibility paramVisibility)
{
if (paramVisibility == JsonAutoDetect.Visibility.DEFAULT)
{
this._getterMinLevel = DEFAULT._getterMinLevel;
this._isGetterMinLevel = DEFAULT._isGetterMinLevel;
this._setterMinLevel = DEFAULT._setterMinLevel;
this._creatorMinLevel = DEFAULT._creatorMinLevel;
this._fieldMinLevel = DEFAULT._fieldMinLevel;
return;
}
this._getterMinLevel = paramVisibility;
this._isGetterMinLevel = paramVisibility;
this._setterMinLevel = paramVisibility;
this._creatorMinLevel = paramVisibility;
this._fieldMinLevel = paramVisibility;
}
示例10: withVisibility
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
public Std withVisibility(PropertyAccessor paramPropertyAccessor, JsonAutoDetect.Visibility paramVisibility)
{
switch (VisibilityChecker.1.$SwitchMap$com$fasterxml$jackson$annotation$PropertyAccessor[paramPropertyAccessor.ordinal()])
{
default:
return this;
case 1:
return withGetterVisibility(paramVisibility);
case 2:
return withSetterVisibility(paramVisibility);
case 3:
return withCreatorVisibility(paramVisibility);
case 4:
return withFieldVisibility(paramVisibility);
case 5:
return withIsGetterVisibility(paramVisibility);
case 6:
}
return with(paramVisibility);
}
示例11: doGoodMapper
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
private static void doGoodMapper(ArrayList<AnInterface> childs)
throws JsonProcessingException {
ObjectMapper theGoodMapper = new ObjectMapper();
theGoodMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
theGoodMapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
theGoodMapper.setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE);
theGoodMapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
theGoodMapper.setVisibility(PropertyAccessor.CREATOR, Visibility.NONE);
theGoodMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
String theJsonText = theGoodMapper.writeValueAsString(childs);
System.out.println(theJsonText);
try {
ArrayList<AnInterface> reconstructedChilds = theGoodMapper.readValue(
theJsonText, new TypeReference<ArrayList<AnInterface>>() {
});
System.out.println("The good mapper works ! ");
System.out.println(reconstructedChilds);
} catch (IOException e) {
System.err.println("Bad mapper fails " + e.getMessage());
}
}
示例12: doBadMapper
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
private static void doBadMapper(ArrayList<AnInterface> childs)
throws JsonProcessingException {
ObjectMapper theBadMapper = new ObjectMapper();
theBadMapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
theBadMapper.setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE);
theBadMapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
theBadMapper.setVisibility(PropertyAccessor.CREATOR, Visibility.NONE);
theBadMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
String theJsonText = theBadMapper.writeValueAsString(childs);
System.out.println(theJsonText);
try {
ArrayList<AnInterface> reconstructedChilds = theBadMapper.readValue(
theJsonText, new TypeReference<ArrayList<AnInterface>>() {
});
System.out.println(reconstructedChilds);
} catch (IOException e) {
System.err.println("Bad mapper fails " + e.getMessage());
}
}
示例13: isSetterAutoDetected
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
private static boolean isSetterAutoDetected( RebindConfiguration configuration, PropertyAccessors propertyAccessors, BeanInfo info ) {
if ( !propertyAccessors.getSetter().isPresent() ) {
return false;
}
for ( Class<? extends Annotation> annotation : AUTO_DISCOVERY_ANNOTATIONS ) {
if ( propertyAccessors.isAnnotationPresentOnSetter( annotation ) ) {
return true;
}
}
JMethod setter = propertyAccessors.getSetter().get();
String methodName = setter.getName();
if ( !methodName.startsWith( "set" ) || methodName.length() <= 3 ) {
// no annotation on method and the method does not follow naming convention
return false;
}
JsonAutoDetect.Visibility visibility = info.getSetterVisibility();
if ( Visibility.DEFAULT == visibility ) {
visibility = configuration.getDefaultSetterVisibility();
}
return isAutoDetected( visibility, setter.isPrivate(), setter.isProtected(), setter.isPublic(), setter
.isDefaultAccess() );
}
示例14: isFieldAutoDetected
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
private static boolean isFieldAutoDetected( RebindConfiguration configuration, PropertyAccessors propertyAccessors, BeanInfo info ) {
if ( !propertyAccessors.getField().isPresent() ) {
return false;
}
for ( Class<? extends Annotation> annotation : AUTO_DISCOVERY_ANNOTATIONS ) {
if ( propertyAccessors.isAnnotationPresentOnField( annotation ) ) {
return true;
}
}
JField field = propertyAccessors.getField().get();
JsonAutoDetect.Visibility visibility = info.getFieldVisibility();
if ( Visibility.DEFAULT == visibility ) {
visibility = configuration.getDefaultFieldVisibility();
}
return isAutoDetected( visibility, field.isPrivate(), field.isProtected(), field.isPublic(), field
.isDefaultAccess() );
}
示例15: isAutoDetected
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; //導入依賴的package包/類
private static boolean isAutoDetected( JsonAutoDetect.Visibility visibility, boolean isPrivate, boolean isProtected, boolean
isPublic, boolean isDefaultAccess ) {
switch ( visibility ) {
case ANY:
return true;
case NONE:
return false;
case NON_PRIVATE:
return !isPrivate;
case PROTECTED_AND_PUBLIC:
return isProtected || isPublic;
case PUBLIC_ONLY:
case DEFAULT:
return isPublic;
default:
return false;
}
}