asciidoctor / asciidoctorj

:coffee: Java bindings for Asciidoctor. Asciidoctor on the JVM!
http://asciidoctor.org
Apache License 2.0
623 stars 173 forks source link

'convert' returns dynamic Ruby Interface instead of String when converting to String #1174

Closed abelsromero closed 1 year ago

abelsromero commented 1 year ago

The following example converts an AsciiDoc source to a String, but has 2 problems:

  var options = Options.builder()
      .catalogAssets(true)
      .safe(SafeMode.UNSAFE)
      .build();
  var doc = asciidoctor.convert(Files.readString(sourceDocument.toPath()), options, Document.class);
  1. The returned internal type is a dynamic coerced interface (in the example org.jruby.gen.InterfaceImpl682315553)

image

  1. The returned object wraps in fact an String but we asked for Document.class.

Both happen because we don't validate the types, but just delegate in jRuby https://github.com/asciidoctor/asciidoctorj/blob/0240f02d54268bc484d6da210d0803c0156578e0/asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/JRubyAsciidoctor.java#L314.

I think we should:

abelsromero commented 1 year ago

It was not my idea to close this yet. The latest fixes prevent returning invalid types but I still think it's worth thinking deeply about how we should expose the convert/load methods in a more Java-like way.