Can Matlab access a Java function that starts with an underscore
Show older comments
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.
Accepted Answer
More Answers (0)
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!