Can Matlab access a Java function that starts with an underscore

11 views (last 30 days)
When I issue Matlab commands which end up using the Jackson FasterXML Java library, MATLAB returns a Java exception:
java.lang.NoSuchMethodError: com.fasterxml.jackson.dataformat.yaml.YAMLFactory._createContentReference(Ljava/lang/Object;)Lcom/fasterxml/jackson/core/io/ContentReference;
The Java function (writen by a different team) that I am calling from MATLAB goes through the following stages
final var mapper = new ObjectMapper(new YAMLFactory());
mapper.registerModule(new JavaTimeModule());
final URI url;
final var configFile = new File(filename);
url = configFile.toURI();
final JsonNode original = mapper.readTree(url.toURL());
so this last line calls function in com.fasterxml.jackson.databind.ObjectMapper
public JsonNode readTree(URL source) throws IOException
{
_assertNotNull("source", source);
return _readTreeAndClose(_jsonFactory.createParser(source));
}
calling function in com.fasterxml.jackson.dataformat.yaml.YAMLFactory
(in public class YAMLFactory extends JsonFactory as the mapper was passed a YAMLFactory)
@Override
public YAMLParser createParser(URL url) throws IOException
{
IOContext ctxt = _createContext(_createContentReference(url), true);
return _createParser(_decorate(_optimizedStreamFromURL(url), ctxt), ctxt);
}
_createContentReference is in the JsonFactory class and is not overriden in YAMLFactory
protected ContentReference _createContentReference(Object contentAccessor) {
// 21-Mar-2021, tatu: For now assume "canHandleBinaryNatively()" is reliable
// indicator of textual vs binary format:
return ContentReference.construct(!canHandleBinaryNatively(), contentAccessor);
}
To prove that MATLAB could have created the ContentReference if I had been able to get to the function
>> createContRef = javaMethod('construct', 'com.fasterxml.jackson.core.io.ContentReference', true, URL)
createContRef = com.fasterxml.jackson.core.io.ContentReference@fce56075
Unfortunately, I rarely deal with Java so not sure if my issue is:-
a) MATLAB cant cope with the underscore in the function name
b) The issue is that the _createContentReference function is in a parent class
c) something else
I have all the relevant jar files in javaclasspath as below
C:\Users\....\jackson-annotations-2.13.1.jar
C:\Users\....\jackson-core-2.13.1.jar
C:\Users\....\jackson-databind-2.13.1.jar
C:\Users\....\jackson-dataformat-yaml-2.13.1.jar
C:\Users\....\jackson-datatype-jsr310-2.13.1.jar
Appreciate any help.
  2 Comments
Richard Floyd
Richard Floyd on 28 Feb 2022
Testing further has ruled out option a) as the problem
a) MATLAB cant cope with the underscore in the function name
If the same function is moved from the parent to the child it can be called successfully.
So, seems to be problem b)
Richard Floyd
Richard Floyd on 1 Mar 2022
Okay, so I think I now understand my own issue as I've found that Matlab 2019b already loads PART of the Jackson libraries (i'm assuming an older version than the one I need to use) as part of the java static path
C:\Program Files\MATLAB\R2019b\java\jarext\jackson\jackson-core.jar
But, i'm forced to use the new jackson dataformat classes from my .jar
C:\Users\....\jackson-dataformat-yaml-2.13.1.jar
These are loaded after the above static path so Matlab is trying to find the _createContentReference function in the old jackson-core.jar which doesn't appear to have the function being called.
So, I need to work out how to load the new Jackson jar's at the top of the static path or somehow remove the old Jackson static entries added by Matlab. Hopefully that won't affect Matlab internally calling the Jackson libraries.

Sign in to comment.

Accepted Answer

Richard Floyd
Richard Floyd on 2 Mar 2022
Thankfully https://undocumentedmatlab.com/articles/static-java-classpath-hacks had the answer with the <before> entry in my javaclasspath.txt file
Obviously care needs to be taken with this as we are overriding the MATLAB versions
<before>
# Java classpath entries (The following come first on MATLAB static path)
# (Override internal ones -> see C:\Program Files\MATLAB\R2019b\java\jarext\jackson)
C:\Users\....\jackson-annotations-2.13.1.jar
C:\Users\....\jackson-core-2.13.1.jam
C:\Users\....\jackson-databind-2.13.1.jar
C:\Users\....\jackson-dataformat-yaml-2.13.1.jar
C:\Users\....\jackson-datatype-jsr310-2.13.1.jar

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Tags

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!