ballerina/reflect module
Module overview
This module provides utility methods for obtaining reflective information about the Ballerina runtime.
Samples
Get service annotations
The sample below shows how to retrieve all the annotations of a service:
@http:ServiceConfig { basePath: "/helloWorld" }
service hello on new http:Listener(9090) {
resource function hello(http:Caller caller, http:Request req) {
http:Response res = new;
res.setTextPayload("hello world");
var result = caller->respond(res);
}
}
reflect:annotationData[] annotations = reflect:getServiceAnnotations(hello);
string annoName = annotations[0].name; // E.g. “ServiceConfig”
string annoPkg = annotations[0].moduleName; // E.g. “ballerina.http”
Records Summary
Functions Summary
public type annotationData record
public type anyStruct record
public function getFunctionAnnotations(any functionPointer) returns (annotationData[])
Parameter Name |
Data Type |
Default Value |
Description |
functionPointer |
any |
|
|
public function getResourceAnnotations(service serviceType, string resourceName) returns (annotationData[])
Parameter Name |
Data Type |
Default Value |
Description |
serviceType |
service |
|
|
resourceName |
string |
|
|
public function getServiceAnnotations(service serviceType) returns (annotationData[])
Parameter Name |
Data Type |
Default Value |
Description |
serviceType |
service |
|
|
public function getStructAnnotations(typedesc structType) returns (annotationData[])
Parameter Name |
Data Type |
Default Value |
Description |
structType |
typedesc |
|
|
public function getStructFieldAnnotations(typedesc structType, string fieldName) returns (annotationData[])
Parameter Name |
Data Type |
Default Value |
Description |
structType |
typedesc |
|
|
fieldName |
string |
|
|