Hello
Hải,
I had a similar problem as well. As mikkelfj pointed out, given the corner cases, parsing FBS files is not simple, but not impossible either. Then I followed a different path: I type the FBS definitions in XML (see the XSD in the attachment) and generate FBS files and Java (de)serializers.
<?xml version="1.0" encoding="utf-8" ?>
<schema xmlns="http://vlkan.com/schema/flatbuffers">
<version>1</version>
<namespace>com.vlkan.flatbuffers.data</namespace>
<attributes>
<attribute>priority</attribute>
</attributes>
<struct name="Vec3">
<field name="x" type="float"/>
<field name="y" type="float"/>
<field name="z" type="float"/>
</struct>
<table name="Monster">
<field name="pos" type="Vec3"/>
<field name="mana" type="short" default="150"/>
<field name="hp" type="short" default="100"/>
<field name="name" type="string"/>
<field name="friendly" type="bool" default="false">
<attribute name="deprecated"/>
<attribute name="priority" value="1"/>
</field>
<field name="inventory" type="[ubyte]"/>
</table>
</schema>
Long story short, if you want to write a native Java code generator in Java (which would be awesome!), you can leverage a similar XML structure too. If it is still needed, in the future phases of the project, you can add a FBS schema reader too.
And you do not need to mess with JNI. Did you see my Maven artifacts for flatc? You can just plug them into your build system and you are done.
Cheers!