当前位置: 首页>>代码示例>>Java>>正文


Java Visibility类代码示例

本文整理汇总了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));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:AdditionalPropertiesIT.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:VisibilityTest.java

示例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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:VisibilityTest.java

示例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();
}
 
开发者ID:nrodrigues,项目名称:pchud,代码行数:24,代码来源:DebugPanel.java

示例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;
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:28,代码来源:DataBridgeManifestReader.java

示例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);
}
 
开发者ID:evrignaud,项目名称:fim,代码行数:23,代码来源:JsonIO.java

示例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;
}
 
开发者ID:geosmart,项目名称:me.demo.hadoop,代码行数:21,代码来源:JsonUtil.java

示例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;
}
 
开发者ID:geosmart,项目名称:me.demo.hadoop,代码行数:22,代码来源:JsonUtil.java

示例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;
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:18,代码来源:VisibilityChecker.java

示例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);
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:21,代码来源:VisibilityChecker.java

示例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());
   }
}
 
开发者ID:chuidiang,项目名称:chuidiang-ejemplos,代码行数:23,代码来源:JackonPolymorphicMain.java

示例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());
   }
}
 
开发者ID:chuidiang,项目名称:chuidiang-ejemplos,代码行数:20,代码来源:JackonPolymorphicMain.java

示例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() );
}
 
开发者ID:nmorel,项目名称:gwt-jackson,代码行数:27,代码来源:PropertyProcessor.java

示例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() );
}
 
开发者ID:nmorel,项目名称:gwt-jackson,代码行数:21,代码来源:PropertyProcessor.java

示例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;
    }
}
 
开发者ID:nmorel,项目名称:gwt-jackson,代码行数:19,代码来源:PropertyProcessor.java


注:本文中的com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。