Java Code Examples for com.fasterxml.jackson.annotation.JsonAutoDetect#Visibility
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: PropertyProcessor.java From gwt-jackson with Apache License 2.0 | 6 votes |
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 2
Source File: PropertyProcessor.java From gwt-jackson with Apache License 2.0 | 6 votes |
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 3
Source File: PropertyProcessor.java From gwt-jackson with Apache License 2.0 | 6 votes |
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 4
Source File: Jackson2ConfigurationResolved.java From typescript-generator with MIT License | 5 votes |
public void setVisibility( JsonAutoDetect.Visibility fieldVisibility, JsonAutoDetect.Visibility getterVisibility, JsonAutoDetect.Visibility isGetterVisibility, JsonAutoDetect.Visibility setterVisibility, JsonAutoDetect.Visibility creatorVisibility) { this.fieldVisibility = fieldVisibility; this.getterVisibility = getterVisibility; this.isGetterVisibility = isGetterVisibility; this.setterVisibility = setterVisibility; this.creatorVisibility = creatorVisibility; }
Example 5
Source File: PropertyProcessor.java From gwt-jackson with Apache License 2.0 | 5 votes |
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 6
Source File: Jackson2Parser.java From typescript-generator with MIT License | 4 votes |
private void setVisibility(PropertyAccessor accessor, JsonAutoDetect.Visibility visibility) { if (visibility != null) { objectMapper.setVisibility(accessor, visibility); } }
Example 7
Source File: RebindConfiguration.java From gwt-jackson with Apache License 2.0 | 4 votes |
/** * <p>Constructor for RebindConfiguration.</p> * * @param logger a {@link com.google.gwt.core.ext.TreeLogger} object. * @param context a {@link com.google.gwt.core.ext.GeneratorContext} object. * @param typeOracle a {@link com.github.nmorel.gwtjackson.rebind.JacksonTypeOracle} object. * @param rootMapperClass a {@link com.google.gwt.core.ext.typeinfo.JClassType} object. * @throws com.google.gwt.core.ext.UnableToCompleteException if any. */ public RebindConfiguration( TreeLogger logger, GeneratorContext context, JacksonTypeOracle typeOracle, JClassType rootMapperClass ) throws UnableToCompleteException { this.logger = logger; this.context = context; this.typeOracle = typeOracle; this.rootMapperClass = rootMapperClass; this.rootMapperHash = new BigInteger( 1, Md5Utils.getMd5Digest( rootMapperClass.getQualifiedSourceName().getBytes() ) ) .toString( 16 ); List<AbstractConfiguration> configurations = getAllConfigurations(); Builder<JClassType> allSupportedSerializationClassBuilder = ImmutableSet.builder(); Builder<JClassType> allSupportedDeserializationClassBuilder = ImmutableSet.builder(); List<String> whitelist = new ArrayList<String>(); JsonAutoDetect.Visibility fieldVisibility = JsonAutoDetect.Visibility.DEFAULT; JsonAutoDetect.Visibility getterVisibility = JsonAutoDetect.Visibility.DEFAULT; JsonAutoDetect.Visibility isGetterVisibility = JsonAutoDetect.Visibility.DEFAULT; JsonAutoDetect.Visibility setterVisibility = JsonAutoDetect.Visibility.DEFAULT; JsonAutoDetect.Visibility creatorVisibility = JsonAutoDetect.Visibility.DEFAULT; for ( AbstractConfiguration configuration : configurations ) { for ( MapperType mapperType : MapperType.values() ) { addMappers( configuration, mapperType, allSupportedSerializationClassBuilder, allSupportedDeserializationClassBuilder ); } addMixInAnnotations( configuration.getMapMixInAnnotations(), rootMapperClass.getAnnotation( JsonMixIns.class ) ); whitelist.addAll( configuration.getWhitelist() ); fieldVisibility = configuration.getFieldVisibility(); getterVisibility = configuration.getGetterVisibility(); isGetterVisibility = configuration.getIsGetterVisibility(); setterVisibility = configuration.getSetterVisibility(); creatorVisibility = configuration.getCreatorVisibility(); } this.allSupportedSerializationClass = allSupportedSerializationClassBuilder.build(); this.allSupportedDeserializationClass = allSupportedDeserializationClassBuilder.build(); this.additionalSupportedTypes = new TypeFilter( logger, whitelist ); this.defaultFieldVisibility = fieldVisibility; this.defaultGetterVisibility = getterVisibility; this.defaultIsGetterVisibility = isGetterVisibility; this.defaultSetterVisibility = setterVisibility; this.defaultCreatorVisibility = creatorVisibility; }
Example 8
Source File: AbstractConfiguration.java From gwt-jackson with Apache License 2.0 | 2 votes |
/** * Override the default behaviour of {@link JsonAutoDetect.Visibility#DEFAULT} for fields. * * @param visibility the new default behaviour * @return a {@link com.github.nmorel.gwtjackson.client.AbstractConfiguration} object. */ protected AbstractConfiguration fieldVisibility( JsonAutoDetect.Visibility visibility ) { this.fieldVisibility = visibility; return this; }
Example 9
Source File: AbstractConfiguration.java From gwt-jackson with Apache License 2.0 | 2 votes |
/** * Override the default behaviour of {@link JsonAutoDetect.Visibility#DEFAULT} for getters. * * @param visibility the new default behaviour * @return a {@link com.github.nmorel.gwtjackson.client.AbstractConfiguration} object. */ protected AbstractConfiguration getterVisibility( JsonAutoDetect.Visibility visibility ) { this.getterVisibility = visibility; return this; }
Example 10
Source File: AbstractConfiguration.java From gwt-jackson with Apache License 2.0 | 2 votes |
/** * Override the default behaviour of {@link JsonAutoDetect.Visibility#DEFAULT} for boolean getters. * * @param visibility the new default behaviour * @return a {@link com.github.nmorel.gwtjackson.client.AbstractConfiguration} object. */ protected AbstractConfiguration isGetterVisibility( JsonAutoDetect.Visibility visibility ) { this.isGetterVisibility = visibility; return this; }
Example 11
Source File: AbstractConfiguration.java From gwt-jackson with Apache License 2.0 | 2 votes |
/** * Override the default behaviour of {@link JsonAutoDetect.Visibility#DEFAULT} for setters. * * @param visibility the new default behaviour * @return a {@link com.github.nmorel.gwtjackson.client.AbstractConfiguration} object. */ protected AbstractConfiguration setterVisibility( JsonAutoDetect.Visibility visibility ) { this.setterVisibility = visibility; return this; }
Example 12
Source File: AbstractConfiguration.java From gwt-jackson with Apache License 2.0 | 2 votes |
/** * Override the default behaviour of {@link JsonAutoDetect.Visibility#DEFAULT} for creators. * * @param visibility the new default behaviour * @return a {@link com.github.nmorel.gwtjackson.client.AbstractConfiguration} object. */ protected AbstractConfiguration creatorVisibility( JsonAutoDetect.Visibility visibility ) { this.creatorVisibility = visibility; return this; }