I am trying to use the opensearch API using the ja...
# cfml-general
t
I am trying to use the opensearch API using the java client via JavaLoader and find I need to create a
"org.opensearch.client.json.JsonData"
object. The interface seems to have a static method
of
with the signature of
(Object)
however when trying to call it I get the error "The of method was not found" "There Either there are no methods with the specified name and argument types of the of method is overloaded with argument types that ColdFusion cannot decipher reliably ..." an example of what I am trying to do
Copy code
javaLoader.create("org.opensearch.client.json.JsonData").of("2023-04-21T00:00:00")
Attached is the cfdump of the JsonData interface, attempting to dup the of method give the error "Element OF is undefined in a Java object of type class coldfusion.runtime.java.JavaProxy https://www.javadoc.io/doc/org.opensearch.client/opensearch-java/latest/org/opensearch/client/json/JsonData.html Example code in java https://learnersbucket.com/examples/elasticsearch/range-query-in-opensearch-with-java-client/
a
Seeing your CFML version would help.
b
Unless that interface has a default method implementation, I wouldn't expect you to be able to call the method on an actual interface.
You need to create a class that implements that interface
I don't know what version of the library you're on, but the
of()
method does not accept an
Object
, it uses generics and the implementing class would determine what type
T
is.
1
t
the source is here https://github.com/opensearch-project/opensearch-java/blob/v2.4.0/java-client/src/main/java/org/opensearch/client/json/JsonData.java I'm not sure the generic is about implementation as this is a static method on an interface (which from what I can tell java has allowed since 1.8)
b
Do you have a Java example of what you want to do?
t
the cf version is 2018 and the javaloader is 1.2
everything else works except the use of the range query builder's from and to methods
b
What CF engine/version are you on?
a
@bdw429s it does have default implementations in the interface
b
Yes, he posted the code above and I saw
a
Ah sorry
t
adobe coldfusion 2018
b
That's your problem
Adobe didn't fix that until 2021
👏 1
Which is quite amazing, considering default method implementations on interfaces has existed since Java 8
AND, adobe added the ability to add default methods to CFML interfaces in 2018
a
Does it really amaze you of CF?
🤡 1
Thinking shit through and doing thorough a thorough job of the task at hand are not exactly something the CF Team is known for.
t
ha, well that's fun
a
But anyway. You are a again, Brad.
😁 1
👍 1
t
it's a silly paradigm, especially when it obfuscates something you should just be able to do with an init.
b
Well, they've made the actual constructor on the JSONDataImpl class private and they are using the interface's static method as a factory of sorts
But yeah, a little circuitous, but this is the sort of code java devs write 🙂
t
for no other reason than to use a feature that obfuscates
ha
guess i'll need to create my own java class to instantiate the JsonData
a
Ha was just about to suggest that.
Does the equiv
to
method in
JsonDataImpl
not help you?
t
no, gives me a "to method not found", not sure what the class wrapper does to the generic
the java CreateJsonData worked for me =p
a
Oh cool!
t
if I knew I was gonna need to do that I would have just written most of this in java. I was trying to not have any compilation steps cause I haven't used that at all for this project
a
😐
t
but using this sdk with cf is ugly, so many builder objects
but it's only half as ugly in java, so there's taht