public static JsonObject toJson ( Message output ) { JsonObject object = new JsonObject ( ) ; for ( Map . Entry < Descriptors . FieldDescriptor , Object > field : output . getAllFields ( ) . entrySet ( ) ) { String jsonName = CaseFormat . LOWER_UNDERSCORE . to ( CaseFormat . LOWER_CAMEL , field . getKey ( ) . getName ( ) ) ; if ( field . getKey ( ) . isRepeated ( ) ) { JsonArray array = new JsonArray ( ) ; List < ? > items = ( List < ? > ) field . getValue ( ) ; for ( Object item : items ) { array . add ( serializeField ( field . getKey ( ) , item ) ) ; } object . add ( jsonName , array ) ; } else { object . add ( jsonName , serializeField ( field . getKey ( ) , field . getValue ( ) ) ) ; } } return object ; }
Converts a proto - message into an equivalent JSON representation .