#Connecting ballerina to java

1 messages · Page 1 of 1 (latest)

ionic void
#

I was following the below link as reference for the connectivity of ballerina to java
https://github.com/ballerina-platform/module-ballerinax-kafka/blob/master/native/src/main/java/io/ballerina/stdlib/kafka/nativeimpl/consumer/BrokerConnection.java

I was able to access the java method which was not returing anything from java side to ballerina .
But when i wanted to access the java method which return some Object to ballerina i am doing this

function readString(handle arg1, handle arg2) returns handle = @java:Method {
`class: "com.exm.Student"
}external

Student s1 = <Student> readString(obj, "hello"));

getting below error :{balerina}TypeCastError {incompetible type 'handle' cannot be cast to package_path:Student}

In java side

public Object readString(string obj) {return new Student("name", 2)}

GitHub

Ballerina Kafka Module. Contribute to ballerina-platform/module-ballerinax-kafka development by creating an account on GitHub.

south sierra
#

'Handle' represents any Java Object. But here we are trying to assign it to a Ballerina class type which panic with cast error. ( Assume Student is Ballerina class). Then we need to return io.ballerina.runtime.api.values.BObject from Java side.
If Student is a record type, We need to return io.ballerina.runtime.api.values.BMap. Please refer https://ballerina.io/learn/ballerina-ffi/#map-ballerina-types-to-java-types which explains how we can map Ballerina types/values to Java

This is a reference guide on the list of language features that enable Ballerina developers to call foreign code written in other programming languages.

ionic void
#

@south sierra
Whe n i call readString(obj, "hello"));
in ballerina that i am getting Student object which in java how do i read its menen=ber functions in ballerina file

ionic void
#

how to read ballerina side custom object