com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility Java Examples

The following examples show how to use com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataBridgeManifestReader.java    From herd with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: JsonJacksonCodec.java    From redisson with Apache License 2.0 6 votes vote down vote up
protected void init(ObjectMapper objectMapper) {
    objectMapper.setSerializationInclusion(Include.NON_NULL);
    objectMapper.setVisibility(objectMapper.getSerializationConfig()
                                                .getDefaultVisibilityChecker()
                                                    .withFieldVisibility(JsonAutoDetect.Visibility.ANY)
                                                    .withGetterVisibility(JsonAutoDetect.Visibility.NONE)
                                                    .withSetterVisibility(JsonAutoDetect.Visibility.NONE)
                                                    .withCreatorVisibility(JsonAutoDetect.Visibility.NONE));
    objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    objectMapper.enable(Feature.WRITE_BIGDECIMAL_AS_PLAIN);
    objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
    objectMapper.addMixIn(Throwable.class, ThrowableMixIn.class);
}
 
Example #3
Source File: JackonPolymorphicMain.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 6 votes vote down vote up
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());
   }
}
 
Example #4
Source File: JackonPolymorphicMain.java    From chuidiang-ejemplos with GNU Lesser General Public License v3.0 6 votes vote down vote up
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());
   }
}
 
Example #5
Source File: MapperConfigBase.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final VisibilityChecker<?> getDefaultVisibilityChecker()
{
    VisibilityChecker<?> vchecker = _configOverrides.getDefaultVisibility();
    // then global overrides (disabling)
    // 05-Mar-2018, tatu: As per [databind#1947], need to see if any disabled
    if ((_mapperFeatures & AUTO_DETECT_MASK) != AUTO_DETECT_MASK) {
        if (!isEnabled(MapperFeature.AUTO_DETECT_FIELDS)) {
            vchecker = vchecker.withFieldVisibility(Visibility.NONE);
        }
        if (!isEnabled(MapperFeature.AUTO_DETECT_GETTERS)) {
            vchecker = vchecker.withGetterVisibility(Visibility.NONE);
        }
        if (!isEnabled(MapperFeature.AUTO_DETECT_IS_GETTERS)) {
            vchecker = vchecker.withIsGetterVisibility(Visibility.NONE);
        }
        if (!isEnabled(MapperFeature.AUTO_DETECT_SETTERS)) {
            vchecker = vchecker.withSetterVisibility(Visibility.NONE);
        }
        if (!isEnabled(MapperFeature.AUTO_DETECT_CREATORS)) {
            vchecker = vchecker.withCreatorVisibility(Visibility.NONE);
        }
    }
    return vchecker;
}
 
Example #6
Source File: VisibilityChecker.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Std withVisibility(PropertyAccessor method, Visibility v)
{
    switch (method) {
    case GETTER:
        return withGetterVisibility(v);
    case SETTER:
        return withSetterVisibility(v);
    case CREATOR:
        return withCreatorVisibility(v);
    case FIELD:
        return withFieldVisibility(v);
    case IS_GETTER:
        return withIsGetterVisibility(v);
    case ALL:
        return with(v);
    //case NONE:
    default:
        // break;
        return this;
    }
}
 
Example #7
Source File: JsonMapper.java    From onetwo with Apache License 2.0 6 votes vote down vote up
public JsonMapper(ObjectMapper objectMapper, Include include, boolean fieldVisibility){
		objectMapper.setSerializationInclusion(include);
//		objectMapper.configure(SerializationConfig.Feature.WRITE_DATES_AS_TIMESTAMPS, false);
//		setDateFormat(DateUtils.DATE_TIME);
		objectMapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
		objectMapper.configure(Feature.ALLOW_COMMENTS, true);
//		objectMapper.configure(Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
		objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
		objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		if(fieldVisibility)
			objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
		objectMapper.setFilterProvider(filterProvider);
//		objectMapper.addMixIn(target, mixinSource);
		this.objectMapper = objectMapper;
		this.typeFactory = this.objectMapper.getTypeFactory();
	}
 
Example #8
Source File: RedisConfigure.java    From cms with Apache License 2.0 6 votes vote down vote up
/**
 * json序列化
 *
 * @return
 */
@Bean
public RedisSerializer<Object> jackson2JsonRedisSerializer() {
    //使用Jackson2JsonRedisSerializer来序列化和反序列化redis的value值(默认使用JDK的序列化方式)
    Jackson2JsonRedisSerializer<Object> serializer = new Jackson2JsonRedisSerializer(Object.class);

    ObjectMapper objectMapper = new ObjectMapper();
    // 指定要序列化的域,field,get和set,以及修饰符范围,ANY是都有包括private和public
    objectMapper.setVisibility(PropertyAccessor.ALL, Visibility.ANY);
    // 指定序列化输入的类型,类必须是非final修饰的,final修饰的类,比如String,Integer等会跑出异常
    //objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.NON_FINAL, As.WRAPPER_ARRAY);

    serializer.setObjectMapper(objectMapper);
    return serializer;
}
 
Example #9
Source File: VisibilityChecker.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor that will assign given visibility value for all
 * properties.
 * 
 * @param v level to use for all property types
 */
public Std(Visibility v)
{
    // typically we shouldn't get this value; but let's handle it if we do:
    if (v == Visibility.DEFAULT) {
        _getterMinLevel = DEFAULT._getterMinLevel;
        _isGetterMinLevel = DEFAULT._isGetterMinLevel;
        _setterMinLevel = DEFAULT._setterMinLevel;
        _creatorMinLevel = DEFAULT._creatorMinLevel;
        _fieldMinLevel = DEFAULT._fieldMinLevel;
    } else {
        _getterMinLevel = v;
        _isGetterMinLevel = v;
        _setterMinLevel = v;
        _creatorMinLevel = v;
        _fieldMinLevel = v;
    }
}
 
Example #10
Source File: PropertyProcessor.java    From gwt-jackson with Apache License 2.0 6 votes vote down vote up
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() );
}
 
Example #11
Source File: PropertyProcessor.java    From gwt-jackson with Apache License 2.0 6 votes vote down vote up
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() );
}
 
Example #12
Source File: PropertyProcessor.java    From gwt-jackson with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example #13
Source File: TestJaxbAutoDetect.java    From jackson-modules-base with Apache License 2.0 6 votes vote down vote up
public void testAutoDetectDisable() throws IOException
{
    ObjectMapper mapper = getJaxbMapper();
    Jackson183Bean bean = new Jackson183Bean();
    Map<String,Object> result;

    // Ok: by default, should see 2 fields:
    result = writeAndMap(mapper, bean);
    assertEquals(2, result.size());
    assertEquals("a", result.get("a"));
    assertEquals("b", result.get("b"));

    // But when disabling auto-detection, just one
    mapper = getJaxbMapperBuilder()
            .changeDefaultVisibility(vc -> vc.withVisibility(PropertyAccessor.GETTER, Visibility.NONE))
            .build();
    result = writeAndMap(mapper, bean);
    assertEquals(1, result.size());
    assertNull(result.get("a"));
    assertEquals("b", result.get("b"));
}
 
Example #14
Source File: FieldObjectMapper.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public FieldObjectMapper() {
  // only pay attention to fields
  setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
  setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
  setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
  setVisibility(PropertyAccessor.CREATOR, Visibility.NONE);
  setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE);

  // ignore unknown fields when reading
  configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

  // ignore null fields when writing
  setSerializationInclusion(JsonInclude.Include.NON_NULL);
}
 
Example #15
Source File: HbaseJsonEventSerializer.java    From searchanalytics-bigdata with MIT License 5 votes vote down vote up
private ObjectMapper getObjectMapper() throws JsonProcessingException {
	final ObjectMapper mapper = new ObjectMapper();
	// try without pretty print..all data in single line
	return mapper
			.setPropertyNamingStrategy(
					new SearchFieldsLowerCaseNameStrategy())
			.setVisibility(PropertyAccessor.FIELD, Visibility.ANY)
			// .setPropertyNamingStrategy(
			// new SearchPropertyNameCaseInsensitiveNameStrategy())
			.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
}
 
Example #16
Source File: CloudConvertMapperProvider.java    From cloudconvert with GNU General Public License v3.0 5 votes vote down vote up
public ObjectMapper getContext(Class<?> cls) {
    ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    
    mapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.SETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    mapper.setVisibility(PropertyAccessor.CREATOR, Visibility.ANY);
    
    mapper.registerModule(new UriSchemeModule());
    
    return mapper;
}
 
Example #17
Source File: StyleConfiguration.java    From depgraph-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static ObjectMapper createObjectMapper() {
  SimpleModule module = new SimpleModule()
      .addKeySerializer(NodeResolution.class, new NodeResolutionSerializer())
      .addDeserializer(NodeResolution.class, new NodeResolutionDeserializer());

  return new ObjectMapper()
      .registerModule(module)
      .setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE)
      .setSerializationInclusion(Include.NON_EMPTY)
      .setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
}
 
Example #18
Source File: JsonCodec.java    From x-pipe with Apache License 2.0 5 votes vote down vote up
public JsonCodec(boolean indent, boolean privateVisible){

		objectMapper = new ObjectMapper();
		objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
		objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		
		if(indent){
			objectMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
		}
		if(privateVisible){
			objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
			objectMapper.setVisibility(PropertyAccessor.GETTER, Visibility.NONE);
			objectMapper.setVisibility(PropertyAccessor.IS_GETTER, Visibility.NONE);
		}
	}
 
Example #19
Source File: VisibilityChecker.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
protected Std _with(Visibility g, Visibility isG, Visibility s,
        Visibility cr, Visibility f) {
    if ((g == _getterMinLevel)
            && (isG == _isGetterMinLevel)
            && (s == _setterMinLevel)
            && (cr == _creatorMinLevel)
            && (f == _fieldMinLevel)
            ) {
        return this;
    }
    return new Std(g, isG, s, cr, f);
}
 
Example #20
Source File: Message.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
public String writeValueAsString(Object obj) {
    ObjectMapper json = new ObjectMapper();
    json.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    try {
        return json.writeValueAsString(obj);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example #21
Source File: GenerateSearchAnalyticsDataImpl.java    From searchanalytics-bigdata with MIT License 5 votes vote down vote up
public ObjectMapper getObjectMapper() throws JsonProcessingException {
	final ObjectMapper mapper = new ObjectMapper();
	// try without pretty print..all data in single line
	return mapper
			.setPropertyNamingStrategy(
					new SearchFieldsLowerCaseNameStrategy())
			.setVisibility(PropertyAccessor.FIELD, Visibility.ANY)
			.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
}
 
Example #22
Source File: JacksonProvider.java    From minnal with Apache License 2.0 5 votes vote down vote up
/**
 * @param mapper
 * @param annotationsToUse
 */
public JacksonProvider(ObjectMapper mapper, Annotations[] annotationsToUse) {
    super(mapper, annotationsToUse);
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.NONE);
    mapper.setVisibility(PropertyAccessor.GETTER, Visibility.PROTECTED_AND_PUBLIC);
    mapper.setVisibility(PropertyAccessor.SETTER, Visibility.PROTECTED_AND_PUBLIC);
    mapper.configure(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS, true);
    mapper.setPropertyNamingStrategy(getPropertyNamingStrategy());
}
 
Example #23
Source File: JacksonProvider.java    From minnal with Apache License 2.0 5 votes vote down vote up
/**
 * @param mapper
 * @param annotationsToUse
 */
public JacksonProvider(ObjectMapper mapper, Annotations[] annotationsToUse) {
	super(mapper, annotationsToUse);
	mapper.setVisibility(PropertyAccessor.FIELD, Visibility.NONE);
	mapper.setVisibility(PropertyAccessor.GETTER, Visibility.PROTECTED_AND_PUBLIC);
	mapper.setVisibility(PropertyAccessor.SETTER, Visibility.PROTECTED_AND_PUBLIC);
	mapper.configure(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS, true);
	mapper.setPropertyNamingStrategy(getPropertyNamingStrategy());
}
 
Example #24
Source File: AbstractJacksonSerializer.java    From minnal with Apache License 2.0 5 votes vote down vote up
protected void init() {
	mapper.addMixInAnnotations(Object.class, PropertyFilterMixIn.class);
	mapper.setVisibility(PropertyAccessor.FIELD, Visibility.NONE);
	mapper.setVisibility(PropertyAccessor.GETTER, Visibility.PROTECTED_AND_PUBLIC);
	mapper.setVisibility(PropertyAccessor.SETTER, Visibility.PROTECTED_AND_PUBLIC);
	registerModules(mapper);
	mapper.configure(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS, true);
	mapper.setPropertyNamingStrategy(getPropertyNamingStrategy());
	SimpleFilterProvider provider = new SimpleFilterProvider();
	provider.addFilter("property_filter", SimpleBeanPropertyFilter.serializeAllExcept(Sets.<String>newHashSet()));
	mapper.setFilters(provider);
}
 
Example #25
Source File: JacksonFieldUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public final void givenDifferentAccessLevels_whenSetVisibility_thenSerializable() throws IOException {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);

    final MyDtoAccessLevel dtoObject = new MyDtoAccessLevel();

    final String dtoAsString = mapper.writeValueAsString(dtoObject);
    assertThat(dtoAsString, containsString("stringValue"));
    assertThat(dtoAsString, containsString("intValue"));
    assertThat(dtoAsString, containsString("booleanValue"));
    System.out.println(dtoAsString);
}
 
Example #26
Source File: PropertyProcessor.java    From gwt-jackson with Apache License 2.0 5 votes vote down vote up
private static boolean isGetterAutoDetected( RebindConfiguration configuration, PropertyAccessors propertyAccessors, BeanInfo info ) {
    if ( !propertyAccessors.getGetter().isPresent() ) {
        return false;
    }

    for ( Class<? extends Annotation> annotation : AUTO_DISCOVERY_ANNOTATIONS ) {
        if ( propertyAccessors.isAnnotationPresentOnGetter( annotation ) ) {
            return true;
        }
    }

    JMethod getter = propertyAccessors.getGetter().get();

    String methodName = getter.getName();
    JsonAutoDetect.Visibility visibility;
    if ( methodName.startsWith( "is" ) && methodName.length() > 2 && JPrimitiveType.BOOLEAN.equals( getter.getReturnType()
            .isPrimitive() ) ) {

        // getter method for a boolean
        visibility = info.getIsGetterVisibility();
        if ( Visibility.DEFAULT == visibility ) {
            visibility = configuration.getDefaultIsGetterVisibility();
        }

    } else if ( methodName.startsWith( "get" ) && methodName.length() > 3 ) {

        visibility = info.getGetterVisibility();
        if ( Visibility.DEFAULT == visibility ) {
            visibility = configuration.getDefaultGetterVisibility();
        }

    } else {
        // no annotation on method and the method does not follow naming convention
        return false;
    }
    return isAutoDetected( visibility, getter.isPrivate(), getter.isProtected(), getter.isPublic(), getter.isDefaultAccess() );
}
 
Example #27
Source File: BeanInfo.java    From gwt-jackson with Apache License 2.0 5 votes vote down vote up
BeanInfo( JClassType type, List<JClassType> parameterizedTypes, Optional<JClassType> builder, Optional<JAbstractMethod> creatorMethod, Map<String, JParameter> creatorParameters, boolean creatorDefaultConstructor, boolean creatorDelegation, Optional<BeanTypeInfo> typeInfo, Optional<PropertyInfo> valuePropertyInfo, Optional<PropertyInfo> anyGetterPropertyInfo, Optional<PropertyInfo> anySetterPropertyInfo, Set<String> ignoredFields, Visibility fieldVisibility, Visibility getterVisibility, Visibility isGetterVisibility, Visibility setterVisibility, Visibility creatorVisibility, boolean ignoreUnknown, List<String> propertyOrderList, boolean propertyOrderAlphabetic, Optional<BeanIdentityInfo> identityInfo, Optional<Include> include ) {

        this.type = type;
        this.parameterizedTypes = ImmutableList.copyOf( parameterizedTypes );

        this.builder = builder;
        this.creatorMethod = creatorMethod;
        this.creatorParameters = ImmutableMap.copyOf( creatorParameters );
        this.creatorDefaultConstructor = creatorDefaultConstructor;
        this.creatorDelegation = creatorDelegation;
        this.typeInfo = typeInfo;
        this.valuePropertyInfo = valuePropertyInfo;
        this.anyGetterPropertyInfo = anyGetterPropertyInfo;
        this.anySetterPropertyInfo = anySetterPropertyInfo;
        this.ignoredFields = ImmutableSet.copyOf( ignoredFields );

        this.fieldVisibility = fieldVisibility;
        this.getterVisibility = getterVisibility;
        this.isGetterVisibility = isGetterVisibility;
        this.setterVisibility = setterVisibility;
        this.creatorVisibility = creatorVisibility;

        this.ignoreUnknown = ignoreUnknown;
        this.propertyOrderList = ImmutableList.copyOf( propertyOrderList );
        this.propertyOrderAlphabetic = propertyOrderAlphabetic;
        this.identityInfo = identityInfo;
        this.include = include;
    }
 
Example #28
Source File: TestConfiguration.java    From gwt-jackson with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    // mixin tests
    addMixInAnnotations( EmptyBean.class, MixInForSimple.class );

    // object tests
    whitelist( "com.github.nmorel.gwtjackson.shared.advanced.ObjectTester.InnerObject" );
    whitelist( "com.github.nmorel.gwtjackson.shared.advanced.ObjectTester.Person" );

    // visibility
    setterVisibility( Visibility.PUBLIC_ONLY ).creatorVisibility( Visibility.ANY );
}
 
Example #29
Source File: JacksonExceptionsUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenClassWithPrivateFields_whenConfigureSerializing_thenCorrect() throws IOException {
    final UserWithPrivateFields user = new UserWithPrivateFields(1, "John");

    final ObjectMapper mapper = new ObjectMapper();
    mapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);

    final String result = mapper.writer()
        .writeValueAsString(user);
    assertThat(result, containsString("John"));
}
 
Example #30
Source File: JacksonMappingExceptionUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public final void givenObjectHasNoAccessors_whenSerializingWithPrivateFieldsVisibility_thenNoException() throws JsonParseException, IOException {
    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
    final String dtoAsString = objectMapper.writeValueAsString(new MyDtoNoAccessors());

    assertThat(dtoAsString, containsString("intValue"));
    assertThat(dtoAsString, containsString("stringValue"));
    assertThat(dtoAsString, containsString("booleanValue"));
}