Java Code Examples for com.fasterxml.jackson.annotation.JsonProperty#Access

The following examples show how to use com.fasterxml.jackson.annotation.JsonProperty#Access . 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: FieldDocumentationGenerator.java    From spring-auto-restdocs with Apache License 2.0 6 votes vote down vote up
public FieldDocumentationGenerator(
        ObjectWriter writer,
        DeserializationConfig deserializationConfig,
        JavadocReader javadocReader,
        ConstraintReader constraintReader,
        TypeMapping typeMapping,
        SnippetTranslationResolver translationResolver,
        JsonProperty.Access skipAccessor
) {
    this.writer = writer;
    this.deserializationConfig = deserializationConfig;
    this.javadocReader = javadocReader;
    this.constraintReader = constraintReader;
    this.typeMapping = typeMapping;
    this.translationResolver = translationResolver;
    this.skipAccessor = skipAccessor;
}
 
Example 2
Source File: FieldDocumentationObjectVisitor.java    From spring-auto-restdocs with Apache License 2.0 6 votes vote down vote up
public FieldDocumentationObjectVisitor(
        SerializerProvider provider,
        FieldDocumentationVisitorContext context,
        String path,
        TypeRegistry typeRegistry,
        TypeFactory typeFactory,
        JsonProperty.Access skipAccessor

) {
    super(provider);
    this.context = context;
    this.path = path;
    this.typeRegistry = typeRegistry;
    this.typeFactory = typeFactory;
    this.skipAccessor = skipAccessor;
}
 
Example 3
Source File: IgnoreJacksonWriteOnlyAccess.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public JsonProperty.Access findPropertyAccess(Annotated m) {
    JsonProperty.Access access = super.findPropertyAccess(m);
    if (access == JsonProperty.Access.WRITE_ONLY) {
        return JsonProperty.Access.AUTO;
    }
    return access;
}
 
Example 4
Source File: JacksonResourceFieldInformationProvider.java    From crnk-framework with Apache License 2.0 5 votes vote down vote up
private Optional<Boolean> isAccessible(BeanAttributeInformation attributeDesc, JsonProperty.Access accessable) {
	Optional<JsonProperty> annotation = attributeDesc.getAnnotation(JsonProperty.class);
	if (annotation.isPresent()) {
		JsonProperty.Access access = annotation.get().access();
		if (access == JsonProperty.Access.READ_WRITE) {
			return Optional.of(true);
		}
		if (access == accessable) {
			return Optional.of(false);
		}
	}
	return Optional.empty();
}
 
Example 5
Source File: AbstractJacksonFieldSnippet.java    From spring-auto-restdocs with Apache License 2.0 5 votes vote down vote up
protected FieldDescriptors createFieldDescriptors(Operation operation,
        HandlerMethod handlerMethod) {
    ObjectMapper objectMapper = getObjectMapper(operation);

    JavadocReader javadocReader = getJavadocReader(operation);
    ConstraintReader constraintReader = getConstraintReader(operation);
    SnippetTranslationResolver translationResolver = getTranslationResolver(operation);
    TypeMapping typeMapping = getTypeMapping(operation);
    JsonProperty.Access skipAcessor = getSkipAcessor();

    Type type = getType(handlerMethod);
    if (type == null) {
        return new FieldDescriptors();
    }

    try {
        FieldDocumentationGenerator generator = new FieldDocumentationGenerator(
                objectMapper.writer(), objectMapper.getDeserializationConfig(), javadocReader,
                constraintReader, typeMapping, translationResolver, skipAcessor);
        FieldDescriptors fieldDescriptors = generator.generateDocumentation(type, objectMapper.getTypeFactory());

        if (shouldFailOnUndocumentedFields()) {
            assertAllDocumented(fieldDescriptors.values(),
                    translationResolver.translate(getHeaderKey(operation)).toLowerCase());
        }
        return fieldDescriptors;
    } catch (JsonMappingException e) {
        throw new JacksonFieldProcessingException("Error while parsing fields", e);
    }
}
 
Example 6
Source File: FieldDocumentationArrayVisitor.java    From spring-auto-restdocs with Apache License 2.0 5 votes vote down vote up
public FieldDocumentationArrayVisitor(SerializerProvider provider,
        FieldDocumentationVisitorContext context, String path, TypeRegistry typeRegistry,
        TypeFactory typeFactory, JsonProperty.Access skipAccessor) {
    super(provider);
    this.context = context;
    this.path = path;
    this.typeRegistry = typeRegistry;
    this.typeFactory = typeFactory;
    this.skipAccessor = skipAccessor;
}
 
Example 7
Source File: FieldDocumentationVisitorWrapper.java    From spring-auto-restdocs with Apache License 2.0 5 votes vote down vote up
public static FieldDocumentationVisitorWrapper create(JavadocReader javadocReader,
        ConstraintReader constraintReader, DeserializationConfig deserializationConfig,
        TypeRegistry typeRegistry, TypeFactory typeFactory, SnippetTranslationResolver translationResolver,
        JsonProperty.Access skipAccessor) {
    FieldDocumentationVisitorContext context = new FieldDocumentationVisitorContext(
            javadocReader, constraintReader, deserializationConfig, translationResolver);
    return new FieldDocumentationVisitorWrapper(context, "", null, typeRegistry, typeFactory, skipAccessor);
}
 
Example 8
Source File: FieldDocumentationVisitorWrapper.java    From spring-auto-restdocs with Apache License 2.0 5 votes vote down vote up
FieldDocumentationVisitorWrapper(SerializerProvider provider,
        FieldDocumentationVisitorContext context, String path, InternalFieldInfo fieldInfo,
        TypeRegistry typeRegistry, TypeFactory typeFactory, JsonProperty.Access skipAccessor) {
    this.provider = provider;
    this.context = context;
    this.path = path;
    this.fieldInfo = fieldInfo;
    this.typeRegistry = typeRegistry;
    this.typeFactory = typeFactory;
    this.skipAccessor = skipAccessor;
}
 
Example 9
Source File: POJOPropertyBuilder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public JsonProperty.Access findAccess() {
    return fromMemberAnnotationsExcept(new WithMember<JsonProperty.Access>() {
        @Override
        public JsonProperty.Access withMember(AnnotatedMember member) {
            return _annotationIntrospector.findPropertyAccess(member);
        }
    }, JsonProperty.Access.AUTO);
}
 
Example 10
Source File: AnnotationIntrospectorPair.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JsonProperty.Access findPropertyAccess(Annotated ann) {
    JsonProperty.Access acc = _primary.findPropertyAccess(ann);
    if ((acc != null) && (acc != JsonProperty.Access.AUTO)) {
        return acc;
    }
    acc = _secondary.findPropertyAccess(ann);
    if (acc != null) {
        return acc;
    }
    return JsonProperty.Access.AUTO;
}
 
Example 11
Source File: POJOPropertiesCollector.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Method called to further get rid of unwanted individual accessors,
 * based on read/write settings and rules for "pulling in" accessors
 * (or not).
 */
protected void _removeUnwantedAccessor(Map<String, POJOPropertyBuilder> props)
{
    final boolean inferMutators = _config.isEnabled(MapperFeature.INFER_PROPERTY_MUTATORS);
    Iterator<POJOPropertyBuilder> it = props.values().iterator();

    while (it.hasNext()) {
        POJOPropertyBuilder prop = it.next();
        // 26-Jan-2017, tatu: [databind#935]: need to denote removal of
        JsonProperty.Access acc = prop.removeNonVisible(inferMutators);
        if (acc == JsonProperty.Access.READ_ONLY) {
            _collectIgnorals(prop.getName());
        }
    }
}
 
Example 12
Source File: FieldDocumentationVisitorWrapper.java    From spring-auto-restdocs with Apache License 2.0 4 votes vote down vote up
FieldDocumentationVisitorWrapper(FieldDocumentationVisitorContext context, String path,
        InternalFieldInfo fieldInfo, TypeRegistry typeRegistry, TypeFactory typeFactory,
        JsonProperty.Access skipAccessor) {
    this(null, context, path, fieldInfo, typeRegistry, typeFactory, skipAccessor);
}
 
Example 13
Source File: POJOPropertyBuilder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param inferMutators Whether mutators can be "pulled in" by visible
 *    accessors or not. 
 */
public JsonProperty.Access removeNonVisible(boolean inferMutators)
{
    /* 07-Jun-2015, tatu: With 2.6, we will allow optional definition
     *  of explicit access type for property; if not "AUTO", it will
     *  dictate how visibility checks are applied.
     */
    JsonProperty.Access acc = findAccess();
    if (acc == null) {
        acc = JsonProperty.Access.AUTO;
    }
    switch (acc) {
    case READ_ONLY:
        // Remove setters, creators for sure, but fields too if deserializing
        _setters = null;
        _ctorParameters = null;
        if (!_forSerialization) {
            _fields = null;
        }
        break;
    case READ_WRITE:
        // no trimming whatsoever?
        break;
    case WRITE_ONLY:
        // remove getters, definitely, but also fields if serializing
        _getters = null;
        if (_forSerialization) {
            _fields = null;
        }
        break;
    default:
    case AUTO: // the default case: base it on visibility
        _getters = _removeNonVisible(_getters);
        _ctorParameters = _removeNonVisible(_ctorParameters);

        if (!inferMutators || (_getters == null)) {
            _fields = _removeNonVisible(_fields);
            _setters = _removeNonVisible(_setters);
        }
    }
    return acc;
}
 
Example 14
Source File: AbstractJacksonFieldSnippet.java    From spring-auto-restdocs with Apache License 2.0 4 votes vote down vote up
protected JsonProperty.Access getSkipAcessor() {
    return null;
}
 
Example 15
Source File: JacksonResponseFieldSnippet.java    From spring-auto-restdocs with Apache License 2.0 4 votes vote down vote up
@Override
protected JsonProperty.Access getSkipAcessor() {
    return JsonProperty.Access.WRITE_ONLY;
}
 
Example 16
Source File: JacksonModelAttributeSnippet.java    From spring-auto-restdocs with Apache License 2.0 4 votes vote down vote up
@Override
protected JsonProperty.Access getSkipAcessor() {
    return JsonProperty.Access.READ_ONLY;
}
 
Example 17
Source File: JacksonRequestFieldSnippet.java    From spring-auto-restdocs with Apache License 2.0 4 votes vote down vote up
@Override
protected JsonProperty.Access getSkipAcessor() {
    return JsonProperty.Access.READ_ONLY;
}