public static String getDefaultValue ( Field field ) { FieldType type = field . getType ( ) ; if ( type instanceof ScalarFieldType ) { return ScalarFieldTypeUtil . getDefaultValue ( ( ScalarFieldType ) type ) ; } if ( type instanceof Message ) { Message m = ( Message ) type ; return UserTypeUtil . getCanonicalName ( m ) + ".getDefaultInstance()" ; } if ( type instanceof Enum ) { Enum anEnum = ( Enum ) type ; String defaultValue ; List < EnumConstant > constants = anEnum . getConstants ( ) ; if ( constants . isEmpty ( ) ) { defaultValue = "UNRECOGNIZED" ; } else { DynamicMessage options = field . getOptions ( ) ; defaultValue = options . containsKey ( DEFAULT ) ? options . get ( DEFAULT ) . getEnumName ( ) : constants . get ( 0 ) . getName ( ) ; } return UserTypeUtil . getCanonicalName ( anEnum ) + "." + defaultValue ; } throw new IllegalArgumentException ( String . valueOf ( type ) ) ; }
Returns a java field default value for proto field .