Squashed 'third_party/flatbuffers/' changes from 338393f85..e5f331db9

e5f331db9 [TS] Add single-file ts codegen & bazel rule for typescript (#7161)
2f84c6038 Apply Namer to Go code gen (#7150)
d64839651 [Lobster] file_identifier support
777e78d8d [Lobster] support unsigned integer reads
4016c549d Apply Namer to Python code gen (#7146)
40827b21b Fix missing 'break' (#7151)
65a10b6e3 Implement a config based name manager and use it in Rust codegen (#7144)
8db2fef3f [TS] Escape keywords in typescript object names (#7137)
9ed132304 Fix 64-bit numeric enum values in typescript (#7135)
1a4c40566 updated npm to 2.0.6
318594e4b prevent name clash (#7133)
3d903302c [Rust] Add length checks to arrays and vectors. (#7130)
c9571d989 Replaced ToDasherCase with ConvertCase (#7131)
3694b830a Use ConvertCase instead of Make{Upper,Lower,Snake} implementations (#7127)
0471fa807 remove stall reference to version
914344ea9 some minor help edits
b40266c56 Use target_compile_features to target C++11 (#7122)
8a9303d46 update proto tests with alaised enum (#7121)
30c4bf47f Trigger fuzzing CI only on relevant changes (#7120)
46ce45601 remove auto generate code from cmakelists (#7119)
433312c55 add the missing checkNullConditionnal code in the "GenObjApi" function when the field is scalar optional (#7114)
9c52ec374 Add deps attribute to flatbuffer_cc_library (#7107)
70e2f49bf fixed string-json -> strict-json typo
5ac0367ed [TS] Fix generation of reserved words in object api (#7106) (#7115)
5d101afb5 Fix minor typo in WhitePaper.md (#7108)
06f4af11b Go optional scalars (#7104)
57e338f81 explicitly use windows-2019 to unblock ci (#7105)
615616cb5 Change Rust generated file defaults (#7101)
3413c3300 Fixed FlexBuffers verifier fuzzer timing out
69f5660a4 Fixed Parser not checking size of union types vector
d5add9fca Fixed FlexBuffers ToString unquoted non-ident keys
15df50eb7 Remove @ExperimentalUnsignedTypes annotation from kotlin code generator. (#7092)
a94132a45 Swift FlatBufferBuilder.sizedByteArray to ByteBuffer.toArray() (#7093)
48befb6be [TS] Refactor away circular ref (#7099)
b30069133 Add reflection support for python (#7026)
faadbc10e Add CreateVector overload to accept array like (#7095)
ed6ae8d32 explicitly defined std::allocator (#7094)
e910bddbc [JS] Add ".js" suffix to all import statements to generate a browser compatible mjs version. (#7086)
c85fb690f Add Parsing Completed function for Rust (#7084)
c1daa6ba0 rust: Bump thiserror version and remove git dependency (#7080)
4c71c7b02 replace framework include of flatbuffers (#7079)
f5664d33f fix go_test implement error (#7012)
39c8a19ce fixed comparator for native_inline (#7076)
826193ff6 skip generating reflection.fbs in generate_scripts (#7077)
fd0d1ed92 update C++ generator to emit scoped enums in vector of unions (#7075)
424988f30 replaced removed xml tag
b2550dbaa removed BSD-3-Clause license and Zlib licenses (#7073)
a2b238960 Fixed default value of bool in struct for Swift (#7072)
619b78437 one last dart omit local (#7070)
68a766154 more omit type annotations for dart local variables (#7069)
7dac9961f omit type annotations for dart local variables (#7067)
c65c389c6 add xmlns to .Net (#7066)
6446dcf3d Updates swift gen licence for grpc code (#7063)
e090d8da1 Fixed long cast to int in flexbufferbuilder.java (#7059)
bc901436d clang format on codebase (#7058)
240be9b5a attempt to remove appveyor (#7056)
bc366a7f9 Provide a short help text and default in error case (#6992)
14b19d446 Use FindPython3 (#7055)
9e6f17b94 remove BIICODE
c3801ad37 Update readme.md
4f3b24db0 Fixes a bug where bools arent being nil when marked optional (#7051)
1d294a31b Implement Serialize on generated rust types (#7022)
dd8fccfb1 Cmake 3.16 de-facto minimum version (#7049)
7089c9ecd Convert flatbuffers_version_string to inline function (#7046)
43203984f [C++] Support C++ object copies and moves (#5988)
5993338ee [ts] Builder incorrectly serializing empty strings (#7047)
19920db39 Include a SizePrefixed..HasIdentifier for c++. (#6871)
dbbaeac85 Use `${PYTHON_EXECUTABLE}` instead of `py` in cmake (#7042)
028f0fde6 'flattest': Add --test_path option (#7041)
87343631b Added support for clang-cl on windows (CMake) (#7038)
1fbfaf5c5 Fix/cmake build grpc (#7028)
4421375bb Add FlatBuffers::FlatBuffers interface, needed for FetchContent_Declare (#7023)
162ad7a37 Fix comment with line orders - Rust should be last. (#7037)
a0a6c3f8c Use actions/checkout@v2, which fixes security vulnerability. (#7036)
a2d38fbb9 Add --warnings-as-errors to flatc compiler. (#7034)
9ef1524d3 Emit include for bfbs-gen-embed (#7031)
0c9de0352 Upgraded GRPC version to 1.42.0 (#7033)
a783bc926 chore: dart 2.0.5 release changes (#6983)
aff818ceb rust: Allow for usage in no_std environment (#6989)
d7b75417f Make flatbuffer builder deterministic (#6993)
a42e89897 Added verifier alignment checking to table fields (#7018)
96cc2f3ee BuildFlatBuffers.cmake: fix arguments not passed properly to flatc (#7013)
3250a1f8d Add initial C# vector of unions support to the documentation. (#6880)
ace4a37f2 [TS/JS] BigInt implementation (#6998)
f28c2b293 Avoid implicit conversion from float to double. (#7003)
96f3cf690 Rearrange #include directives to pass to compilation with a particular DSP toolchain (#7000)
b3edfdbfb Reverting grpc generated file suffix (#6995)
b8aaccee8 Disable parsing of nested_flatbuffers as bytes by default
2dc8ae774 Enable OSS-Fuzz on CI
5b0d49112 Updated FlexBuffers fuzzer
d8b7041d7 Added alignment checking to FlexBuffers verifier
5a0c3366c FlexBuffers verifier additionally checks for nesting
f8148b8da Made FlexBuffers reuse tracker track types
a22b1b626 Prevent shadow with _{{FIELD_NAME}} (#6991)
4264daadd FlexBuffers fuzzer fixes
3cbc120a0 Refractor Flatc Options (#6987)
8dcd2682c [CMake] Add option for disable universal on OSX (#6990)
b78002ff3 Validate C# json/object-api options (#6985)
c555ee8fa Add .NET test to github workflows (#6982)
b92bb0584 [CMake]: Fix version in pkgconfig file (#6986)
956d11569 re-enabled FlexBuffer JSON in fuzzer
e367ca32a Verifier for FlexBuffers (#6977)
705f27f6e [CMake]: Fix python command for mingw environment (#6984)
5fc87f4c4 Enable --gen-onefile in Python (#6953)
11749095a Make idl_parser deterministic (#6976)
d0cede9c9 Bumping to Version 2.0.5 (#6967)
fcc2bee0b Fix typo in variable name (#6973)
e08da4dea remove Appveyor's Vs2010 and 13 builds (#6969)
18538c401 [TS] Fix reserved words as arguments (#6955) (#6956)
e57f4ab2d Update stale bot version and provide away to exempt issues with the not-stale label (#6968)
deed68db5 missing generated files (#6966)
061d61f3f Lua Generator using IR. (#6940)
cffe0c454 FixedTypedVector: add const to ElementType() and size() (#6965)
fadd40e40 Have grpc include file with correct filename-suffix given to flatc (#6954)
e47dc0e46 Removed test/generate_code.{sh|bat} (#6873)
5c5475479 switched to windows-lastest, removed deadcode (#6948)
4f7f6dc30 Restore FlatBufferBuilder::kFileIdentifierLength. (#6960)
0fadaf391 Enable verifier on nested_flatbuffers
4d0e9a870 Turn off nested FlatBuffers/FlexBuffers for the fuzzer
c05f6783a invalid conditional running genrate_code.py (#6952)
a14f4052c rust: remove needless borrow (#6922)
9e4ca857b Vector Downward GetSize optimization (#6925)
a2b99084b Fix flexbuffers clang-analyzer warning (#6947)
85b4effac test: fix undefined order of functio parameters. (#6946)
790f41154 [cmake] Fix getting version info from tags during the build (#6936)
e89de4411 clang-all (#6941)
256ab3798 WIP: Dart release 2.0 (#6927)
a59288a01 Add benchmarks to Linux CI (#6928)
587bbd49a [C++] Fix compile failure on Object API union construction for struct member (#6923)
a9c341545 Fix integer overflow warnings
8aa18b629 fixed cmp0048 error (#6932)
d727579b6 fuzzers: fix typo in file path (#6931)
97a30171c Added Raw C++ benchmarks (#6924)
0989fc5e5 Added Google benchmarks (and gtests) (#6920)
927175ea2 [Java] lookup by byteArray is giving back wrong entry (#6915)
6748c373b Removal of support for FLATBUFFERS_CPP98_STL (#6918)
3fab0c6ee move [[ ]] to calling sites (#6914)
6c8c29155 [C++] Split flatbuffers.h into separate files (#6868)
fd4ff23da Keep methods with struct name and switch them to default (#6879)
f8b69e330 [Python] Verify EnumDef is not generated in GenUnionCreator (#6903)
c0394bb09 Support `--conform` for vector of unions (#6883)
8433eb108 Typo fixes in comments of flatbuffers.h and flexbuffers.h (#6901)
f2f9380c8 [Java] Prevent generation of enum names when underlying type is long (#6781) (#6895)
e672dabfe [C++] Fix memory leak when using grpc (#6896) (#6897)
9a4ca2764 Output errors / warnings on stderr instead of stdout (#6881)
4c7a9c10d Adds JSON encoding to swift (#6874)
38295a187 [Kotlin] Fix missing escape for struct construction statements (#6877)
31bb0b972 add working directory (#6878)
45e5642e9 Default Arguments for Mutators C++ [Updated] (#6872)
a592f4c89 [Cmake] Add a post build command after flatc to run the new generate_code.py script. (#6866)
b9d43a557 dart - add Packable interface (#6846)
2ece9e25b Bumped package.json to 2.0.4
2dd212637 Fix linker errors on (Free|Open)BSD. (#6860)
f63c130c2 Improves documentation, and adding DocC (#6784)
e2b26ee19 Make and generate_code.sh generate same outputs (#6855)
9d686bf43 Include subdirectories in published npm package (#6850)
1d26daff3 Use ArrayBuffer type for JS flexbuffer's toObject (#6851)
e72e18d9f feat(build): compile "universal" libraries and executables for Mac (#6852)
354d97f6d fixed errant itemgroup element in C# test project (#6854)
6f7a57eaa [C#] Using 'global::' as qualifying_start_ within BaseGenerator (#6767)
90baa1444 Dart: binary lists (typed_data) (#6839)
0a3b017f0 Delete IDLOptions::lang (#6841)
47d35f105 BugFix: Optional enum when it is null (#6835)
8fb8c2ce1 [C#] Use @ for keyword escaping (#6834)
1d063d87c [C++] Let builder accept custom-alloc std::vector (#6814)
338331b55 Changes to support binary schema file loading and parsing (flatc) (#6823)
156a30c75 Move Apple-specific build flags to Clang section (#6802)
550d2f904 Issue error if jsonschema has no root type defined #6821 (#6831)
c3a38242e Fix typos in docs (#6829)
74c3d7eba [C++] Add mutable version of LookupByKey and test (#6826)
db6eae5c4 Add html and latex to gitignore (#6819)
0e9d79c35 [Java] Avoid casting ByteBuffer to Buffer (#6785)
b20c4d3aa [C++] Add GetMutableSizePrefixedRoot and generate GetMutableSizePrefixedXxx functions (#6815)
ae145293c flattests_cpp17 doesn't compile with Visual Studio 2017: warning C4100: 'indent': unreferenced formal parameter (#6811)
e3c76a5cd Dart lints (#6808)
4b9123baf fix parser string=null (#6810)
f89e0b1a6 Refactor idl_gen_rust and Rust generated code to use consistent whitespace (#6809)
273f6084e Fix Rust keyword inconsistency (#6794)
4a0879458 [C#] Remove superfluous semicolon in C# structs (#6791)
d6f51ea16 fix ptr in flatbuffers cpp tutorial (#6787)
067dce6e7 [C#] Handle keywords (#6775)
2ca5f0e72 [C#] Respect command line parameter for file name extension and suffix (#6779)
f20d2253a update Java version to 2.0.3
390d438e2 [Kotlin] Fix CI by changing compiler to Java 11 (#6783)
6fb2c90d9 avoiding even more NoSuchMethod exceptions (#6729)
a7b527d94 java: Use maven profile to target Java 8 bytecode (#6764)
5d77820b3 [C++] Using calculated fields_number for field_names size (#6769)
909ce970a [C++] Use UnPackTo instead of UnPack if pointer exists (#6725)
35e2cac6e Store vtables sorted in Rust builder (#6765)
c39fc9dd9 [C++] Use nullptr instead of 0 in generated headers (#6762)
775c6567d [C++] Fix compiler warning -Wredundant-parens in clang (#6761)
97d9527f6 Dart 2.0 release prep (#6759)
e01205466 [C++] Use proper gRPC C++ API when using MemoryBuffer Slice (#6756)
5235133f3 Dart - make ascii optimization optional in StringReader, same as in writeString() (#6758)
c871df770 Dart - change table building to assert() instead of exceptions (#6754)
a6eeeb3b9 Dart - inline small functions to increase performance (#6755)
3dd02144d [C#] Fix field name struct name collision (#6744) (#6757)
e77926f0e [C#] Add Union Constructor Utility for ObjectAPI. (#6105)
ac2348202 Dart - fixup writeString() return type after previous merges (#6753)
8be8a0a71 [C++] Fix union type handling on object api in C++17 (#6745)
12e341e4f Rework how Rust generated files are laid out (#6731)
c36672d80 Dart - optimize writeString for ASCII (#6736)
2bfc8e9f0 Dart - make writeString() argument non-nullable (#6737)
674a9f2aa fix lints in rust tests (#6743)
016e6aa13 Add a split on ':' to build_defs.bzl (#6742)
65700441d Dart - make vTable fixed size (expect the number of fields when creating) (#6735)
dd5bb55ca Dart - make vTable deduplication optional (#6734)
e8423da1b Dart - regenerate example after recent flatc changes (#6733)
0980e39c9 flexbuffers: Add variant of Blob() that takes a key (#6730)
e73fab27d Dart - store empty vectors instead of NULL (#6728)
92ae532e4 Dart - finish/lowFinish/buffer changes (#6712)
7482b25f8 Remove ubuntu1604 from presubmit.yml (#6715)
3f77dc9a0 Dart - unpack() must use eager list reader (#6723)
838c93b84 Dart - fix flex-builder compilation error (#6722)
089f48a4a Dart - make sure added padding is zeroed, same as in C++ (#6716)
bf3470c16 Fix UB in CreateVectorOfStructs in case of an empty vector: avoid calling memcpy in this case (#6726)
8f8196e13 Fix 6348 (#6717)
8ab35b2a5 Dart - add custom allocator support (#6711)
c0ba2870c Fix typo in docu (#6714)
22498cf3a [C++] add make_span for Array<T,N> (#6663)
bd37e67ac [C++] Fix a -Wdeprecated-copy warning. (#6708)
a6ee33557 Dart null safety (#6696)
71d43f3be Make --bfbs-filenames default to location of first schema file. (#6705)
c8db1ca5d Jsonschema add prop comments (#6617)
962751a6e Improve generated comparisons for tables (#6486)
06fd6d640 Replace filenames in reflection with filenames+includes. (#6703)
acce4ac3f Fix incorrect assertion usage. (#6702)
8fd7861b7 Fix warning about deprecated module: imp (#6362)
c58ae9422 Add the file a symbol is declared in to Reflection (#6613)
2cf7bb796 Intermediate Representation docs (#6685)
4e3a66c14 Dart object API (#6682)
d959e2320 dart - change Builder.reset() to reuse an existing buffer (#6661)
a9fb54088 use improved versioning (#6691)
337eb8b8f update docs - structs can't be roots (#6690)
6415ef05d [Python] [Codegen] Fixes nested structs with underscore names (#6686)
f069396d1 [C++] flatc --cpp-field-case-style option to permit camel-case field names in C++ (#6669)
021177af0 Fix snap version formatting (#6683)
e1e9f9373 [C++/grpc] added hiding of unused variables in the generated code (#6677)
15110094e Fix GitHub Actions CI gcc/clang versions
093badb0a Use unoptimized path for ReadUInt64 for win32 build as the optimized path crashes. (#6681)
752c7b576 avoiding more NoSuchMethod exceptions (#6671)
7c3e267e1 [Java] ObjectAPI implementation (#6521) (#6582)
baaffbaed npm update to 2.0.3 and script fix
4cb3f222b [TS] Fix module reference in package.json (#6676)
eabdbda75 [TS] Generate entry point module (#6674)
bec23700f Prepare for Java 2.0.1 release
12f2eedad Update CI to GCC/Clang 11
221eeb231 Fix typo in C++ doc (#6664)
813d3632e avoiding NoSuchMethod exception (#6658)
d84bccb0c Removed most heap allocations in builder (#6662)
b4e67f9bf Dart test fix (#6660)
54c11932f [Java] Flexbuffers - Negative signed object length (#6651)
fbcb3c423 [TS/JS] Updates the grpc (#6654)
8937dcfd7 Updates go lang support to allow other languages to communicate with it (#6653)
512d5a689 Update readme.md to point to security policy
a92cb5dd7 Create Security.md
d151dcbb9 Revert "[C++] Removed most heap allocations in builder (#6620)" (#6659)
f1884c66f Fix gRPC test to use EndVector without specifying the length. (#6646)
72730ecd8 [C++] Removed most heap allocations in builder (#6620)
fe2bc2b0a Added README for Rust Flatbuffers (before publishing v=2.0) (#6652)
4867c9456 Fixed generation of c++ code with flags (#6637)
ef0eb3701 Ran clang-format-all.sh. Removed default --style=file parameter (#6639)
f83ee1af5 [idl_parser] Check structs and enums do not clash in a namespace (#6562)
a5175c513 Implements verifier and code gen for swift (#6373)
04b10f5a3 Deprecate EnumVal.object (#6612)
c121c0345 Fixed Java gRPC version number dependency
8fd10606c Implement Serialize for flexbuffer::Reader (#6635)
a1730fcea [Swift] Updated cocoapods to 2.0.0 (#6634)
a9a295fec More missing version changes
5c01ad387 Dart generated code update
42ca1b914 Swift/Kotlin generated code version updates
6ed780dbd C++/Rust version changes
3412fab8e C#/Java generated code version updates
8a7d013f8 Updated main version numbers to 2.0
170af5978 [Go] Add missing namespace when using Object API (#6633)
c8c16de16 Fix reverse iterators for Vector and Array (#6626)
4525cd9c5 [Lua] manipulate byte array as string (#6624)
47361baf6 [C++] Fix union copy constructor to work with nested structs (#6552) (#6607)
8a582883a Updates swift generated monster sample file (#6616)
a4bb8f0c2 [Lua] Avoid infinite loop when creating empty string (#6614)
82aed82b8 Added support for Lua 5.1, 5.2 and 5.4 (#6606)
60ff76630 [TS] Remove wrong and obsolete NS prefix use (#6604)
a27c7d809 Fixed LuaJIT when not compiled with COMPAT mode (#6605)
363220823 removed unneeded type prefixing (#6601)
6b44c605b Bump Rust to 0.9.0 (#6610)
d3cd78a87 [Lua] Add LuaJIT support (#6584)
8fa3dfdb5 Introduce new_from_vec in Rust (also fix formatting) (#6599)
29379e8e4 fix typo in CppUsage.md (#6595)
14725d6c3 [Lua] GetRootAs can accept strings. Made Luatest Benchmarks optional (#6593)
16836ff95 Add advance feature indicators to reflection (#6546)
c87179e73 Rust Remove SafeSliceAccess for Arrays, and fix miri. (#6592)
c24031c36 Mark endian_scalar as unsafe. (#6588)
4ccc52c7a [swift] Implements union strings (#6589)
b82fe0738 [Rust] Fix small mistyping (#6585)
1e7f6c8c7 [TS] Commit the generated tests code (#6579)
84714b109 chore: ensure bash is used to generate code (#6577)
1045d7dd4 [Lua] Fix EnforceNumberAndPack for bool type (#6576)
0c7777596 [TS] Remove duplicated build-ts ci (#6575)
c43ba1752 [Rust] Specify Minimum Supported Rust Version (#6573)
da3bb64ef [Rust] Add support for fixed size arrays (#6548)
151900ba9 [Kotlin][FlexBuffers] Add support for Kotlin-iOS (#6564)
c012f29f9 silenced clippy warning (#6565)
df2df21ec [Kotlin] Bump kotlinx.benchmark dependency to 0.3.0 (#6560)
408e4db4a [TS] Add Build TS to CI jobs (#6524)
4d2364f34 [Kotlin][FlexBuffers] Add support for Kotlin-JS (#6554)
261cf3b20 Default-empty vectors of enums (#6505)
cd67261bb [CI] fixes buildkite (#6544)
1aa0c2f6a Limit formatter to pull requests only (#6540)
4133a39df Rust structz (#6539)
1c26d2a1a [Kotlin][FlexBuffers] JSON support for Flexbuffers (#6417)
276b1bc34 [grpc] Support latest version of grpc PoC (#6338)
124654ffc fixed packing structs (#6530)
3b7d1e86b [GO] Tries to add go format to the CI (#6518)
78f0c0d1d [C++] #6501 - Problem when mapping a native type multiple times (#6514)
c992eafb5 [fuzzer] Add `monster_debug` target (#6513)
ef8dd7792 [Swift] Removes allman rule (#6519)
69b329fc8 [flexbuffers, json] Parse `nan` and `inf` (#6512)
6543ba529 fixed packing structs in nested buffers (#6509)
0e453ac35 [idl_parser] Add kTokenNumericConstant token (#6432)
e9b4ae69d Remove `flatbuffers.pc` from the repository (#6508)
fc4fffea4 Bump grpc to 1.0.0 (#6507)
b240ab704 Move Traits struct and Create method out of --cpp-static-reflection. (#6503)
9a4f1f434 Disable x64-specific optimizations for ARM64EC ReadInt64 (#6506)
fac64918d Add --cpp-static-reflection to generate_code.bat. (#6502)
a69815f72 [C++17] Add compile-time reflection for fields. (#6324)
4033ff589 fixed invalid TS call and added test files (#6495)
a08357251 disable clippy (#6494)
5319dedb1 [idl_parser, JSON] Disable parsing of JSON for incomplete schemes (#6493)
bd4e0b30a [idl_parser] Track included files by hash (#6434)
bf9061200 fix for noUncheckedIndexedAccess in ts (#6474)
8142fedd1 Working on a python example plus fixing python grpc code (#6456)
c0be1cb7a [rust] Remove debug code (#6475)
8cccdfba5 Revert "[C#] Fix truncated ArraySegment<byte> if elementSize != 1 (#6462)" (#6488)
cbbbaa61b [C#] Fix truncated ArraySegment<byte> if elementSize != 1 (#6462)
ffc2ef77c [CI] Adds Code Generation tests on Github Actions (#6482)
1da6f4f18 [CMake] generate pkg-config flatbuffers.pc file (#6455)
b5da526e6 [Swift] Moves grpc example to grpc/examples (#6479)
3b5365762 [TS] Moves grpc code to examples folder (#6476)
e2f5438ac Fixes grammer (#6477)
5e3613f73 Fix sample_binary.py to use latest EndVector without a size. (#6478)
e6b911d40 updated JS docs to reflect current status (#6436)
0c7ae5816 [Go] Working on a go example plus fixing go grpc code (#6448)
ae603b977 [Swift] adds support for default vectors and strings (#6461)
7f47718b6 Update Building.md (#6473)
54dc09e8a GetUOffsetT must get value by GetUint32 not GetInt32 (#6072)
334c6be49 Fix a typo in Swift codegen (#6470)
4174c10e7 [rust] Genericize flexbuffer reader (#6450)
a20f606c2 [Swift] Renaming protocols (#6469)
a72a20827 Update swift docs (#6460)
86401e078 Default strings and vectors: Parser + Rust support (#6421)
6af37e672 [CMake] Renames BUILD files (#6457)
1b88655b0 [Build, cmake] Add -Werror override option (#6429)
0b15916e5 [C++]Fix extra char generation for byte type during json schema generation (#6276)
60eed0ca6 Updating working code (#6441)
0f83367f5 JSON schema - tailing double quotes for maximum (#6452)
fee095410 [idl_parser] Validate `force_align` on all possible paths (#6430)
6f3e45eca Implement Rust object API defaults (#6444)
815d3e820 Upgrade swift grpc to alpha 24 (#6439)
76e7a0ff5 [fuzzer] Limit parser_fuzzer execution time (#6431)
6d91096a2 This commit contains the initial implementation of Flexbuffers in Kotlin. The code was ported based (#6387)
13d9e3585 Better python generated code naming (#6336)
6effe431b Rust: remove inner attributes (#6410)
efcbdc769 [Rust] Ensure unions are referenced with the correct path (#6422)
e581013e3 Refactor FieldDef to model presense as an enum rather than 2 bools. (#6420)
0984d4328 [c++] Apply NativeName before WrapInNameSpace in idl_gen_cpp.cpp (#6419)
786f69b24 Formats cpp code (#6349)
1da0a2dfa Rust Object API (#6070)
796ed68fa Clarify that (Flat|Flex)Buffers do not deduplicate vector elements (#6415)
7b1ee31d8 Clarify that FlatBuffers unions do not support scalars (#6416)
4aff1198d Explain how FlatBuffers encodes unions (#6414)
ad3a729f9 dart Builder - expose finished buffer size (#6403)
52e217706 Remove invalid claim that Protocol Buffers does not support unions (#6413)
760c65755 [TS/JS] New gen TS code gen (#6302)
75c859e98 [idl_parser] Improve symbols lookup thru parent namespaces (#6407)
91b0958c4 Search for includes in the directory containg the current file (#6371)
8008dde11 Upgrade Rust dependencies (#6406)
c81cf8249 [TS/JS] New gen TS code gen prequel to preserve history (#6404)
8573108bb Unset FieldDef.optional if its key (#6402)
7abe612b5 [fuzzer] Fix the binary schema loading in the monster_fuzzer (#6396)
408cf5802 Fix Rust UB problems (#6393)
39e115fdb Define Vector::value_type for STL compatibility (#6394)
85719669c [fuzzer] Debug the monster_tets.bfbs on clusterfuzz server (#6392)
809fe49c7 Fix up scripts, fix generated enum value for strong mode, regenerate files (#6389)
41253e574 [go] tests/GoTest.sh: Fix flags.Parse location to work on new go SDKs. (#6388)
08d2ce844 fix Dart Builder._writeString() - always write trailing zero byte (#6390)
a15a8d930 fix Dart Builder.reset() - clear vTables (#6386)
83ce29cc2 [C++, JSON] Fix nullptr access when reading a key with a default value. (#6375)
4363c1d2c Fix generated EndVector. (#6385)
1bf1ec027 Implements type promotion for Java enum  (#6382)
080097653 Delete label_notify.yml
795408115 Disabled PHP CI (#6381)
46545e627 fixed warnings (#6355)
0168178a1 Fix multiple fbs code generation failure (#6365)
82836a62b [idl_parser] Improve stack overflow protection (#6364)
e7430bbeb [idl_parser] Check the range of explicitly set field's id value (#6363)
24dd85fd2 Generate code to encode and decode nested flatbuffers in Python. (#6354)
57f68e289 [Rust] Shared String (#6367)
44cf2bde1 Updates license  date to 2021 (#6378)
be37d4da1 include_prefix support for rust (#6330)
4e79d129c [Swift] Rebuild the way swift handles structs from scratch (#6326)
05192553f Fix typos in usage/comments; Make rust generator respect to --filenam… (#6342)
f2511d7d4 Renaming infinity variables in test.cpp (#6340)
f8b203c9c Add vectorNumElements attribute to Builder for simpler vector creation. (#6328)
8ab7c7e2c [CI] Adds formatter to CI (#6272)
7e0039028 Fix Max CI build path (#6333)
65c415911 Generate nullable properties in C# object-based API for optional scalars. (without -gen-mutable) (#6273)
a9e91116d [Python] Commit some orphan python genfile diffs. (#6325)
80a745d9b Fixed missing ending quotes in labeller (#6327)
9fca5e4f4 Add flatc option to inhibit all warnings #6005 (#6301)
92a806b4e [fuzzer] Rename fuzzing dictionaries for `oss-fuzz` (#6318)
9c9baf6d5 bumprust (#6322)
aafc5dc95 Set default initialSize for Builder to 0 (#6310)
442949bc1 Rust Flatbuffers Verifier (#6269)
9064072e8 Version message should be a "STATUS" to avoid going to stderr. (#6316)
fd4c1b5ff Replace std::string and const char* CreateSharedString with string_view (#6315)
bc7eb8ade [fuzzer] Fix mistakes in the `parser` and `scalar` fuzzers. (#6314)
fc960f367 Add default to offset param of Python generated GetRootAs (#6312)
f437f0f7e [fuzzer] Fix loading of schema in monster_fuzzer (#6308)
7f33cf682 [C++] Switch `flatc` to `--cpp-std c++11` C++ code generator (#6306)
8d9eae9ac [idl_parser] Unify parsing of NaN values read from .fbs and .json files (#6296)
2046bffa4 Moved various language tests from AppVeyor to GitHub Actions (#6300)

git-subtree-dir: third_party/flatbuffers
git-subtree-split: e5f331db998a808f78cf5a4880e6f5d0a321c4d0
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
Change-Id: I37f8aaf007fc86226cfa250169a87807afa64a78
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.java b/tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.java
index e23cecc..949c204 100644
--- a/tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.java
+++ b/tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.java
@@ -2,6 +2,7 @@
 
 package NamespaceA.NamespaceB;
 
+@SuppressWarnings("unused")
 public final class EnumInNestedNS {
   private EnumInNestedNS() { }
   public static final byte A = 0;
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.py b/tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.py
index cb8218f..ae74c54 100644
--- a/tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.py
+++ b/tests/namespace_test/NamespaceA/NamespaceB/EnumInNestedNS.py
@@ -6,4 +6,3 @@
     A = 0
     B = 1
     C = 2
-
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.cs b/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.cs
index 6fa9dd3..0ed6a63 100644
--- a/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.cs
+++ b/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.cs
@@ -43,7 +43,7 @@
       _o.A,
       _o.B);
   }
-};
+}
 
 public class StructInNestedNST
 {
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.java b/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.java
index 6505561..7184f03 100644
--- a/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.java
+++ b/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNS.java
@@ -30,5 +30,23 @@
     public StructInNestedNS get(int j) { return get(new StructInNestedNS(), j); }
     public StructInNestedNS get(StructInNestedNS obj, int j) {  return obj.__assign(__element(j), bb); }
   }
+  public StructInNestedNST unpack() {
+    StructInNestedNST _o = new StructInNestedNST();
+    unpackTo(_o);
+    return _o;
+  }
+  public void unpackTo(StructInNestedNST _o) {
+    int _oA = a();
+    _o.setA(_oA);
+    int _oB = b();
+    _o.setB(_oB);
+  }
+  public static int pack(FlatBufferBuilder builder, StructInNestedNST _o) {
+    if (_o == null) return 0;
+    return createStructInNestedNS(
+      builder,
+      _o.getA(),
+      _o.getB());
+  }
 }
 
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNST.java b/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNST.java
new file mode 100644
index 0000000..0e6963c
--- /dev/null
+++ b/tests/namespace_test/NamespaceA/NamespaceB/StructInNestedNST.java
@@ -0,0 +1,28 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+package NamespaceA.NamespaceB;
+
+import java.nio.*;
+import java.lang.*;
+import java.util.*;
+import com.google.flatbuffers.*;
+
+public class StructInNestedNST {
+  private int a;
+  private int b;
+
+  public int getA() { return a; }
+
+  public void setA(int a) { this.a = a; }
+
+  public int getB() { return b; }
+
+  public void setB(int b) { this.b = b; }
+
+
+  public StructInNestedNST() {
+    this.a = 0;
+    this.b = 0;
+  }
+}
+
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs
index cdbf6f8..9e67112 100644
--- a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs
+++ b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.cs
@@ -13,7 +13,7 @@
 {
   private Table __p;
   public ByteBuffer ByteBuffer { get { return __p.bb; } }
-  public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_1_12_0(); }
+  public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_2_0_0(); }
   public static TableInNestedNS GetRootAsTableInNestedNS(ByteBuffer _bb) { return GetRootAsTableInNestedNS(_bb, new TableInNestedNS()); }
   public static TableInNestedNS GetRootAsTableInNestedNS(ByteBuffer _bb, TableInNestedNS obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
   public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
@@ -49,7 +49,7 @@
       builder,
       _o.Foo);
   }
-};
+}
 
 public class TableInNestedNST
 {
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.java b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.java
index b0931b1..45e4974 100644
--- a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.java
+++ b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.java
@@ -9,7 +9,7 @@
 
 @SuppressWarnings("unused")
 public final class TableInNestedNS extends Table {
-  public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); }
+  public static void ValidateVersion() { Constants.FLATBUFFERS_2_0_0(); }
   public static TableInNestedNS getRootAsTableInNestedNS(ByteBuffer _bb) { return getRootAsTableInNestedNS(_bb, new TableInNestedNS()); }
   public static TableInNestedNS getRootAsTableInNestedNS(ByteBuffer _bb, TableInNestedNS obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
   public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
@@ -38,5 +38,20 @@
     public TableInNestedNS get(int j) { return get(new TableInNestedNS(), j); }
     public TableInNestedNS get(TableInNestedNS obj, int j) {  return obj.__assign(__indirect(__element(j), bb), bb); }
   }
+  public TableInNestedNST unpack() {
+    TableInNestedNST _o = new TableInNestedNST();
+    unpackTo(_o);
+    return _o;
+  }
+  public void unpackTo(TableInNestedNST _o) {
+    int _oFoo = foo();
+    _o.setFoo(_oFoo);
+  }
+  public static int pack(FlatBufferBuilder builder, TableInNestedNST _o) {
+    if (_o == null) return 0;
+    return createTableInNestedNS(
+      builder,
+      _o.getFoo());
+  }
 }
 
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.kt b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.kt
index 0fb2e3c..cb4cc10 100644
--- a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.kt
+++ b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.kt
@@ -32,7 +32,7 @@
         }
     }
     companion object {
-        fun validateVersion() = Constants.FLATBUFFERS_1_12_0()
+        fun validateVersion() = Constants.FLATBUFFERS_2_0_0()
         fun getRootAsTableInNestedNS(_bb: ByteBuffer): TableInNestedNS = getRootAsTableInNestedNS(_bb, TableInNestedNS())
         fun getRootAsTableInNestedNS(_bb: ByteBuffer, obj: TableInNestedNS): TableInNestedNS {
             _bb.order(ByteOrder.LITTLE_ENDIAN)
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.lua b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.lua
index dd45e58..af86203 100644
--- a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.lua
+++ b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.lua
@@ -13,6 +13,9 @@
     return o
 end
 function TableInNestedNS.GetRootAsTableInNestedNS(buf, offset)
+    if type(buf) == "string" then
+        buf = flatbuffers.binaryArray.New(buf)
+    end
     local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
     local o = TableInNestedNS.New()
     o:Init(buf, n + offset)
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.py b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.py
index e86ba63..a9848d8 100644
--- a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.py
+++ b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNS.py
@@ -10,12 +10,16 @@
     __slots__ = ['_tab']
 
     @classmethod
-    def GetRootAsTableInNestedNS(cls, buf, offset):
+    def GetRootAs(cls, buf, offset=0):
         n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
         x = TableInNestedNS()
         x.Init(buf, n + offset)
         return x
 
+    @classmethod
+    def GetRootAsTableInNestedNS(cls, buf, offset=0):
+        """This method is deprecated. Please switch to GetRootAs."""
+        return cls.GetRootAs(buf, offset)
     # TableInNestedNS
     def Init(self, buf, pos):
         self._tab = flatbuffers.table.Table(buf, pos)
@@ -28,9 +32,14 @@
         return 0
 
 def TableInNestedNSStart(builder): builder.StartObject(1)
+def Start(builder):
+    return TableInNestedNSStart(builder)
 def TableInNestedNSAddFoo(builder, foo): builder.PrependInt32Slot(0, foo, 0)
+def AddFoo(builder, foo):
+    return TableInNestedNSAddFoo(builder, foo)
 def TableInNestedNSEnd(builder): return builder.EndObject()
-
+def End(builder):
+    return TableInNestedNSEnd(builder)
 
 class TableInNestedNST(object):
 
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNST.java b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNST.java
new file mode 100644
index 0000000..1968a96
--- /dev/null
+++ b/tests/namespace_test/NamespaceA/NamespaceB/TableInNestedNST.java
@@ -0,0 +1,22 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+package NamespaceA.NamespaceB;
+
+import java.nio.*;
+import java.lang.*;
+import java.util.*;
+import com.google.flatbuffers.*;
+
+public class TableInNestedNST {
+  private int foo;
+
+  public int getFoo() { return foo; }
+
+  public void setFoo(int foo) { this.foo = foo; }
+
+
+  public TableInNestedNST() {
+    this.foo = 0;
+  }
+}
+
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.cs b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.cs
new file mode 100644
index 0000000..7d1234f
--- /dev/null
+++ b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.cs
@@ -0,0 +1,78 @@
+// <auto-generated>
+//  automatically generated by the FlatBuffers compiler, do not modify
+// </auto-generated>
+
+namespace NamespaceA.NamespaceB
+{
+
+[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))]
+public enum UnionInNestedNS : byte
+{
+  NONE = 0,
+  TableInNestedNS = 1,
+};
+
+public class UnionInNestedNSUnion {
+  public UnionInNestedNS Type { get; set; }
+  public object Value { get; set; }
+
+  public UnionInNestedNSUnion() {
+    this.Type = UnionInNestedNS.NONE;
+    this.Value = null;
+  }
+
+  public T As<T>() where T : class { return this.Value as T; }
+  public NamespaceA.NamespaceB.TableInNestedNST AsTableInNestedNS() { return this.As<NamespaceA.NamespaceB.TableInNestedNST>(); }
+  public static UnionInNestedNSUnion FromTableInNestedNS(NamespaceA.NamespaceB.TableInNestedNST _tableinnestedns) { return new UnionInNestedNSUnion{ Type = UnionInNestedNS.TableInNestedNS, Value = _tableinnestedns }; }
+
+  public static int Pack(FlatBuffers.FlatBufferBuilder builder, UnionInNestedNSUnion _o) {
+    switch (_o.Type) {
+      default: return 0;
+      case UnionInNestedNS.TableInNestedNS: return NamespaceA.NamespaceB.TableInNestedNS.Pack(builder, _o.AsTableInNestedNS()).Value;
+    }
+  }
+}
+
+public class UnionInNestedNSUnion_JsonConverter : Newtonsoft.Json.JsonConverter {
+  public override bool CanConvert(System.Type objectType) {
+    return objectType == typeof(UnionInNestedNSUnion) || objectType == typeof(System.Collections.Generic.List<UnionInNestedNSUnion>);
+  }
+  public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, Newtonsoft.Json.JsonSerializer serializer) {
+    var _olist = value as System.Collections.Generic.List<UnionInNestedNSUnion>;
+    if (_olist != null) {
+      writer.WriteStartArray();
+      foreach (var _o in _olist) { this.WriteJson(writer, _o, serializer); }
+      writer.WriteEndArray();
+    } else {
+      this.WriteJson(writer, value as UnionInNestedNSUnion, serializer);
+    }
+  }
+  public void WriteJson(Newtonsoft.Json.JsonWriter writer, UnionInNestedNSUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
+    if (_o == null) return;
+    serializer.Serialize(writer, _o.Value);
+  }
+  public override object ReadJson(Newtonsoft.Json.JsonReader reader, System.Type objectType, object existingValue, Newtonsoft.Json.JsonSerializer serializer) {
+    var _olist = existingValue as System.Collections.Generic.List<UnionInNestedNSUnion>;
+    if (_olist != null) {
+      for (var _j = 0; _j < _olist.Count; ++_j) {
+        reader.Read();
+        _olist[_j] = this.ReadJson(reader, _olist[_j], serializer);
+      }
+      reader.Read();
+      return _olist;
+    } else {
+      return this.ReadJson(reader, existingValue as UnionInNestedNSUnion, serializer);
+    }
+  }
+  public UnionInNestedNSUnion ReadJson(Newtonsoft.Json.JsonReader reader, UnionInNestedNSUnion _o, Newtonsoft.Json.JsonSerializer serializer) {
+    if (_o == null) return null;
+    switch (_o.Type) {
+      default: break;
+      case UnionInNestedNS.TableInNestedNS: _o.Value = serializer.Deserialize<NamespaceA.NamespaceB.TableInNestedNST>(reader); break;
+    }
+    return _o;
+  }
+}
+
+
+}
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.go b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.go
new file mode 100644
index 0000000..f7b1d1c
--- /dev/null
+++ b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.go
@@ -0,0 +1,36 @@
+// Code generated by the FlatBuffers compiler. DO NOT EDIT.
+
+package NamespaceB
+
+import (
+	"strconv"
+
+	flatbuffers "github.com/google/flatbuffers/go"
+
+	NamespaceA__NamespaceB "NamespaceA/NamespaceB"
+)
+
+type UnionInNestedNST struct {
+	Type UnionInNestedNS
+	Value interface{}
+}
+
+func (t *UnionInNestedNST) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
+	if t == nil {
+		return 0
+	}
+	switch t.Type {
+	case UnionInNestedNSTableInNestedNS:
+		return t.Value.(*NamespaceA__NamespaceB.TableInNestedNST).Pack(builder)
+	}
+	return 0
+}
+
+func (rcv UnionInNestedNS) UnPack(table flatbuffers.Table) *UnionInNestedNST {
+	switch rcv {
+	case UnionInNestedNSTableInNestedNS:
+		x := TableInNestedNS{_tab: table}
+		return &NamespaceA__NamespaceB.UnionInNestedNST{ Type: UnionInNestedNSTableInNestedNS, Value: x.UnPack() }
+	}
+	return nil
+}
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.java b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.java
new file mode 100644
index 0000000..27f24e3
--- /dev/null
+++ b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.java
@@ -0,0 +1,15 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+package NamespaceA.NamespaceB;
+
+@SuppressWarnings("unused")
+public final class UnionInNestedNS {
+  private UnionInNestedNS() { }
+  public static final byte NONE = 0;
+  public static final byte TableInNestedNS = 1;
+
+  public static final String[] names = { "NONE", "TableInNestedNS", };
+
+  public static String name(int e) { return names[e]; }
+}
+
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.kt b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.kt
new file mode 100644
index 0000000..1c52f95
--- /dev/null
+++ b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.kt
@@ -0,0 +1,14 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+package NamespaceA.NamespaceB
+
+@Suppress("unused")
+@ExperimentalUnsignedTypes
+class UnionInNestedNS private constructor() {
+    companion object {
+        const val NONE: UByte = 0u
+        const val TableInNestedNS: UByte = 1u
+        val names : Array<String> = arrayOf("NONE", "TableInNestedNS")
+        fun name(e: Int) : String = names[e]
+    }
+}
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.lua b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.lua
new file mode 100644
index 0000000..30bc93e
--- /dev/null
+++ b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.lua
@@ -0,0 +1,10 @@
+-- automatically generated by the FlatBuffers compiler, do not modify
+
+-- namespace: NamespaceB
+
+local UnionInNestedNS = {
+    NONE = 0,
+    TableInNestedNS = 1,
+}
+
+return UnionInNestedNS -- return the module
\ No newline at end of file
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.php b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.php
new file mode 100644
index 0000000..ff948d7
--- /dev/null
+++ b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.php
@@ -0,0 +1,23 @@
+<?php
+// automatically generated by the FlatBuffers compiler, do not modify
+
+namespace NamespaceA\NamespaceB;
+
+class UnionInNestedNS
+{
+    const NONE = 0;
+    const TableInNestedNS = 1;
+
+    private static $names = array(
+        UnionInNestedNS::NONE=>"NONE",
+        UnionInNestedNS::TableInNestedNS=>"TableInNestedNS",
+    );
+
+    public static function Name($e)
+    {
+        if (!isset(self::$names[$e])) {
+            throw new \Exception();
+        }
+        return self::$names[$e];
+    }
+}
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.py b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.py
new file mode 100644
index 0000000..af601c7
--- /dev/null
+++ b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNS.py
@@ -0,0 +1,15 @@
+# automatically generated by the FlatBuffers compiler, do not modify
+
+# namespace: NamespaceB
+
+class UnionInNestedNS(object):
+    NONE = 0
+    TableInNestedNS = 1
+
+def UnionInNestedNSCreator(unionType, table):
+    from flatbuffers.table import Table
+    if not isinstance(table, Table):
+        return None
+    if unionType == UnionInNestedNS().TableInNestedNS:
+        return TableInNestedNST.InitFromBuf(table.Bytes, table.Pos)
+    return None
diff --git a/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNSUnion.java b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNSUnion.java
new file mode 100644
index 0000000..5b89938
--- /dev/null
+++ b/tests/namespace_test/NamespaceA/NamespaceB/UnionInNestedNSUnion.java
@@ -0,0 +1,33 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+package NamespaceA.NamespaceB;
+
+import com.google.flatbuffers.FlatBufferBuilder;
+
+public class UnionInNestedNSUnion {
+  private byte type;
+  private Object value;
+
+  public byte getType() { return type; }
+
+  public void setType(byte type) { this.type = type; }
+
+  public Object getValue() { return value; }
+
+  public void setValue(Object value) { this.value = value; }
+
+  public UnionInNestedNSUnion() {
+    this.type = UnionInNestedNS.NONE;
+    this.value = null;
+  }
+
+  public NamespaceA.NamespaceB.TableInNestedNST asTableInNestedNS() { return (NamespaceA.NamespaceB.TableInNestedNST) value; }
+
+  public static int pack(FlatBufferBuilder builder, UnionInNestedNSUnion _o) {
+    switch (_o.type) {
+      case UnionInNestedNS.TableInNestedNS: return NamespaceA.NamespaceB.TableInNestedNS.pack(builder, _o.asTableInNestedNS());
+      default: return 0;
+    }
+  }
+}
+
diff --git a/tests/namespace_test/NamespaceA/SecondTableInA.cs b/tests/namespace_test/NamespaceA/SecondTableInA.cs
index a949c61..6e7ef88 100644
--- a/tests/namespace_test/NamespaceA/SecondTableInA.cs
+++ b/tests/namespace_test/NamespaceA/SecondTableInA.cs
@@ -13,7 +13,7 @@
 {
   private Table __p;
   public ByteBuffer ByteBuffer { get { return __p.bb; } }
-  public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_1_12_0(); }
+  public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_2_0_0(); }
   public static SecondTableInA GetRootAsSecondTableInA(ByteBuffer _bb) { return GetRootAsSecondTableInA(_bb, new SecondTableInA()); }
   public static SecondTableInA GetRootAsSecondTableInA(ByteBuffer _bb, SecondTableInA obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
   public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
@@ -49,7 +49,7 @@
       builder,
       _refer_to_c);
   }
-};
+}
 
 public class SecondTableInAT
 {
diff --git a/tests/namespace_test/NamespaceA/SecondTableInA.java b/tests/namespace_test/NamespaceA/SecondTableInA.java
index ec6e561..ff539ab 100644
--- a/tests/namespace_test/NamespaceA/SecondTableInA.java
+++ b/tests/namespace_test/NamespaceA/SecondTableInA.java
@@ -9,7 +9,7 @@
 
 @SuppressWarnings("unused")
 public final class SecondTableInA extends Table {
-  public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); }
+  public static void ValidateVersion() { Constants.FLATBUFFERS_2_0_0(); }
   public static SecondTableInA getRootAsSecondTableInA(ByteBuffer _bb) { return getRootAsSecondTableInA(_bb, new SecondTableInA()); }
   public static SecondTableInA getRootAsSecondTableInA(ByteBuffer _bb, SecondTableInA obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
   public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
@@ -19,9 +19,9 @@
   public NamespaceC.TableInC referToC(NamespaceC.TableInC obj) { int o = __offset(4); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; }
 
   public static int createSecondTableInA(FlatBufferBuilder builder,
-      int refer_to_cOffset) {
+      int referToCOffset) {
     builder.startTable(1);
-    SecondTableInA.addReferToC(builder, refer_to_cOffset);
+    SecondTableInA.addReferToC(builder, referToCOffset);
     return SecondTableInA.endSecondTableInA(builder);
   }
 
@@ -38,5 +38,21 @@
     public SecondTableInA get(int j) { return get(new SecondTableInA(), j); }
     public SecondTableInA get(SecondTableInA obj, int j) {  return obj.__assign(__indirect(__element(j), bb), bb); }
   }
+  public SecondTableInAT unpack() {
+    SecondTableInAT _o = new SecondTableInAT();
+    unpackTo(_o);
+    return _o;
+  }
+  public void unpackTo(SecondTableInAT _o) {
+    if (referToC() != null) _o.setReferToC(referToC().unpack());
+    else _o.setReferToC(null);
+  }
+  public static int pack(FlatBufferBuilder builder, SecondTableInAT _o) {
+    if (_o == null) return 0;
+    int _refer_to_c = _o.getReferToC() == null ? 0 : NamespaceC.TableInC.pack(builder, _o.getReferToC());
+    return createSecondTableInA(
+      builder,
+      _refer_to_c);
+  }
 }
 
diff --git a/tests/namespace_test/NamespaceA/SecondTableInA.kt b/tests/namespace_test/NamespaceA/SecondTableInA.kt
index 5b41f73..a516070 100644
--- a/tests/namespace_test/NamespaceA/SecondTableInA.kt
+++ b/tests/namespace_test/NamespaceA/SecondTableInA.kt
@@ -27,7 +27,7 @@
         }
     }
     companion object {
-        fun validateVersion() = Constants.FLATBUFFERS_1_12_0()
+        fun validateVersion() = Constants.FLATBUFFERS_2_0_0()
         fun getRootAsSecondTableInA(_bb: ByteBuffer): SecondTableInA = getRootAsSecondTableInA(_bb, SecondTableInA())
         fun getRootAsSecondTableInA(_bb: ByteBuffer, obj: SecondTableInA): SecondTableInA {
             _bb.order(ByteOrder.LITTLE_ENDIAN)
diff --git a/tests/namespace_test/NamespaceA/SecondTableInA.lua b/tests/namespace_test/NamespaceA/SecondTableInA.lua
index 9a60e4b..b953c12 100644
--- a/tests/namespace_test/NamespaceA/SecondTableInA.lua
+++ b/tests/namespace_test/NamespaceA/SecondTableInA.lua
@@ -13,6 +13,9 @@
     return o
 end
 function SecondTableInA.GetRootAsSecondTableInA(buf, offset)
+    if type(buf) == "string" then
+        buf = flatbuffers.binaryArray.New(buf)
+    end
     local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
     local o = SecondTableInA.New()
     o:Init(buf, n + offset)
diff --git a/tests/namespace_test/NamespaceA/SecondTableInA.py b/tests/namespace_test/NamespaceA/SecondTableInA.py
index 5aaa8ed..474f44d 100644
--- a/tests/namespace_test/NamespaceA/SecondTableInA.py
+++ b/tests/namespace_test/NamespaceA/SecondTableInA.py
@@ -10,12 +10,16 @@
     __slots__ = ['_tab']
 
     @classmethod
-    def GetRootAsSecondTableInA(cls, buf, offset):
+    def GetRootAs(cls, buf, offset=0):
         n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
         x = SecondTableInA()
         x.Init(buf, n + offset)
         return x
 
+    @classmethod
+    def GetRootAsSecondTableInA(cls, buf, offset=0):
+        """This method is deprecated. Please switch to GetRootAs."""
+        return cls.GetRootAs(buf, offset)
     # SecondTableInA
     def Init(self, buf, pos):
         self._tab = flatbuffers.table.Table(buf, pos)
@@ -31,9 +35,14 @@
         return None
 
 def SecondTableInAStart(builder): builder.StartObject(1)
+def Start(builder):
+    return SecondTableInAStart(builder)
 def SecondTableInAAddReferToC(builder, referToC): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(referToC), 0)
+def AddReferToC(builder, referToC):
+    return SecondTableInAAddReferToC(builder, referToC)
 def SecondTableInAEnd(builder): return builder.EndObject()
-
+def End(builder):
+    return SecondTableInAEnd(builder)
 try:
     from typing import Optional
 except:
diff --git a/tests/namespace_test/NamespaceA/SecondTableInAT.java b/tests/namespace_test/NamespaceA/SecondTableInAT.java
new file mode 100644
index 0000000..98fe21c
--- /dev/null
+++ b/tests/namespace_test/NamespaceA/SecondTableInAT.java
@@ -0,0 +1,22 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+package NamespaceA;
+
+import java.nio.*;
+import java.lang.*;
+import java.util.*;
+import com.google.flatbuffers.*;
+
+public class SecondTableInAT {
+  private NamespaceC.TableInCT referToC;
+
+  public NamespaceC.TableInCT getReferToC() { return referToC; }
+
+  public void setReferToC(NamespaceC.TableInCT referToC) { this.referToC = referToC; }
+
+
+  public SecondTableInAT() {
+    this.referToC = null;
+  }
+}
+
diff --git a/tests/namespace_test/NamespaceA/TableInFirstNS.cs b/tests/namespace_test/NamespaceA/TableInFirstNS.cs
index 3d597d7..6522f49 100644
--- a/tests/namespace_test/NamespaceA/TableInFirstNS.cs
+++ b/tests/namespace_test/NamespaceA/TableInFirstNS.cs
@@ -13,7 +13,7 @@
 {
   private Table __p;
   public ByteBuffer ByteBuffer { get { return __p.bb; } }
-  public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_1_12_0(); }
+  public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_2_0_0(); }
   public static TableInFirstNS GetRootAsTableInFirstNS(ByteBuffer _bb) { return GetRootAsTableInFirstNS(_bb, new TableInFirstNS()); }
   public static TableInFirstNS GetRootAsTableInFirstNS(ByteBuffer _bb, TableInFirstNS obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
   public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
@@ -22,23 +22,32 @@
   public NamespaceA.NamespaceB.TableInNestedNS? FooTable { get { int o = __p.__offset(4); return o != 0 ? (NamespaceA.NamespaceB.TableInNestedNS?)(new NamespaceA.NamespaceB.TableInNestedNS()).__assign(__p.__indirect(o + __p.bb_pos), __p.bb) : null; } }
   public NamespaceA.NamespaceB.EnumInNestedNS FooEnum { get { int o = __p.__offset(6); return o != 0 ? (NamespaceA.NamespaceB.EnumInNestedNS)__p.bb.GetSbyte(o + __p.bb_pos) : NamespaceA.NamespaceB.EnumInNestedNS.A; } }
   public bool MutateFooEnum(NamespaceA.NamespaceB.EnumInNestedNS foo_enum) { int o = __p.__offset(6); if (o != 0) { __p.bb.PutSbyte(o + __p.bb_pos, (sbyte)foo_enum); return true; } else { return false; } }
-  public NamespaceA.NamespaceB.StructInNestedNS? FooStruct { get { int o = __p.__offset(8); return o != 0 ? (NamespaceA.NamespaceB.StructInNestedNS?)(new NamespaceA.NamespaceB.StructInNestedNS()).__assign(o + __p.bb_pos, __p.bb) : null; } }
+  public NamespaceA.NamespaceB.UnionInNestedNS FooUnionType { get { int o = __p.__offset(8); return o != 0 ? (NamespaceA.NamespaceB.UnionInNestedNS)__p.bb.Get(o + __p.bb_pos) : NamespaceA.NamespaceB.UnionInNestedNS.NONE; } }
+  public TTable? FooUnion<TTable>() where TTable : struct, IFlatbufferObject { int o = __p.__offset(10); return o != 0 ? (TTable?)__p.__union<TTable>(o + __p.bb_pos) : null; }
+  public NamespaceA.NamespaceB.TableInNestedNS FooUnionAsTableInNestedNS() { return FooUnion<NamespaceA.NamespaceB.TableInNestedNS>().Value; }
+  public NamespaceA.NamespaceB.StructInNestedNS? FooStruct { get { int o = __p.__offset(12); return o != 0 ? (NamespaceA.NamespaceB.StructInNestedNS?)(new NamespaceA.NamespaceB.StructInNestedNS()).__assign(o + __p.bb_pos, __p.bb) : null; } }
 
   public static Offset<NamespaceA.TableInFirstNS> CreateTableInFirstNS(FlatBufferBuilder builder,
       Offset<NamespaceA.NamespaceB.TableInNestedNS> foo_tableOffset = default(Offset<NamespaceA.NamespaceB.TableInNestedNS>),
       NamespaceA.NamespaceB.EnumInNestedNS foo_enum = NamespaceA.NamespaceB.EnumInNestedNS.A,
+      NamespaceA.NamespaceB.UnionInNestedNS foo_union_type = NamespaceA.NamespaceB.UnionInNestedNS.NONE,
+      int foo_unionOffset = 0,
       NamespaceA.NamespaceB.StructInNestedNST foo_struct = null) {
-    builder.StartTable(3);
+    builder.StartTable(5);
     TableInFirstNS.AddFooStruct(builder, NamespaceA.NamespaceB.StructInNestedNS.Pack(builder, foo_struct));
+    TableInFirstNS.AddFooUnion(builder, foo_unionOffset);
     TableInFirstNS.AddFooTable(builder, foo_tableOffset);
+    TableInFirstNS.AddFooUnionType(builder, foo_union_type);
     TableInFirstNS.AddFooEnum(builder, foo_enum);
     return TableInFirstNS.EndTableInFirstNS(builder);
   }
 
-  public static void StartTableInFirstNS(FlatBufferBuilder builder) { builder.StartTable(3); }
+  public static void StartTableInFirstNS(FlatBufferBuilder builder) { builder.StartTable(5); }
   public static void AddFooTable(FlatBufferBuilder builder, Offset<NamespaceA.NamespaceB.TableInNestedNS> fooTableOffset) { builder.AddOffset(0, fooTableOffset.Value, 0); }
   public static void AddFooEnum(FlatBufferBuilder builder, NamespaceA.NamespaceB.EnumInNestedNS fooEnum) { builder.AddSbyte(1, (sbyte)fooEnum, 0); }
-  public static void AddFooStruct(FlatBufferBuilder builder, Offset<NamespaceA.NamespaceB.StructInNestedNS> fooStructOffset) { builder.AddStruct(2, fooStructOffset.Value, 0); }
+  public static void AddFooUnionType(FlatBufferBuilder builder, NamespaceA.NamespaceB.UnionInNestedNS fooUnionType) { builder.AddByte(2, (byte)fooUnionType, 0); }
+  public static void AddFooUnion(FlatBufferBuilder builder, int fooUnionOffset) { builder.AddOffset(3, fooUnionOffset, 0); }
+  public static void AddFooStruct(FlatBufferBuilder builder, Offset<NamespaceA.NamespaceB.StructInNestedNS> fooStructOffset) { builder.AddStruct(4, fooStructOffset.Value, 0); }
   public static Offset<NamespaceA.TableInFirstNS> EndTableInFirstNS(FlatBufferBuilder builder) {
     int o = builder.EndTable();
     return new Offset<NamespaceA.TableInFirstNS>(o);
@@ -51,18 +60,30 @@
   public void UnPackTo(TableInFirstNST _o) {
     _o.FooTable = this.FooTable.HasValue ? this.FooTable.Value.UnPack() : null;
     _o.FooEnum = this.FooEnum;
+    _o.FooUnion = new NamespaceA.NamespaceB.UnionInNestedNSUnion();
+    _o.FooUnion.Type = this.FooUnionType;
+    switch (this.FooUnionType) {
+      default: break;
+      case NamespaceA.NamespaceB.UnionInNestedNS.TableInNestedNS:
+        _o.FooUnion.Value = this.FooUnion<NamespaceA.NamespaceB.TableInNestedNS>().HasValue ? this.FooUnion<NamespaceA.NamespaceB.TableInNestedNS>().Value.UnPack() : null;
+        break;
+    }
     _o.FooStruct = this.FooStruct.HasValue ? this.FooStruct.Value.UnPack() : null;
   }
   public static Offset<NamespaceA.TableInFirstNS> Pack(FlatBufferBuilder builder, TableInFirstNST _o) {
     if (_o == null) return default(Offset<NamespaceA.TableInFirstNS>);
     var _foo_table = _o.FooTable == null ? default(Offset<NamespaceA.NamespaceB.TableInNestedNS>) : NamespaceA.NamespaceB.TableInNestedNS.Pack(builder, _o.FooTable);
+    var _foo_union_type = _o.FooUnion == null ? NamespaceA.NamespaceB.UnionInNestedNS.NONE : _o.FooUnion.Type;
+    var _foo_union = _o.FooUnion == null ? 0 : NamespaceA.NamespaceB.UnionInNestedNSUnion.Pack(builder, _o.FooUnion);
     return CreateTableInFirstNS(
       builder,
       _foo_table,
       _o.FooEnum,
+      _foo_union_type,
+      _foo_union,
       _o.FooStruct);
   }
-};
+}
 
 public class TableInFirstNST
 {
@@ -70,12 +91,26 @@
   public NamespaceA.NamespaceB.TableInNestedNST FooTable { get; set; }
   [Newtonsoft.Json.JsonProperty("foo_enum")]
   public NamespaceA.NamespaceB.EnumInNestedNS FooEnum { get; set; }
+  [Newtonsoft.Json.JsonProperty("foo_union_type")]
+  private NamespaceA.NamespaceB.UnionInNestedNS FooUnionType {
+    get {
+      return this.FooUnion != null ? this.FooUnion.Type : NamespaceA.NamespaceB.UnionInNestedNS.NONE;
+    }
+    set {
+      this.FooUnion = new NamespaceA.NamespaceB.UnionInNestedNSUnion();
+      this.FooUnion.Type = value;
+    }
+  }
+  [Newtonsoft.Json.JsonProperty("foo_union")]
+  [Newtonsoft.Json.JsonConverter(typeof(NamespaceA.NamespaceB.UnionInNestedNSUnion_JsonConverter))]
+  public NamespaceA.NamespaceB.UnionInNestedNSUnion FooUnion { get; set; }
   [Newtonsoft.Json.JsonProperty("foo_struct")]
   public NamespaceA.NamespaceB.StructInNestedNST FooStruct { get; set; }
 
   public TableInFirstNST() {
     this.FooTable = null;
     this.FooEnum = NamespaceA.NamespaceB.EnumInNestedNS.A;
+    this.FooUnion = null;
     this.FooStruct = new NamespaceA.NamespaceB.StructInNestedNST();
   }
 }
diff --git a/tests/namespace_test/NamespaceA/TableInFirstNS.go b/tests/namespace_test/NamespaceA/TableInFirstNS.go
index 7f419b8..3feaaaa 100644
--- a/tests/namespace_test/NamespaceA/TableInFirstNS.go
+++ b/tests/namespace_test/NamespaceA/TableInFirstNS.go
@@ -11,15 +11,22 @@
 type TableInFirstNST struct {
 	FooTable *NamespaceA__NamespaceB.TableInNestedNST
 	FooEnum NamespaceA__NamespaceB.EnumInNestedNS
+	FooUnion *NamespaceA__NamespaceB.UnionInNestedNST
 	FooStruct *NamespaceA__NamespaceB.StructInNestedNST
 }
 
 func (t *TableInFirstNST) Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
 	if t == nil { return 0 }
 	fooTableOffset := t.FooTable.Pack(builder)
+	fooUnionOffset := t.FooUnion.Pack(builder)
+	
 	TableInFirstNSStart(builder)
 	TableInFirstNSAddFooTable(builder, fooTableOffset)
 	TableInFirstNSAddFooEnum(builder, t.FooEnum)
+	if t.FooUnion != nil {
+		TableInFirstNSAddFooUnionType(builder, t.FooUnion.Type)
+	}
+	TableInFirstNSAddFooUnion(builder, fooUnionOffset)
 	fooStructOffset := t.FooStruct.Pack(builder)
 	TableInFirstNSAddFooStruct(builder, fooStructOffset)
 	return TableInFirstNSEnd(builder)
@@ -28,6 +35,10 @@
 func (rcv *TableInFirstNS) UnPackTo(t *TableInFirstNST) {
 	t.FooTable = rcv.FooTable(nil).UnPack()
 	t.FooEnum = rcv.FooEnum()
+	fooUnionTable := flatbuffers.Table{}
+	if rcv.FooUnion(&fooUnionTable) {
+		t.FooUnion = rcv.FooUnionType().UnPack(fooUnionTable)
+	}
 	t.FooStruct = rcv.FooStruct(nil).UnPack()
 }
 
@@ -90,9 +101,30 @@
 	return rcv._tab.MutateInt8Slot(6, int8(n))
 }
 
-func (rcv *TableInFirstNS) FooStruct(obj *NamespaceA__NamespaceB.StructInNestedNS) *NamespaceA__NamespaceB.StructInNestedNS {
+func (rcv *TableInFirstNS) FooUnionType() NamespaceA__NamespaceB.UnionInNestedNS {
 	o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
 	if o != 0 {
+		return NamespaceA__NamespaceB.UnionInNestedNS(rcv._tab.GetByte(o + rcv._tab.Pos))
+	}
+	return 0
+}
+
+func (rcv *TableInFirstNS) MutateFooUnionType(n NamespaceA__NamespaceB.UnionInNestedNS) bool {
+	return rcv._tab.MutateByteSlot(8, byte(n))
+}
+
+func (rcv *TableInFirstNS) FooUnion(obj *flatbuffers.Table) bool {
+	o := flatbuffers.UOffsetT(rcv._tab.Offset(10))
+	if o != 0 {
+		rcv._tab.Union(obj, o)
+		return true
+	}
+	return false
+}
+
+func (rcv *TableInFirstNS) FooStruct(obj *NamespaceA__NamespaceB.StructInNestedNS) *NamespaceA__NamespaceB.StructInNestedNS {
+	o := flatbuffers.UOffsetT(rcv._tab.Offset(12))
+	if o != 0 {
 		x := o + rcv._tab.Pos
 		if obj == nil {
 			obj = new(NamespaceA__NamespaceB.StructInNestedNS)
@@ -104,7 +136,7 @@
 }
 
 func TableInFirstNSStart(builder *flatbuffers.Builder) {
-	builder.StartObject(3)
+	builder.StartObject(5)
 }
 func TableInFirstNSAddFooTable(builder *flatbuffers.Builder, fooTable flatbuffers.UOffsetT) {
 	builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(fooTable), 0)
@@ -112,8 +144,14 @@
 func TableInFirstNSAddFooEnum(builder *flatbuffers.Builder, fooEnum NamespaceA__NamespaceB.EnumInNestedNS) {
 	builder.PrependInt8Slot(1, int8(fooEnum), 0)
 }
+func TableInFirstNSAddFooUnionType(builder *flatbuffers.Builder, fooUnionType NamespaceA__NamespaceB.UnionInNestedNS) {
+	builder.PrependByteSlot(2, byte(fooUnionType), 0)
+}
+func TableInFirstNSAddFooUnion(builder *flatbuffers.Builder, fooUnion flatbuffers.UOffsetT) {
+	builder.PrependUOffsetTSlot(3, flatbuffers.UOffsetT(fooUnion), 0)
+}
 func TableInFirstNSAddFooStruct(builder *flatbuffers.Builder, fooStruct flatbuffers.UOffsetT) {
-	builder.PrependStructSlot(2, flatbuffers.UOffsetT(fooStruct), 0)
+	builder.PrependStructSlot(4, flatbuffers.UOffsetT(fooStruct), 0)
 }
 func TableInFirstNSEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
 	return builder.EndObject()
diff --git a/tests/namespace_test/NamespaceA/TableInFirstNS.java b/tests/namespace_test/NamespaceA/TableInFirstNS.java
index f04d9e9..2fdfec8 100644
--- a/tests/namespace_test/NamespaceA/TableInFirstNS.java
+++ b/tests/namespace_test/NamespaceA/TableInFirstNS.java
@@ -9,7 +9,7 @@
 
 @SuppressWarnings("unused")
 public final class TableInFirstNS extends Table {
-  public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); }
+  public static void ValidateVersion() { Constants.FLATBUFFERS_2_0_0(); }
   public static TableInFirstNS getRootAsTableInFirstNS(ByteBuffer _bb) { return getRootAsTableInFirstNS(_bb, new TableInFirstNS()); }
   public static TableInFirstNS getRootAsTableInFirstNS(ByteBuffer _bb, TableInFirstNS obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
   public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
@@ -19,13 +19,17 @@
   public NamespaceA.NamespaceB.TableInNestedNS fooTable(NamespaceA.NamespaceB.TableInNestedNS obj) { int o = __offset(4); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; }
   public byte fooEnum() { int o = __offset(6); return o != 0 ? bb.get(o + bb_pos) : 0; }
   public boolean mutateFooEnum(byte foo_enum) { int o = __offset(6); if (o != 0) { bb.put(o + bb_pos, foo_enum); return true; } else { return false; } }
+  public byte fooUnionType() { int o = __offset(8); return o != 0 ? bb.get(o + bb_pos) : 0; }
+  public Table fooUnion(Table obj) { int o = __offset(10); return o != 0 ? __union(obj, o + bb_pos) : null; }
   public NamespaceA.NamespaceB.StructInNestedNS fooStruct() { return fooStruct(new NamespaceA.NamespaceB.StructInNestedNS()); }
-  public NamespaceA.NamespaceB.StructInNestedNS fooStruct(NamespaceA.NamespaceB.StructInNestedNS obj) { int o = __offset(8); return o != 0 ? obj.__assign(o + bb_pos, bb) : null; }
+  public NamespaceA.NamespaceB.StructInNestedNS fooStruct(NamespaceA.NamespaceB.StructInNestedNS obj) { int o = __offset(12); return o != 0 ? obj.__assign(o + bb_pos, bb) : null; }
 
-  public static void startTableInFirstNS(FlatBufferBuilder builder) { builder.startTable(3); }
+  public static void startTableInFirstNS(FlatBufferBuilder builder) { builder.startTable(5); }
   public static void addFooTable(FlatBufferBuilder builder, int fooTableOffset) { builder.addOffset(0, fooTableOffset, 0); }
   public static void addFooEnum(FlatBufferBuilder builder, byte fooEnum) { builder.addByte(1, fooEnum, 0); }
-  public static void addFooStruct(FlatBufferBuilder builder, int fooStructOffset) { builder.addStruct(2, fooStructOffset, 0); }
+  public static void addFooUnionType(FlatBufferBuilder builder, byte fooUnionType) { builder.addByte(2, fooUnionType, 0); }
+  public static void addFooUnion(FlatBufferBuilder builder, int fooUnionOffset) { builder.addOffset(3, fooUnionOffset, 0); }
+  public static void addFooStruct(FlatBufferBuilder builder, int fooStructOffset) { builder.addStruct(4, fooStructOffset, 0); }
   public static int endTableInFirstNS(FlatBufferBuilder builder) {
     int o = builder.endTable();
     return o;
@@ -37,5 +41,43 @@
     public TableInFirstNS get(int j) { return get(new TableInFirstNS(), j); }
     public TableInFirstNS get(TableInFirstNS obj, int j) {  return obj.__assign(__indirect(__element(j), bb), bb); }
   }
+  public TableInFirstNST unpack() {
+    TableInFirstNST _o = new TableInFirstNST();
+    unpackTo(_o);
+    return _o;
+  }
+  public void unpackTo(TableInFirstNST _o) {
+    if (fooTable() != null) _o.setFooTable(fooTable().unpack());
+    else _o.setFooTable(null);
+    byte _oFooEnum = fooEnum();
+    _o.setFooEnum(_oFooEnum);
+    NamespaceA.NamespaceB.UnionInNestedNSUnion _oFooUnion = new NamespaceA.NamespaceB.UnionInNestedNSUnion();
+    byte _oFooUnionType = fooUnionType();
+    _oFooUnion.setType(_oFooUnionType);
+    Table _oFooUnionValue;
+    switch (_oFooUnionType) {
+      case NamespaceA.NamespaceB.UnionInNestedNS.TableInNestedNS:
+        _oFooUnionValue = fooUnion(new NamespaceA.NamespaceB.TableInNestedNS());
+        _oFooUnion.setValue(_oFooUnionValue != null ? ((NamespaceA.NamespaceB.TableInNestedNS) _oFooUnionValue).unpack() : null);
+        break;
+      default: break;
+    }
+    _o.setFooUnion(_oFooUnion);
+    if (fooStruct() != null) fooStruct().unpackTo(_o.getFooStruct());
+    else _o.setFooStruct(null);
+  }
+  public static int pack(FlatBufferBuilder builder, TableInFirstNST _o) {
+    if (_o == null) return 0;
+    int _foo_table = _o.getFooTable() == null ? 0 : NamespaceA.NamespaceB.TableInNestedNS.pack(builder, _o.getFooTable());
+    byte _fooUnionType = _o.getFooUnion() == null ? NamespaceA.NamespaceB.UnionInNestedNS.NONE : _o.getFooUnion().getType();
+    int _fooUnion = _o.getFooUnion() == null ? 0 : NamespaceA.NamespaceB.UnionInNestedNSUnion.pack(builder, _o.getFooUnion());
+    startTableInFirstNS(builder);
+    addFooTable(builder, _foo_table);
+    addFooEnum(builder, _o.getFooEnum());
+    addFooUnionType(builder, _fooUnionType);
+    addFooUnion(builder, _fooUnion);
+    addFooStruct(builder, NamespaceA.NamespaceB.StructInNestedNS.pack(builder, _o.getFooStruct()));
+    return endTableInFirstNS(builder);
+  }
 }
 
diff --git a/tests/namespace_test/NamespaceA/TableInFirstNS.kt b/tests/namespace_test/NamespaceA/TableInFirstNS.kt
index febe050..bec3319 100644
--- a/tests/namespace_test/NamespaceA/TableInFirstNS.kt
+++ b/tests/namespace_test/NamespaceA/TableInFirstNS.kt
@@ -40,9 +40,26 @@
             false
         }
     }
+    val fooUnionType : UByte
+        get() {
+            val o = __offset(8)
+            return if(o != 0) bb.get(o + bb_pos).toUByte() else 0u
+        }
+    fun mutateFooUnionType(fooUnionType: UByte) : Boolean {
+        val o = __offset(8)
+        return if (o != 0) {
+            bb.put(o + bb_pos, fooUnionType.toByte())
+            true
+        } else {
+            false
+        }
+    }
+    fun fooUnion(obj: Table) : Table? {
+        val o = __offset(10); return if (o != 0) __union(obj, o + bb_pos) else null
+    }
     val fooStruct : NamespaceA.NamespaceB.StructInNestedNS? get() = fooStruct(NamespaceA.NamespaceB.StructInNestedNS())
     fun fooStruct(obj: NamespaceA.NamespaceB.StructInNestedNS) : NamespaceA.NamespaceB.StructInNestedNS? {
-        val o = __offset(8)
+        val o = __offset(12)
         return if (o != 0) {
             obj.__assign(o + bb_pos, bb)
         } else {
@@ -50,16 +67,18 @@
         }
     }
     companion object {
-        fun validateVersion() = Constants.FLATBUFFERS_1_12_0()
+        fun validateVersion() = Constants.FLATBUFFERS_2_0_0()
         fun getRootAsTableInFirstNS(_bb: ByteBuffer): TableInFirstNS = getRootAsTableInFirstNS(_bb, TableInFirstNS())
         fun getRootAsTableInFirstNS(_bb: ByteBuffer, obj: TableInFirstNS): TableInFirstNS {
             _bb.order(ByteOrder.LITTLE_ENDIAN)
             return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb))
         }
-        fun startTableInFirstNS(builder: FlatBufferBuilder) = builder.startTable(3)
+        fun startTableInFirstNS(builder: FlatBufferBuilder) = builder.startTable(5)
         fun addFooTable(builder: FlatBufferBuilder, fooTable: Int) = builder.addOffset(0, fooTable, 0)
         fun addFooEnum(builder: FlatBufferBuilder, fooEnum: Byte) = builder.addByte(1, fooEnum, 0)
-        fun addFooStruct(builder: FlatBufferBuilder, fooStruct: Int) = builder.addStruct(2, fooStruct, 0)
+        fun addFooUnionType(builder: FlatBufferBuilder, fooUnionType: UByte) = builder.addByte(2, fooUnionType.toByte(), 0)
+        fun addFooUnion(builder: FlatBufferBuilder, fooUnion: Int) = builder.addOffset(3, fooUnion, 0)
+        fun addFooStruct(builder: FlatBufferBuilder, fooStruct: Int) = builder.addStruct(4, fooStruct, 0)
         fun endTableInFirstNS(builder: FlatBufferBuilder) : Int {
             val o = builder.endTable()
             return o
diff --git a/tests/namespace_test/NamespaceA/TableInFirstNS.lua b/tests/namespace_test/NamespaceA/TableInFirstNS.lua
index f70f2c7..1b62cc5 100644
--- a/tests/namespace_test/NamespaceA/TableInFirstNS.lua
+++ b/tests/namespace_test/NamespaceA/TableInFirstNS.lua
@@ -13,6 +13,9 @@
     return o
 end
 function TableInFirstNS.GetRootAsTableInFirstNS(buf, offset)
+    if type(buf) == "string" then
+        buf = flatbuffers.binaryArray.New(buf)
+    end
     local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
     local o = TableInFirstNS.New()
     o:Init(buf, n + offset)
@@ -37,19 +40,36 @@
     end
     return 0
 end
-function TableInFirstNS_mt:FooStruct()
+function TableInFirstNS_mt:FooUnionType()
     local o = self.view:Offset(8)
     if o ~= 0 then
+        return self.view:Get(flatbuffers.N.Uint8, o + self.view.pos)
+    end
+    return 0
+end
+function TableInFirstNS_mt:FooUnion()
+    local o = self.view:Offset(10)
+    if o ~= 0 then
+        local obj = flatbuffers.view.New(require('flatbuffers.binaryarray').New(0), 0)
+        self.view:Union(obj, o)
+        return obj
+    end
+end
+function TableInFirstNS_mt:FooStruct()
+    local o = self.view:Offset(12)
+    if o ~= 0 then
         local x = o + self.view.pos
         local obj = require('NamespaceA.NamespaceB.StructInNestedNS').New()
         obj:Init(self.view.bytes, x)
         return obj
     end
 end
-function TableInFirstNS.Start(builder) builder:StartObject(3) end
+function TableInFirstNS.Start(builder) builder:StartObject(5) end
 function TableInFirstNS.AddFooTable(builder, fooTable) builder:PrependUOffsetTRelativeSlot(0, fooTable, 0) end
 function TableInFirstNS.AddFooEnum(builder, fooEnum) builder:PrependInt8Slot(1, fooEnum, 0) end
-function TableInFirstNS.AddFooStruct(builder, fooStruct) builder:PrependStructSlot(2, fooStruct, 0) end
+function TableInFirstNS.AddFooUnionType(builder, fooUnionType) builder:PrependUint8Slot(2, fooUnionType, 0) end
+function TableInFirstNS.AddFooUnion(builder, fooUnion) builder:PrependUOffsetTRelativeSlot(3, fooUnion, 0) end
+function TableInFirstNS.AddFooStruct(builder, fooStruct) builder:PrependStructSlot(4, fooStruct, 0) end
 function TableInFirstNS.End(builder) return builder:EndObject() end
 
 return TableInFirstNS -- return the module
\ No newline at end of file
diff --git a/tests/namespace_test/NamespaceA/TableInFirstNS.php b/tests/namespace_test/NamespaceA/TableInFirstNS.php
index 9fb29c3..637ead5 100644
--- a/tests/namespace_test/NamespaceA/TableInFirstNS.php
+++ b/tests/namespace_test/NamespaceA/TableInFirstNS.php
@@ -48,10 +48,28 @@
         return $o != 0 ? $this->bb->getSbyte($o + $this->bb_pos) : \NamespaceA\NamespaceB\EnumInNestedNS::A;
     }
 
+    /**
+     * @return byte
+     */
+    public function getFooUnionType()
+    {
+        $o = $this->__offset(8);
+        return $o != 0 ? $this->bb->getByte($o + $this->bb_pos) : \NamespaceA\NamespaceB\UnionInNestedNS::NONE;
+    }
+
+    /**
+     * @returnint
+     */
+    public function getFooUnion($obj)
+    {
+        $o = $this->__offset(10);
+        return $o != 0 ? $this->__union($obj, $o) : null;
+    }
+
     public function getFooStruct()
     {
         $obj = new StructInNestedNS();
-        $o = $this->__offset(8);
+        $o = $this->__offset(12);
         return $o != 0 ? $obj->init($o + $this->bb_pos, $this->bb) : 0;
     }
 
@@ -61,18 +79,20 @@
      */
     public static function startTableInFirstNS(FlatBufferBuilder $builder)
     {
-        $builder->StartObject(3);
+        $builder->StartObject(5);
     }
 
     /**
      * @param FlatBufferBuilder $builder
      * @return TableInFirstNS
      */
-    public static function createTableInFirstNS(FlatBufferBuilder $builder, $foo_table, $foo_enum, $foo_struct)
+    public static function createTableInFirstNS(FlatBufferBuilder $builder, $foo_table, $foo_enum, $foo_union_type, $foo_union, $foo_struct)
     {
-        $builder->startObject(3);
+        $builder->startObject(5);
         self::addFooTable($builder, $foo_table);
         self::addFooEnum($builder, $foo_enum);
+        self::addFooUnionType($builder, $foo_union_type);
+        self::addFooUnion($builder, $foo_union);
         self::addFooStruct($builder, $foo_struct);
         $o = $builder->endObject();
         return $o;
@@ -100,12 +120,27 @@
 
     /**
      * @param FlatBufferBuilder $builder
+     * @param byte
+     * @return void
+     */
+    public static function addFooUnionType(FlatBufferBuilder $builder, $fooUnionType)
+    {
+        $builder->addByteX(2, $fooUnionType, 0);
+    }
+
+    public static function addFooUnion(FlatBufferBuilder $builder, $offset)
+    {
+        $builder->addOffsetX(3, $offset, 0);
+    }
+
+    /**
+     * @param FlatBufferBuilder $builder
      * @param int
      * @return void
      */
     public static function addFooStruct(FlatBufferBuilder $builder, $fooStruct)
     {
-        $builder->addStructX(2, $fooStruct, 0);
+        $builder->addStructX(4, $fooStruct, 0);
     }
 
     /**
diff --git a/tests/namespace_test/NamespaceA/TableInFirstNS.py b/tests/namespace_test/NamespaceA/TableInFirstNS.py
index 39598f5..8f191f8 100644
--- a/tests/namespace_test/NamespaceA/TableInFirstNS.py
+++ b/tests/namespace_test/NamespaceA/TableInFirstNS.py
@@ -10,12 +10,16 @@
     __slots__ = ['_tab']
 
     @classmethod
-    def GetRootAsTableInFirstNS(cls, buf, offset):
+    def GetRootAs(cls, buf, offset=0):
         n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
         x = TableInFirstNS()
         x.Init(buf, n + offset)
         return x
 
+    @classmethod
+    def GetRootAsTableInFirstNS(cls, buf, offset=0):
+        """This method is deprecated. Please switch to GetRootAs."""
+        return cls.GetRootAs(buf, offset)
     # TableInFirstNS
     def Init(self, buf, pos):
         self._tab = flatbuffers.table.Table(buf, pos)
@@ -38,23 +42,55 @@
         return 0
 
     # TableInFirstNS
-    def FooStruct(self):
+    def FooUnionType(self):
         o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8))
         if o != 0:
+            return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos)
+        return 0
+
+    # TableInFirstNS
+    def FooUnion(self):
+        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10))
+        if o != 0:
+            from flatbuffers.table import Table
+            obj = Table(bytearray(), 0)
+            self._tab.Union(obj, o)
+            return obj
+        return None
+
+    # TableInFirstNS
+    def FooStruct(self):
+        o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12))
+        if o != 0:
             x = o + self._tab.Pos
             obj = StructInNestedNS()
             obj.Init(self._tab.Bytes, x)
             return obj
         return None
 
-def TableInFirstNSStart(builder): builder.StartObject(3)
+def TableInFirstNSStart(builder): builder.StartObject(5)
+def Start(builder):
+    return TableInFirstNSStart(builder)
 def TableInFirstNSAddFooTable(builder, fooTable): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(fooTable), 0)
+def AddFooTable(builder, fooTable):
+    return TableInFirstNSAddFooTable(builder, fooTable)
 def TableInFirstNSAddFooEnum(builder, fooEnum): builder.PrependInt8Slot(1, fooEnum, 0)
-def TableInFirstNSAddFooStruct(builder, fooStruct): builder.PrependStructSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(fooStruct), 0)
+def AddFooEnum(builder, fooEnum):
+    return TableInFirstNSAddFooEnum(builder, fooEnum)
+def TableInFirstNSAddFooUnionType(builder, fooUnionType): builder.PrependUint8Slot(2, fooUnionType, 0)
+def AddFooUnionType(builder, fooUnionType):
+    return TableInFirstNSAddFooUnionType(builder, fooUnionType)
+def TableInFirstNSAddFooUnion(builder, fooUnion): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(fooUnion), 0)
+def AddFooUnion(builder, fooUnion):
+    return TableInFirstNSAddFooUnion(builder, fooUnion)
+def TableInFirstNSAddFooStruct(builder, fooStruct): builder.PrependStructSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(fooStruct), 0)
+def AddFooStruct(builder, fooStruct):
+    return TableInFirstNSAddFooStruct(builder, fooStruct)
 def TableInFirstNSEnd(builder): return builder.EndObject()
-
+def End(builder):
+    return TableInFirstNSEnd(builder)
 try:
-    from typing import Optional
+    from typing import Optional, Union
 except:
     pass
 
@@ -64,6 +100,8 @@
     def __init__(self):
         self.fooTable = None  # type: Optional[TableInNestedNST]
         self.fooEnum = 0  # type: int
+        self.fooUnionType = 0  # type: int
+        self.fooUnion = None  # type: Union[None, TableInNestedNST]
         self.fooStruct = None  # type: Optional[StructInNestedNST]
 
     @classmethod
@@ -85,6 +123,8 @@
         if tableInFirstNS.FooTable() is not None:
             self.fooTable = TableInNestedNST.InitFromObj(tableInFirstNS.FooTable())
         self.fooEnum = tableInFirstNS.FooEnum()
+        self.fooUnionType = tableInFirstNS.FooUnionType()
+        self.fooUnion = UnionInNestedNSCreator(self.fooUnionType, tableInFirstNS.FooUnion())
         if tableInFirstNS.FooStruct() is not None:
             self.fooStruct = StructInNestedNST.InitFromObj(tableInFirstNS.FooStruct())
 
@@ -92,10 +132,15 @@
     def Pack(self, builder):
         if self.fooTable is not None:
             fooTable = self.fooTable.Pack(builder)
+        if self.fooUnion is not None:
+            fooUnion = self.fooUnion.Pack(builder)
         TableInFirstNSStart(builder)
         if self.fooTable is not None:
             TableInFirstNSAddFooTable(builder, fooTable)
         TableInFirstNSAddFooEnum(builder, self.fooEnum)
+        TableInFirstNSAddFooUnionType(builder, self.fooUnionType)
+        if self.fooUnion is not None:
+            TableInFirstNSAddFooUnion(builder, fooUnion)
         if self.fooStruct is not None:
             fooStruct = self.fooStruct.Pack(builder)
             TableInFirstNSAddFooStruct(builder, fooStruct)
diff --git a/tests/namespace_test/NamespaceA/TableInFirstNST.java b/tests/namespace_test/NamespaceA/TableInFirstNST.java
new file mode 100644
index 0000000..ee439d4
--- /dev/null
+++ b/tests/namespace_test/NamespaceA/TableInFirstNST.java
@@ -0,0 +1,40 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+package NamespaceA;
+
+import java.nio.*;
+import java.lang.*;
+import java.util.*;
+import com.google.flatbuffers.*;
+
+public class TableInFirstNST {
+  private NamespaceA.NamespaceB.TableInNestedNST fooTable;
+  private byte fooEnum;
+  private NamespaceA.NamespaceB.UnionInNestedNSUnion fooUnion;
+  private NamespaceA.NamespaceB.StructInNestedNST fooStruct;
+
+  public NamespaceA.NamespaceB.TableInNestedNST getFooTable() { return fooTable; }
+
+  public void setFooTable(NamespaceA.NamespaceB.TableInNestedNST fooTable) { this.fooTable = fooTable; }
+
+  public byte getFooEnum() { return fooEnum; }
+
+  public void setFooEnum(byte fooEnum) { this.fooEnum = fooEnum; }
+
+  public NamespaceA.NamespaceB.UnionInNestedNSUnion getFooUnion() { return fooUnion; }
+
+  public void setFooUnion(NamespaceA.NamespaceB.UnionInNestedNSUnion fooUnion) { this.fooUnion = fooUnion; }
+
+  public NamespaceA.NamespaceB.StructInNestedNST getFooStruct() { return fooStruct; }
+
+  public void setFooStruct(NamespaceA.NamespaceB.StructInNestedNST fooStruct) { this.fooStruct = fooStruct; }
+
+
+  public TableInFirstNST() {
+    this.fooTable = null;
+    this.fooEnum = 0;
+    this.fooUnion = null;
+    this.fooStruct = new NamespaceA.NamespaceB.StructInNestedNST();
+  }
+}
+
diff --git a/tests/namespace_test/NamespaceC/TableInC.cs b/tests/namespace_test/NamespaceC/TableInC.cs
index bfb9b76..2077e32 100644
--- a/tests/namespace_test/NamespaceC/TableInC.cs
+++ b/tests/namespace_test/NamespaceC/TableInC.cs
@@ -13,7 +13,7 @@
 {
   private Table __p;
   public ByteBuffer ByteBuffer { get { return __p.bb; } }
-  public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_1_12_0(); }
+  public static void ValidateVersion() { FlatBufferConstants.FLATBUFFERS_2_0_0(); }
   public static TableInC GetRootAsTableInC(ByteBuffer _bb) { return GetRootAsTableInC(_bb, new TableInC()); }
   public static TableInC GetRootAsTableInC(ByteBuffer _bb, TableInC obj) { return (obj.__assign(_bb.GetInt(_bb.Position) + _bb.Position, _bb)); }
   public void __init(int _i, ByteBuffer _bb) { __p = new Table(_i, _bb); }
@@ -56,7 +56,7 @@
       _refer_to_a1,
       _refer_to_a2);
   }
-};
+}
 
 public class TableInCT
 {
diff --git a/tests/namespace_test/NamespaceC/TableInC.java b/tests/namespace_test/NamespaceC/TableInC.java
index 503f237..04ceac7 100644
--- a/tests/namespace_test/NamespaceC/TableInC.java
+++ b/tests/namespace_test/NamespaceC/TableInC.java
@@ -9,7 +9,7 @@
 
 @SuppressWarnings("unused")
 public final class TableInC extends Table {
-  public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); }
+  public static void ValidateVersion() { Constants.FLATBUFFERS_2_0_0(); }
   public static TableInC getRootAsTableInC(ByteBuffer _bb) { return getRootAsTableInC(_bb, new TableInC()); }
   public static TableInC getRootAsTableInC(ByteBuffer _bb, TableInC obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
   public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
@@ -21,11 +21,11 @@
   public NamespaceA.SecondTableInA referToA2(NamespaceA.SecondTableInA obj) { int o = __offset(6); return o != 0 ? obj.__assign(__indirect(o + bb_pos), bb) : null; }
 
   public static int createTableInC(FlatBufferBuilder builder,
-      int refer_to_a1Offset,
-      int refer_to_a2Offset) {
+      int referToA1Offset,
+      int referToA2Offset) {
     builder.startTable(2);
-    TableInC.addReferToA2(builder, refer_to_a2Offset);
-    TableInC.addReferToA1(builder, refer_to_a1Offset);
+    TableInC.addReferToA2(builder, referToA2Offset);
+    TableInC.addReferToA1(builder, referToA1Offset);
     return TableInC.endTableInC(builder);
   }
 
@@ -43,5 +43,25 @@
     public TableInC get(int j) { return get(new TableInC(), j); }
     public TableInC get(TableInC obj, int j) {  return obj.__assign(__indirect(__element(j), bb), bb); }
   }
+  public TableInCT unpack() {
+    TableInCT _o = new TableInCT();
+    unpackTo(_o);
+    return _o;
+  }
+  public void unpackTo(TableInCT _o) {
+    if (referToA1() != null) _o.setReferToA1(referToA1().unpack());
+    else _o.setReferToA1(null);
+    if (referToA2() != null) _o.setReferToA2(referToA2().unpack());
+    else _o.setReferToA2(null);
+  }
+  public static int pack(FlatBufferBuilder builder, TableInCT _o) {
+    if (_o == null) return 0;
+    int _refer_to_a1 = _o.getReferToA1() == null ? 0 : NamespaceA.TableInFirstNS.pack(builder, _o.getReferToA1());
+    int _refer_to_a2 = _o.getReferToA2() == null ? 0 : NamespaceA.SecondTableInA.pack(builder, _o.getReferToA2());
+    return createTableInC(
+      builder,
+      _refer_to_a1,
+      _refer_to_a2);
+  }
 }
 
diff --git a/tests/namespace_test/NamespaceC/TableInC.kt b/tests/namespace_test/NamespaceC/TableInC.kt
index a5222f1..7586e25 100644
--- a/tests/namespace_test/NamespaceC/TableInC.kt
+++ b/tests/namespace_test/NamespaceC/TableInC.kt
@@ -36,7 +36,7 @@
         }
     }
     companion object {
-        fun validateVersion() = Constants.FLATBUFFERS_1_12_0()
+        fun validateVersion() = Constants.FLATBUFFERS_2_0_0()
         fun getRootAsTableInC(_bb: ByteBuffer): TableInC = getRootAsTableInC(_bb, TableInC())
         fun getRootAsTableInC(_bb: ByteBuffer, obj: TableInC): TableInC {
             _bb.order(ByteOrder.LITTLE_ENDIAN)
diff --git a/tests/namespace_test/NamespaceC/TableInC.lua b/tests/namespace_test/NamespaceC/TableInC.lua
index bb4fef0..71e4842 100644
--- a/tests/namespace_test/NamespaceC/TableInC.lua
+++ b/tests/namespace_test/NamespaceC/TableInC.lua
@@ -13,6 +13,9 @@
     return o
 end
 function TableInC.GetRootAsTableInC(buf, offset)
+    if type(buf) == "string" then
+        buf = flatbuffers.binaryArray.New(buf)
+    end
     local n = flatbuffers.N.UOffsetT:Unpack(buf, offset)
     local o = TableInC.New()
     o:Init(buf, n + offset)
diff --git a/tests/namespace_test/NamespaceC/TableInC.py b/tests/namespace_test/NamespaceC/TableInC.py
index 8f04b52..762e1a1 100644
--- a/tests/namespace_test/NamespaceC/TableInC.py
+++ b/tests/namespace_test/NamespaceC/TableInC.py
@@ -10,12 +10,16 @@
     __slots__ = ['_tab']
 
     @classmethod
-    def GetRootAsTableInC(cls, buf, offset):
+    def GetRootAs(cls, buf, offset=0):
         n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset)
         x = TableInC()
         x.Init(buf, n + offset)
         return x
 
+    @classmethod
+    def GetRootAsTableInC(cls, buf, offset=0):
+        """This method is deprecated. Please switch to GetRootAs."""
+        return cls.GetRootAs(buf, offset)
     # TableInC
     def Init(self, buf, pos):
         self._tab = flatbuffers.table.Table(buf, pos)
@@ -41,10 +45,17 @@
         return None
 
 def TableInCStart(builder): builder.StartObject(2)
+def Start(builder):
+    return TableInCStart(builder)
 def TableInCAddReferToA1(builder, referToA1): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(referToA1), 0)
+def AddReferToA1(builder, referToA1):
+    return TableInCAddReferToA1(builder, referToA1)
 def TableInCAddReferToA2(builder, referToA2): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(referToA2), 0)
+def AddReferToA2(builder, referToA2):
+    return TableInCAddReferToA2(builder, referToA2)
 def TableInCEnd(builder): return builder.EndObject()
-
+def End(builder):
+    return TableInCEnd(builder)
 try:
     from typing import Optional
 except:
diff --git a/tests/namespace_test/NamespaceC/TableInCT.java b/tests/namespace_test/NamespaceC/TableInCT.java
new file mode 100644
index 0000000..d265091
--- /dev/null
+++ b/tests/namespace_test/NamespaceC/TableInCT.java
@@ -0,0 +1,28 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+package NamespaceC;
+
+import java.nio.*;
+import java.lang.*;
+import java.util.*;
+import com.google.flatbuffers.*;
+
+public class TableInCT {
+  private NamespaceA.TableInFirstNST referToA1;
+  private NamespaceA.SecondTableInAT referToA2;
+
+  public NamespaceA.TableInFirstNST getReferToA1() { return referToA1; }
+
+  public void setReferToA1(NamespaceA.TableInFirstNST referToA1) { this.referToA1 = referToA1; }
+
+  public NamespaceA.SecondTableInAT getReferToA2() { return referToA2; }
+
+  public void setReferToA2(NamespaceA.SecondTableInAT referToA2) { this.referToA2 = referToA2; }
+
+
+  public TableInCT() {
+    this.referToA1 = null;
+    this.referToA2 = null;
+  }
+}
+
diff --git a/tests/namespace_test/mod.rs b/tests/namespace_test/mod.rs
new file mode 100644
index 0000000..8572c8d
--- /dev/null
+++ b/tests/namespace_test/mod.rs
@@ -0,0 +1,24 @@
+// Automatically generated by the Flatbuffers compiler. Do not modify.
+pub mod namespace_a {
+  use super::*;
+  pub mod namespace_b {
+    use super::*;
+    mod union_in_nested_ns_generated;
+    pub use self::union_in_nested_ns_generated::*;
+    mod enum_in_nested_ns_generated;
+    pub use self::enum_in_nested_ns_generated::*;
+    mod table_in_nested_ns_generated;
+    pub use self::table_in_nested_ns_generated::*;
+    mod struct_in_nested_ns_generated;
+    pub use self::struct_in_nested_ns_generated::*;
+  } // namespace_b
+  mod table_in_first_ns_generated;
+  pub use self::table_in_first_ns_generated::*;
+  mod second_table_in_a_generated;
+  pub use self::second_table_in_a_generated::*;
+} // namespace_a
+pub mod namespace_c {
+  use super::*;
+  mod table_in_c_generated;
+  pub use self::table_in_c_generated::*;
+} // namespace_c
diff --git a/tests/namespace_test/namespace-a/namespace-b/enum-in-nested-n-s.js b/tests/namespace_test/namespace-a/namespace-b/enum-in-nested-n-s.js
new file mode 100644
index 0000000..9105ed4
--- /dev/null
+++ b/tests/namespace_test/namespace-a/namespace-b/enum-in-nested-n-s.js
@@ -0,0 +1,7 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+export var EnumInNestedNS;
+(function (EnumInNestedNS) {
+    EnumInNestedNS[EnumInNestedNS["A"] = 0] = "A";
+    EnumInNestedNS[EnumInNestedNS["B"] = 1] = "B";
+    EnumInNestedNS[EnumInNestedNS["C"] = 2] = "C";
+})(EnumInNestedNS || (EnumInNestedNS = {}));
diff --git a/tests/namespace_test/namespace-a/namespace-b/enum-in-nested-n-s.ts b/tests/namespace_test/namespace-a/namespace-b/enum-in-nested-n-s.ts
new file mode 100644
index 0000000..676b7e4
--- /dev/null
+++ b/tests/namespace_test/namespace-a/namespace-b/enum-in-nested-n-s.ts
@@ -0,0 +1,8 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+export enum EnumInNestedNS{
+  A = 0,
+  B = 1,
+  C = 2
+}
+
diff --git a/tests/namespace_test/namespace-a/namespace-b/struct-in-nested-n-s.js b/tests/namespace_test/namespace-a/namespace-b/struct-in-nested-n-s.js
new file mode 100644
index 0000000..918e238
--- /dev/null
+++ b/tests/namespace_test/namespace-a/namespace-b/struct-in-nested-n-s.js
@@ -0,0 +1,54 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+export class StructInNestedNS {
+    constructor() {
+        this.bb = null;
+        this.bb_pos = 0;
+    }
+    __init(i, bb) {
+        this.bb_pos = i;
+        this.bb = bb;
+        return this;
+    }
+    a() {
+        return this.bb.readInt32(this.bb_pos);
+    }
+    mutate_a(value) {
+        this.bb.writeInt32(this.bb_pos + 0, value);
+        return true;
+    }
+    b() {
+        return this.bb.readInt32(this.bb_pos + 4);
+    }
+    mutate_b(value) {
+        this.bb.writeInt32(this.bb_pos + 4, value);
+        return true;
+    }
+    static getFullyQualifiedName() {
+        return 'NamespaceA.NamespaceB.StructInNestedNS';
+    }
+    static sizeOf() {
+        return 8;
+    }
+    static createStructInNestedNS(builder, a, b) {
+        builder.prep(4, 8);
+        builder.writeInt32(b);
+        builder.writeInt32(a);
+        return builder.offset();
+    }
+    unpack() {
+        return new StructInNestedNST(this.a(), this.b());
+    }
+    unpackTo(_o) {
+        _o.a = this.a();
+        _o.b = this.b();
+    }
+}
+export class StructInNestedNST {
+    constructor(a = 0, b = 0) {
+        this.a = a;
+        this.b = b;
+    }
+    pack(builder) {
+        return StructInNestedNS.createStructInNestedNS(builder, this.a, this.b);
+    }
+}
diff --git a/tests/namespace_test/namespace-a/namespace-b/struct-in-nested-n-s.ts b/tests/namespace_test/namespace-a/namespace-b/struct-in-nested-n-s.ts
new file mode 100644
index 0000000..4b10118
--- /dev/null
+++ b/tests/namespace_test/namespace-a/namespace-b/struct-in-nested-n-s.ts
@@ -0,0 +1,77 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+import * as flatbuffers from 'flatbuffers';
+
+
+
+export class StructInNestedNS {
+  bb: flatbuffers.ByteBuffer|null = null;
+  bb_pos = 0;
+__init(i:number, bb:flatbuffers.ByteBuffer):StructInNestedNS {
+  this.bb_pos = i;
+  this.bb = bb;
+  return this;
+}
+
+a():number {
+  return this.bb!.readInt32(this.bb_pos);
+}
+
+mutate_a(value:number):boolean {
+  this.bb!.writeInt32(this.bb_pos + 0, value);
+  return true;
+}
+
+b():number {
+  return this.bb!.readInt32(this.bb_pos + 4);
+}
+
+mutate_b(value:number):boolean {
+  this.bb!.writeInt32(this.bb_pos + 4, value);
+  return true;
+}
+
+static getFullyQualifiedName():string {
+  return 'NamespaceA.NamespaceB.StructInNestedNS';
+}
+
+static sizeOf():number {
+  return 8;
+}
+
+static createStructInNestedNS(builder:flatbuffers.Builder, a: number, b: number):flatbuffers.Offset {
+  builder.prep(4, 8);
+  builder.writeInt32(b);
+  builder.writeInt32(a);
+  return builder.offset();
+}
+
+
+unpack(): StructInNestedNST {
+  return new StructInNestedNST(
+    this.a(),
+    this.b()
+  );
+}
+
+
+unpackTo(_o: StructInNestedNST): void {
+  _o.a = this.a();
+  _o.b = this.b();
+}
+}
+
+export class StructInNestedNST {
+constructor(
+  public a: number = 0,
+  public b: number = 0
+){}
+
+
+pack(builder:flatbuffers.Builder): flatbuffers.Offset {
+  return StructInNestedNS.createStructInNestedNS(builder,
+    this.a,
+    this.b
+  );
+}
+}
diff --git a/tests/namespace_test/namespace-a/namespace-b/table-in-nested-n-s.js b/tests/namespace_test/namespace-a/namespace-b/table-in-nested-n-s.js
new file mode 100644
index 0000000..fca1668
--- /dev/null
+++ b/tests/namespace_test/namespace-a/namespace-b/table-in-nested-n-s.js
@@ -0,0 +1,64 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+import * as flatbuffers from 'flatbuffers';
+export class TableInNestedNS {
+    constructor() {
+        this.bb = null;
+        this.bb_pos = 0;
+    }
+    __init(i, bb) {
+        this.bb_pos = i;
+        this.bb = bb;
+        return this;
+    }
+    static getRootAsTableInNestedNS(bb, obj) {
+        return (obj || new TableInNestedNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+    }
+    static getSizePrefixedRootAsTableInNestedNS(bb, obj) {
+        bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
+        return (obj || new TableInNestedNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+    }
+    foo() {
+        const offset = this.bb.__offset(this.bb_pos, 4);
+        return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
+    }
+    mutate_foo(value) {
+        const offset = this.bb.__offset(this.bb_pos, 4);
+        if (offset === 0) {
+            return false;
+        }
+        this.bb.writeInt32(this.bb_pos + offset, value);
+        return true;
+    }
+    static getFullyQualifiedName() {
+        return 'NamespaceA.NamespaceB.TableInNestedNS';
+    }
+    static startTableInNestedNS(builder) {
+        builder.startObject(1);
+    }
+    static addFoo(builder, foo) {
+        builder.addFieldInt32(0, foo, 0);
+    }
+    static endTableInNestedNS(builder) {
+        const offset = builder.endObject();
+        return offset;
+    }
+    static createTableInNestedNS(builder, foo) {
+        TableInNestedNS.startTableInNestedNS(builder);
+        TableInNestedNS.addFoo(builder, foo);
+        return TableInNestedNS.endTableInNestedNS(builder);
+    }
+    unpack() {
+        return new TableInNestedNST(this.foo());
+    }
+    unpackTo(_o) {
+        _o.foo = this.foo();
+    }
+}
+export class TableInNestedNST {
+    constructor(foo = 0) {
+        this.foo = foo;
+    }
+    pack(builder) {
+        return TableInNestedNS.createTableInNestedNS(builder, this.foo);
+    }
+}
diff --git a/tests/namespace_test/namespace-a/namespace-b/table-in-nested-n-s.ts b/tests/namespace_test/namespace-a/namespace-b/table-in-nested-n-s.ts
new file mode 100644
index 0000000..5279fdb
--- /dev/null
+++ b/tests/namespace_test/namespace-a/namespace-b/table-in-nested-n-s.ts
@@ -0,0 +1,87 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+import * as flatbuffers from 'flatbuffers';
+
+
+
+export class TableInNestedNS {
+  bb: flatbuffers.ByteBuffer|null = null;
+  bb_pos = 0;
+__init(i:number, bb:flatbuffers.ByteBuffer):TableInNestedNS {
+  this.bb_pos = i;
+  this.bb = bb;
+  return this;
+}
+
+static getRootAsTableInNestedNS(bb:flatbuffers.ByteBuffer, obj?:TableInNestedNS):TableInNestedNS {
+  return (obj || new TableInNestedNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+}
+
+static getSizePrefixedRootAsTableInNestedNS(bb:flatbuffers.ByteBuffer, obj?:TableInNestedNS):TableInNestedNS {
+  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
+  return (obj || new TableInNestedNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+}
+
+foo():number {
+  const offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
+}
+
+mutate_foo(value:number):boolean {
+  const offset = this.bb!.__offset(this.bb_pos, 4);
+
+  if (offset === 0) {
+    return false;
+  }
+
+  this.bb!.writeInt32(this.bb_pos + offset, value);
+  return true;
+}
+
+static getFullyQualifiedName():string {
+  return 'NamespaceA.NamespaceB.TableInNestedNS';
+}
+
+static startTableInNestedNS(builder:flatbuffers.Builder) {
+  builder.startObject(1);
+}
+
+static addFoo(builder:flatbuffers.Builder, foo:number) {
+  builder.addFieldInt32(0, foo, 0);
+}
+
+static endTableInNestedNS(builder:flatbuffers.Builder):flatbuffers.Offset {
+  const offset = builder.endObject();
+  return offset;
+}
+
+static createTableInNestedNS(builder:flatbuffers.Builder, foo:number):flatbuffers.Offset {
+  TableInNestedNS.startTableInNestedNS(builder);
+  TableInNestedNS.addFoo(builder, foo);
+  return TableInNestedNS.endTableInNestedNS(builder);
+}
+
+unpack(): TableInNestedNST {
+  return new TableInNestedNST(
+    this.foo()
+  );
+}
+
+
+unpackTo(_o: TableInNestedNST): void {
+  _o.foo = this.foo();
+}
+}
+
+export class TableInNestedNST {
+constructor(
+  public foo: number = 0
+){}
+
+
+pack(builder:flatbuffers.Builder): flatbuffers.Offset {
+  return TableInNestedNS.createTableInNestedNS(builder,
+    this.foo
+  );
+}
+}
diff --git a/tests/namespace_test/namespace-a/namespace-b/union-in-nested-n-s.js b/tests/namespace_test/namespace-a/namespace-b/union-in-nested-n-s.js
new file mode 100644
index 0000000..b820bce
--- /dev/null
+++ b/tests/namespace_test/namespace-a/namespace-b/union-in-nested-n-s.js
@@ -0,0 +1,21 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+import { TableInNestedNS } from '../../namespace-a/namespace-b/table-in-nested-n-s';
+export var UnionInNestedNS;
+(function (UnionInNestedNS) {
+    UnionInNestedNS[UnionInNestedNS["NONE"] = 0] = "NONE";
+    UnionInNestedNS[UnionInNestedNS["TableInNestedNS"] = 1] = "TableInNestedNS";
+})(UnionInNestedNS || (UnionInNestedNS = {}));
+export function unionToUnionInNestedNS(type, accessor) {
+    switch (UnionInNestedNS[type]) {
+        case 'NONE': return null;
+        case 'TableInNestedNS': return accessor(new TableInNestedNS());
+        default: return null;
+    }
+}
+export function unionListToUnionInNestedNS(type, accessor, index) {
+    switch (UnionInNestedNS[type]) {
+        case 'NONE': return null;
+        case 'TableInNestedNS': return accessor(index, new TableInNestedNS());
+        default: return null;
+    }
+}
diff --git a/tests/namespace_test/namespace-a/namespace-b/union-in-nested-n-s.ts b/tests/namespace_test/namespace-a/namespace-b/union-in-nested-n-s.ts
new file mode 100644
index 0000000..441ebf7
--- /dev/null
+++ b/tests/namespace_test/namespace-a/namespace-b/union-in-nested-n-s.ts
@@ -0,0 +1,33 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+import { TableInNestedNS, TableInNestedNST } from '../../namespace-a/namespace-b/table-in-nested-n-s';
+
+
+export enum UnionInNestedNS{
+  NONE = 0,
+  TableInNestedNS = 1
+}
+
+export function unionToUnionInNestedNS(
+  type: UnionInNestedNS,
+  accessor: (obj:TableInNestedNS) => TableInNestedNS|null
+): TableInNestedNS|null {
+  switch(UnionInNestedNS[type]) {
+    case 'NONE': return null; 
+    case 'TableInNestedNS': return accessor(new TableInNestedNS())! as TableInNestedNS;
+    default: return null;
+  }
+}
+
+export function unionListToUnionInNestedNS(
+  type: UnionInNestedNS, 
+  accessor: (index: number, obj:TableInNestedNS) => TableInNestedNS|null, 
+  index: number
+): TableInNestedNS|null {
+  switch(UnionInNestedNS[type]) {
+    case 'NONE': return null; 
+    case 'TableInNestedNS': return accessor(index, new TableInNestedNS())! as TableInNestedNS;
+    default: return null;
+  }
+}
+
diff --git a/tests/namespace_test/namespace-a/second-table-in-a.js b/tests/namespace_test/namespace-a/second-table-in-a.js
new file mode 100644
index 0000000..fe848e0
--- /dev/null
+++ b/tests/namespace_test/namespace-a/second-table-in-a.js
@@ -0,0 +1,58 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+import * as flatbuffers from 'flatbuffers';
+import { TableInC } from '../namespace-c/table-in-c';
+export class SecondTableInA {
+    constructor() {
+        this.bb = null;
+        this.bb_pos = 0;
+    }
+    __init(i, bb) {
+        this.bb_pos = i;
+        this.bb = bb;
+        return this;
+    }
+    static getRootAsSecondTableInA(bb, obj) {
+        return (obj || new SecondTableInA()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+    }
+    static getSizePrefixedRootAsSecondTableInA(bb, obj) {
+        bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
+        return (obj || new SecondTableInA()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+    }
+    referToC(obj) {
+        const offset = this.bb.__offset(this.bb_pos, 4);
+        return offset ? (obj || new TableInC()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
+    }
+    static getFullyQualifiedName() {
+        return 'NamespaceA.SecondTableInA';
+    }
+    static startSecondTableInA(builder) {
+        builder.startObject(1);
+    }
+    static addReferToC(builder, referToCOffset) {
+        builder.addFieldOffset(0, referToCOffset, 0);
+    }
+    static endSecondTableInA(builder) {
+        const offset = builder.endObject();
+        return offset;
+    }
+    static createSecondTableInA(builder, referToCOffset) {
+        SecondTableInA.startSecondTableInA(builder);
+        SecondTableInA.addReferToC(builder, referToCOffset);
+        return SecondTableInA.endSecondTableInA(builder);
+    }
+    unpack() {
+        return new SecondTableInAT((this.referToC() !== null ? this.referToC().unpack() : null));
+    }
+    unpackTo(_o) {
+        _o.referToC = (this.referToC() !== null ? this.referToC().unpack() : null);
+    }
+}
+export class SecondTableInAT {
+    constructor(referToC = null) {
+        this.referToC = referToC;
+    }
+    pack(builder) {
+        const referToC = (this.referToC !== null ? this.referToC.pack(builder) : 0);
+        return SecondTableInA.createSecondTableInA(builder, referToC);
+    }
+}
diff --git a/tests/namespace_test/namespace-a/second-table-in-a.ts b/tests/namespace_test/namespace-a/second-table-in-a.ts
new file mode 100644
index 0000000..9be3402
--- /dev/null
+++ b/tests/namespace_test/namespace-a/second-table-in-a.ts
@@ -0,0 +1,79 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+import * as flatbuffers from 'flatbuffers';
+
+import { TableInC, TableInCT } from '../namespace-c/table-in-c';
+
+
+export class SecondTableInA {
+  bb: flatbuffers.ByteBuffer|null = null;
+  bb_pos = 0;
+__init(i:number, bb:flatbuffers.ByteBuffer):SecondTableInA {
+  this.bb_pos = i;
+  this.bb = bb;
+  return this;
+}
+
+static getRootAsSecondTableInA(bb:flatbuffers.ByteBuffer, obj?:SecondTableInA):SecondTableInA {
+  return (obj || new SecondTableInA()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+}
+
+static getSizePrefixedRootAsSecondTableInA(bb:flatbuffers.ByteBuffer, obj?:SecondTableInA):SecondTableInA {
+  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
+  return (obj || new SecondTableInA()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+}
+
+referToC(obj?:TableInC):TableInC|null {
+  const offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? (obj || new TableInC()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
+}
+
+static getFullyQualifiedName():string {
+  return 'NamespaceA.SecondTableInA';
+}
+
+static startSecondTableInA(builder:flatbuffers.Builder) {
+  builder.startObject(1);
+}
+
+static addReferToC(builder:flatbuffers.Builder, referToCOffset:flatbuffers.Offset) {
+  builder.addFieldOffset(0, referToCOffset, 0);
+}
+
+static endSecondTableInA(builder:flatbuffers.Builder):flatbuffers.Offset {
+  const offset = builder.endObject();
+  return offset;
+}
+
+static createSecondTableInA(builder:flatbuffers.Builder, referToCOffset:flatbuffers.Offset):flatbuffers.Offset {
+  SecondTableInA.startSecondTableInA(builder);
+  SecondTableInA.addReferToC(builder, referToCOffset);
+  return SecondTableInA.endSecondTableInA(builder);
+}
+
+unpack(): SecondTableInAT {
+  return new SecondTableInAT(
+    (this.referToC() !== null ? this.referToC()!.unpack() : null)
+  );
+}
+
+
+unpackTo(_o: SecondTableInAT): void {
+  _o.referToC = (this.referToC() !== null ? this.referToC()!.unpack() : null);
+}
+}
+
+export class SecondTableInAT {
+constructor(
+  public referToC: TableInCT|null = null
+){}
+
+
+pack(builder:flatbuffers.Builder): flatbuffers.Offset {
+  const referToC = (this.referToC !== null ? this.referToC!.pack(builder) : 0);
+
+  return SecondTableInA.createSecondTableInA(builder,
+    referToC
+  );
+}
+}
diff --git a/tests/namespace_test/namespace-a/table-in-first-n-s.js b/tests/namespace_test/namespace-a/table-in-first-n-s.js
new file mode 100644
index 0000000..91bcc85
--- /dev/null
+++ b/tests/namespace_test/namespace-a/table-in-first-n-s.js
@@ -0,0 +1,119 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+import * as flatbuffers from 'flatbuffers';
+import { EnumInNestedNS } from '../namespace-a/namespace-b/enum-in-nested-n-s';
+import { StructInNestedNS } from '../namespace-a/namespace-b/struct-in-nested-n-s';
+import { TableInNestedNS } from '../namespace-a/namespace-b/table-in-nested-n-s';
+import { UnionInNestedNS, unionToUnionInNestedNS } from '../namespace-a/namespace-b/union-in-nested-n-s';
+export class TableInFirstNS {
+    constructor() {
+        this.bb = null;
+        this.bb_pos = 0;
+    }
+    __init(i, bb) {
+        this.bb_pos = i;
+        this.bb = bb;
+        return this;
+    }
+    static getRootAsTableInFirstNS(bb, obj) {
+        return (obj || new TableInFirstNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+    }
+    static getSizePrefixedRootAsTableInFirstNS(bb, obj) {
+        bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
+        return (obj || new TableInFirstNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+    }
+    fooTable(obj) {
+        const offset = this.bb.__offset(this.bb_pos, 4);
+        return offset ? (obj || new TableInNestedNS()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
+    }
+    fooEnum() {
+        const offset = this.bb.__offset(this.bb_pos, 6);
+        return offset ? this.bb.readInt8(this.bb_pos + offset) : EnumInNestedNS.A;
+    }
+    mutate_foo_enum(value) {
+        const offset = this.bb.__offset(this.bb_pos, 6);
+        if (offset === 0) {
+            return false;
+        }
+        this.bb.writeInt8(this.bb_pos + offset, value);
+        return true;
+    }
+    fooUnionType() {
+        const offset = this.bb.__offset(this.bb_pos, 8);
+        return offset ? this.bb.readUint8(this.bb_pos + offset) : UnionInNestedNS.NONE;
+    }
+    fooUnion(obj) {
+        const offset = this.bb.__offset(this.bb_pos, 10);
+        return offset ? this.bb.__union(obj, this.bb_pos + offset) : null;
+    }
+    fooStruct(obj) {
+        const offset = this.bb.__offset(this.bb_pos, 12);
+        return offset ? (obj || new StructInNestedNS()).__init(this.bb_pos + offset, this.bb) : null;
+    }
+    static getFullyQualifiedName() {
+        return 'NamespaceA.TableInFirstNS';
+    }
+    static startTableInFirstNS(builder) {
+        builder.startObject(5);
+    }
+    static addFooTable(builder, fooTableOffset) {
+        builder.addFieldOffset(0, fooTableOffset, 0);
+    }
+    static addFooEnum(builder, fooEnum) {
+        builder.addFieldInt8(1, fooEnum, EnumInNestedNS.A);
+    }
+    static addFooUnionType(builder, fooUnionType) {
+        builder.addFieldInt8(2, fooUnionType, UnionInNestedNS.NONE);
+    }
+    static addFooUnion(builder, fooUnionOffset) {
+        builder.addFieldOffset(3, fooUnionOffset, 0);
+    }
+    static addFooStruct(builder, fooStructOffset) {
+        builder.addFieldStruct(4, fooStructOffset, 0);
+    }
+    static endTableInFirstNS(builder) {
+        const offset = builder.endObject();
+        return offset;
+    }
+    unpack() {
+        return new TableInFirstNST((this.fooTable() !== null ? this.fooTable().unpack() : null), this.fooEnum(), this.fooUnionType(), (() => {
+            let temp = unionToUnionInNestedNS(this.fooUnionType(), this.fooUnion.bind(this));
+            if (temp === null) {
+                return null;
+            }
+            return temp.unpack();
+        })(), (this.fooStruct() !== null ? this.fooStruct().unpack() : null));
+    }
+    unpackTo(_o) {
+        _o.fooTable = (this.fooTable() !== null ? this.fooTable().unpack() : null);
+        _o.fooEnum = this.fooEnum();
+        _o.fooUnionType = this.fooUnionType();
+        _o.fooUnion = (() => {
+            let temp = unionToUnionInNestedNS(this.fooUnionType(), this.fooUnion.bind(this));
+            if (temp === null) {
+                return null;
+            }
+            return temp.unpack();
+        })();
+        _o.fooStruct = (this.fooStruct() !== null ? this.fooStruct().unpack() : null);
+    }
+}
+export class TableInFirstNST {
+    constructor(fooTable = null, fooEnum = EnumInNestedNS.A, fooUnionType = UnionInNestedNS.NONE, fooUnion = null, fooStruct = null) {
+        this.fooTable = fooTable;
+        this.fooEnum = fooEnum;
+        this.fooUnionType = fooUnionType;
+        this.fooUnion = fooUnion;
+        this.fooStruct = fooStruct;
+    }
+    pack(builder) {
+        const fooTable = (this.fooTable !== null ? this.fooTable.pack(builder) : 0);
+        const fooUnion = builder.createObjectOffset(this.fooUnion);
+        TableInFirstNS.startTableInFirstNS(builder);
+        TableInFirstNS.addFooTable(builder, fooTable);
+        TableInFirstNS.addFooEnum(builder, this.fooEnum);
+        TableInFirstNS.addFooUnionType(builder, this.fooUnionType);
+        TableInFirstNS.addFooUnion(builder, fooUnion);
+        TableInFirstNS.addFooStruct(builder, (this.fooStruct !== null ? this.fooStruct.pack(builder) : 0));
+        return TableInFirstNS.endTableInFirstNS(builder);
+    }
+}
diff --git a/tests/namespace_test/namespace-a/table-in-first-n-s.ts b/tests/namespace_test/namespace-a/table-in-first-n-s.ts
new file mode 100644
index 0000000..8e4d706
--- /dev/null
+++ b/tests/namespace_test/namespace-a/table-in-first-n-s.ts
@@ -0,0 +1,150 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+import * as flatbuffers from 'flatbuffers';
+
+import { EnumInNestedNS } from '../namespace-a/namespace-b/enum-in-nested-n-s';
+import { StructInNestedNS, StructInNestedNST } from '../namespace-a/namespace-b/struct-in-nested-n-s';
+import { TableInNestedNS, TableInNestedNST } from '../namespace-a/namespace-b/table-in-nested-n-s';
+import { UnionInNestedNS, unionToUnionInNestedNS, unionListToUnionInNestedNS } from '../namespace-a/namespace-b/union-in-nested-n-s';
+
+
+export class TableInFirstNS {
+  bb: flatbuffers.ByteBuffer|null = null;
+  bb_pos = 0;
+__init(i:number, bb:flatbuffers.ByteBuffer):TableInFirstNS {
+  this.bb_pos = i;
+  this.bb = bb;
+  return this;
+}
+
+static getRootAsTableInFirstNS(bb:flatbuffers.ByteBuffer, obj?:TableInFirstNS):TableInFirstNS {
+  return (obj || new TableInFirstNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+}
+
+static getSizePrefixedRootAsTableInFirstNS(bb:flatbuffers.ByteBuffer, obj?:TableInFirstNS):TableInFirstNS {
+  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
+  return (obj || new TableInFirstNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+}
+
+fooTable(obj?:TableInNestedNS):TableInNestedNS|null {
+  const offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? (obj || new TableInNestedNS()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
+}
+
+fooEnum():EnumInNestedNS {
+  const offset = this.bb!.__offset(this.bb_pos, 6);
+  return offset ? this.bb!.readInt8(this.bb_pos + offset) : EnumInNestedNS.A;
+}
+
+mutate_foo_enum(value:EnumInNestedNS):boolean {
+  const offset = this.bb!.__offset(this.bb_pos, 6);
+
+  if (offset === 0) {
+    return false;
+  }
+
+  this.bb!.writeInt8(this.bb_pos + offset, value);
+  return true;
+}
+
+fooUnionType():UnionInNestedNS {
+  const offset = this.bb!.__offset(this.bb_pos, 8);
+  return offset ? this.bb!.readUint8(this.bb_pos + offset) : UnionInNestedNS.NONE;
+}
+
+fooUnion<T extends flatbuffers.Table>(obj:any):any|null {
+  const offset = this.bb!.__offset(this.bb_pos, 10);
+  return offset ? this.bb!.__union(obj, this.bb_pos + offset) : null;
+}
+
+fooStruct(obj?:StructInNestedNS):StructInNestedNS|null {
+  const offset = this.bb!.__offset(this.bb_pos, 12);
+  return offset ? (obj || new StructInNestedNS()).__init(this.bb_pos + offset, this.bb!) : null;
+}
+
+static getFullyQualifiedName():string {
+  return 'NamespaceA.TableInFirstNS';
+}
+
+static startTableInFirstNS(builder:flatbuffers.Builder) {
+  builder.startObject(5);
+}
+
+static addFooTable(builder:flatbuffers.Builder, fooTableOffset:flatbuffers.Offset) {
+  builder.addFieldOffset(0, fooTableOffset, 0);
+}
+
+static addFooEnum(builder:flatbuffers.Builder, fooEnum:EnumInNestedNS) {
+  builder.addFieldInt8(1, fooEnum, EnumInNestedNS.A);
+}
+
+static addFooUnionType(builder:flatbuffers.Builder, fooUnionType:UnionInNestedNS) {
+  builder.addFieldInt8(2, fooUnionType, UnionInNestedNS.NONE);
+}
+
+static addFooUnion(builder:flatbuffers.Builder, fooUnionOffset:flatbuffers.Offset) {
+  builder.addFieldOffset(3, fooUnionOffset, 0);
+}
+
+static addFooStruct(builder:flatbuffers.Builder, fooStructOffset:flatbuffers.Offset) {
+  builder.addFieldStruct(4, fooStructOffset, 0);
+}
+
+static endTableInFirstNS(builder:flatbuffers.Builder):flatbuffers.Offset {
+  const offset = builder.endObject();
+  return offset;
+}
+
+
+unpack(): TableInFirstNST {
+  return new TableInFirstNST(
+    (this.fooTable() !== null ? this.fooTable()!.unpack() : null),
+    this.fooEnum(),
+    this.fooUnionType(),
+    (() => {
+      let temp = unionToUnionInNestedNS(this.fooUnionType(), this.fooUnion.bind(this));
+      if(temp === null) { return null; }
+      return temp.unpack()
+  })(),
+    (this.fooStruct() !== null ? this.fooStruct()!.unpack() : null)
+  );
+}
+
+
+unpackTo(_o: TableInFirstNST): void {
+  _o.fooTable = (this.fooTable() !== null ? this.fooTable()!.unpack() : null);
+  _o.fooEnum = this.fooEnum();
+  _o.fooUnionType = this.fooUnionType();
+  _o.fooUnion = (() => {
+      let temp = unionToUnionInNestedNS(this.fooUnionType(), this.fooUnion.bind(this));
+      if(temp === null) { return null; }
+      return temp.unpack()
+  })();
+  _o.fooStruct = (this.fooStruct() !== null ? this.fooStruct()!.unpack() : null);
+}
+}
+
+export class TableInFirstNST {
+constructor(
+  public fooTable: TableInNestedNST|null = null,
+  public fooEnum: EnumInNestedNS = EnumInNestedNS.A,
+  public fooUnionType: UnionInNestedNS = UnionInNestedNS.NONE,
+  public fooUnion: TableInNestedNST|null = null,
+  public fooStruct: StructInNestedNST|null = null
+){}
+
+
+pack(builder:flatbuffers.Builder): flatbuffers.Offset {
+  const fooTable = (this.fooTable !== null ? this.fooTable!.pack(builder) : 0);
+  const fooUnion = builder.createObjectOffset(this.fooUnion);
+
+  TableInFirstNS.startTableInFirstNS(builder);
+  TableInFirstNS.addFooTable(builder, fooTable);
+  TableInFirstNS.addFooEnum(builder, this.fooEnum);
+  TableInFirstNS.addFooUnionType(builder, this.fooUnionType);
+  TableInFirstNS.addFooUnion(builder, fooUnion);
+  TableInFirstNS.addFooStruct(builder, (this.fooStruct !== null ? this.fooStruct!.pack(builder) : 0));
+
+  return TableInFirstNS.endTableInFirstNS(builder);
+}
+}
diff --git a/tests/namespace_test/namespace-c/table-in-c.js b/tests/namespace_test/namespace-c/table-in-c.js
new file mode 100644
index 0000000..d097a3c
--- /dev/null
+++ b/tests/namespace_test/namespace-c/table-in-c.js
@@ -0,0 +1,67 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+import * as flatbuffers from 'flatbuffers';
+import { SecondTableInA } from '../namespace-a/second-table-in-a';
+import { TableInFirstNS } from '../namespace-a/table-in-first-n-s';
+export class TableInC {
+    constructor() {
+        this.bb = null;
+        this.bb_pos = 0;
+    }
+    __init(i, bb) {
+        this.bb_pos = i;
+        this.bb = bb;
+        return this;
+    }
+    static getRootAsTableInC(bb, obj) {
+        return (obj || new TableInC()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+    }
+    static getSizePrefixedRootAsTableInC(bb, obj) {
+        bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
+        return (obj || new TableInC()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+    }
+    referToA1(obj) {
+        const offset = this.bb.__offset(this.bb_pos, 4);
+        return offset ? (obj || new TableInFirstNS()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
+    }
+    referToA2(obj) {
+        const offset = this.bb.__offset(this.bb_pos, 6);
+        return offset ? (obj || new SecondTableInA()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
+    }
+    static getFullyQualifiedName() {
+        return 'NamespaceC.TableInC';
+    }
+    static startTableInC(builder) {
+        builder.startObject(2);
+    }
+    static addReferToA1(builder, referToA1Offset) {
+        builder.addFieldOffset(0, referToA1Offset, 0);
+    }
+    static addReferToA2(builder, referToA2Offset) {
+        builder.addFieldOffset(1, referToA2Offset, 0);
+    }
+    static endTableInC(builder) {
+        const offset = builder.endObject();
+        return offset;
+    }
+    unpack() {
+        return new TableInCT((this.referToA1() !== null ? this.referToA1().unpack() : null), (this.referToA2() !== null ? this.referToA2().unpack() : null));
+    }
+    unpackTo(_o) {
+        _o.referToA1 = (this.referToA1() !== null ? this.referToA1().unpack() : null);
+        _o.referToA2 = (this.referToA2() !== null ? this.referToA2().unpack() : null);
+    }
+}
+export class TableInCT {
+    constructor(referToA1 = null, referToA2 = null) {
+        this.referToA1 = referToA1;
+        this.referToA2 = referToA2;
+    }
+    pack(builder) {
+        const referToA1 = (this.referToA1 !== null ? this.referToA1.pack(builder) : 0);
+        const referToA2 = (this.referToA2 !== null ? this.referToA2.pack(builder) : 0);
+        TableInC.startTableInC(builder);
+        TableInC.addReferToA1(builder, referToA1);
+        TableInC.addReferToA2(builder, referToA2);
+        return TableInC.endTableInC(builder);
+    }
+}
diff --git a/tests/namespace_test/namespace-c/table-in-c.ts b/tests/namespace_test/namespace-c/table-in-c.ts
new file mode 100644
index 0000000..7b924b8
--- /dev/null
+++ b/tests/namespace_test/namespace-c/table-in-c.ts
@@ -0,0 +1,90 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+
+import * as flatbuffers from 'flatbuffers';
+
+import { SecondTableInA, SecondTableInAT } from '../namespace-a/second-table-in-a';
+import { TableInFirstNS, TableInFirstNST } from '../namespace-a/table-in-first-n-s';
+
+
+export class TableInC {
+  bb: flatbuffers.ByteBuffer|null = null;
+  bb_pos = 0;
+__init(i:number, bb:flatbuffers.ByteBuffer):TableInC {
+  this.bb_pos = i;
+  this.bb = bb;
+  return this;
+}
+
+static getRootAsTableInC(bb:flatbuffers.ByteBuffer, obj?:TableInC):TableInC {
+  return (obj || new TableInC()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+}
+
+static getSizePrefixedRootAsTableInC(bb:flatbuffers.ByteBuffer, obj?:TableInC):TableInC {
+  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
+  return (obj || new TableInC()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
+}
+
+referToA1(obj?:TableInFirstNS):TableInFirstNS|null {
+  const offset = this.bb!.__offset(this.bb_pos, 4);
+  return offset ? (obj || new TableInFirstNS()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
+}
+
+referToA2(obj?:SecondTableInA):SecondTableInA|null {
+  const offset = this.bb!.__offset(this.bb_pos, 6);
+  return offset ? (obj || new SecondTableInA()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
+}
+
+static getFullyQualifiedName():string {
+  return 'NamespaceC.TableInC';
+}
+
+static startTableInC(builder:flatbuffers.Builder) {
+  builder.startObject(2);
+}
+
+static addReferToA1(builder:flatbuffers.Builder, referToA1Offset:flatbuffers.Offset) {
+  builder.addFieldOffset(0, referToA1Offset, 0);
+}
+
+static addReferToA2(builder:flatbuffers.Builder, referToA2Offset:flatbuffers.Offset) {
+  builder.addFieldOffset(1, referToA2Offset, 0);
+}
+
+static endTableInC(builder:flatbuffers.Builder):flatbuffers.Offset {
+  const offset = builder.endObject();
+  return offset;
+}
+
+
+unpack(): TableInCT {
+  return new TableInCT(
+    (this.referToA1() !== null ? this.referToA1()!.unpack() : null),
+    (this.referToA2() !== null ? this.referToA2()!.unpack() : null)
+  );
+}
+
+
+unpackTo(_o: TableInCT): void {
+  _o.referToA1 = (this.referToA1() !== null ? this.referToA1()!.unpack() : null);
+  _o.referToA2 = (this.referToA2() !== null ? this.referToA2()!.unpack() : null);
+}
+}
+
+export class TableInCT {
+constructor(
+  public referToA1: TableInFirstNST|null = null,
+  public referToA2: SecondTableInAT|null = null
+){}
+
+
+pack(builder:flatbuffers.Builder): flatbuffers.Offset {
+  const referToA1 = (this.referToA1 !== null ? this.referToA1!.pack(builder) : 0);
+  const referToA2 = (this.referToA2 !== null ? this.referToA2!.pack(builder) : 0);
+
+  TableInC.startTableInC(builder);
+  TableInC.addReferToA1(builder, referToA1);
+  TableInC.addReferToA2(builder, referToA2);
+
+  return TableInC.endTableInC(builder);
+}
+}
diff --git a/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs
new file mode 100644
index 0000000..b636638
--- /dev/null
+++ b/tests/namespace_test/namespace_a/namespace_b/enum_in_nested_ns_generated.rs
@@ -0,0 +1,97 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+extern crate flatbuffers;
+use std::mem;
+use std::cmp::Ordering;
+use self::flatbuffers::{EndianScalar, Follow};
+use super::*;
+#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
+pub const ENUM_MIN_ENUM_IN_NESTED_NS: i8 = 0;
+#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
+pub const ENUM_MAX_ENUM_IN_NESTED_NS: i8 = 2;
+#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
+#[allow(non_camel_case_types)]
+pub const ENUM_VALUES_ENUM_IN_NESTED_NS: [EnumInNestedNS; 3] = [
+  EnumInNestedNS::A,
+  EnumInNestedNS::B,
+  EnumInNestedNS::C,
+];
+
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
+#[repr(transparent)]
+pub struct EnumInNestedNS(pub i8);
+#[allow(non_upper_case_globals)]
+impl EnumInNestedNS {
+  pub const A: Self = Self(0);
+  pub const B: Self = Self(1);
+  pub const C: Self = Self(2);
+
+  pub const ENUM_MIN: i8 = 0;
+  pub const ENUM_MAX: i8 = 2;
+  pub const ENUM_VALUES: &'static [Self] = &[
+    Self::A,
+    Self::B,
+    Self::C,
+  ];
+  /// Returns the variant's name or "" if unknown.
+  pub fn variant_name(self) -> Option<&'static str> {
+    match self {
+      Self::A => Some("A"),
+      Self::B => Some("B"),
+      Self::C => Some("C"),
+      _ => None,
+    }
+  }
+}
+impl std::fmt::Debug for EnumInNestedNS {
+  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+    if let Some(name) = self.variant_name() {
+      f.write_str(name)
+    } else {
+      f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
+    }
+  }
+}
+impl<'a> flatbuffers::Follow<'a> for EnumInNestedNS {
+  type Inner = Self;
+  #[inline]
+  fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
+    let b = unsafe {
+      flatbuffers::read_scalar_at::<i8>(buf, loc)
+    };
+    Self(b)
+  }
+}
+
+impl flatbuffers::Push for EnumInNestedNS {
+    type Output = EnumInNestedNS;
+    #[inline]
+    fn push(&self, dst: &mut [u8], _rest: &[u8]) {
+        unsafe { flatbuffers::emplace_scalar::<i8>(dst, self.0); }
+    }
+}
+
+impl flatbuffers::EndianScalar for EnumInNestedNS {
+  #[inline]
+  fn to_little_endian(self) -> Self {
+    let b = i8::to_le(self.0);
+    Self(b)
+  }
+  #[inline]
+  #[allow(clippy::wrong_self_convention)]
+  fn from_little_endian(self) -> Self {
+    let b = i8::from_le(self.0);
+    Self(b)
+  }
+}
+
+impl<'a> flatbuffers::Verifiable for EnumInNestedNS {
+  #[inline]
+  fn run_verifier(
+    v: &mut flatbuffers::Verifier, pos: usize
+  ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
+    use self::flatbuffers::Verifiable;
+    i8::run_verifier(v, pos)
+  }
+}
+
+impl flatbuffers::SimpleToVerifyInSlice for EnumInNestedNS {}
diff --git a/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs
new file mode 100644
index 0000000..55fff40
--- /dev/null
+++ b/tests/namespace_test/namespace_a/namespace_b/struct_in_nested_ns_generated.rs
@@ -0,0 +1,156 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+extern crate flatbuffers;
+use std::mem;
+use std::cmp::Ordering;
+use self::flatbuffers::{EndianScalar, Follow};
+use super::*;
+// struct StructInNestedNS, aligned to 4
+#[repr(transparent)]
+#[derive(Clone, Copy, PartialEq)]
+pub struct StructInNestedNS(pub [u8; 8]);
+impl Default for StructInNestedNS { 
+  fn default() -> Self { 
+    Self([0; 8])
+  }
+}
+impl std::fmt::Debug for StructInNestedNS {
+  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+    f.debug_struct("StructInNestedNS")
+      .field("a", &self.a())
+      .field("b", &self.b())
+      .finish()
+  }
+}
+
+impl flatbuffers::SimpleToVerifyInSlice for StructInNestedNS {}
+impl flatbuffers::SafeSliceAccess for StructInNestedNS {}
+impl<'a> flatbuffers::Follow<'a> for StructInNestedNS {
+  type Inner = &'a StructInNestedNS;
+  #[inline]
+  fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
+    <&'a StructInNestedNS>::follow(buf, loc)
+  }
+}
+impl<'a> flatbuffers::Follow<'a> for &'a StructInNestedNS {
+  type Inner = &'a StructInNestedNS;
+  #[inline]
+  fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
+    flatbuffers::follow_cast_ref::<StructInNestedNS>(buf, loc)
+  }
+}
+impl<'b> flatbuffers::Push for StructInNestedNS {
+    type Output = StructInNestedNS;
+    #[inline]
+    fn push(&self, dst: &mut [u8], _rest: &[u8]) {
+        let src = unsafe {
+            ::std::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size())
+        };
+        dst.copy_from_slice(src);
+    }
+}
+impl<'b> flatbuffers::Push for &'b StructInNestedNS {
+    type Output = StructInNestedNS;
+
+    #[inline]
+    fn push(&self, dst: &mut [u8], _rest: &[u8]) {
+        let src = unsafe {
+            ::std::slice::from_raw_parts(*self as *const StructInNestedNS as *const u8, Self::size())
+        };
+        dst.copy_from_slice(src);
+    }
+}
+
+impl<'a> flatbuffers::Verifiable for StructInNestedNS {
+  #[inline]
+  fn run_verifier(
+    v: &mut flatbuffers::Verifier, pos: usize
+  ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
+    use self::flatbuffers::Verifiable;
+    v.in_buffer::<Self>(pos)
+  }
+}
+
+impl<'a> StructInNestedNS {
+  #[allow(clippy::too_many_arguments)]
+  pub fn new(
+    a: i32,
+    b: i32,
+  ) -> Self {
+    let mut s = Self([0; 8]);
+    s.set_a(a);
+    s.set_b(b);
+    s
+  }
+
+  pub const fn get_fully_qualified_name() -> &'static str {
+    "NamespaceA.NamespaceB.StructInNestedNS"
+  }
+
+  pub fn a(&self) -> i32 {
+    let mut mem = core::mem::MaybeUninit::<i32>::uninit();
+    unsafe {
+      core::ptr::copy_nonoverlapping(
+        self.0[0..].as_ptr(),
+        mem.as_mut_ptr() as *mut u8,
+        core::mem::size_of::<i32>(),
+      );
+      mem.assume_init()
+    }.from_little_endian()
+  }
+
+  pub fn set_a(&mut self, x: i32) {
+    let x_le = x.to_little_endian();
+    unsafe {
+      core::ptr::copy_nonoverlapping(
+        &x_le as *const i32 as *const u8,
+        self.0[0..].as_mut_ptr(),
+        core::mem::size_of::<i32>(),
+      );
+    }
+  }
+
+  pub fn b(&self) -> i32 {
+    let mut mem = core::mem::MaybeUninit::<i32>::uninit();
+    unsafe {
+      core::ptr::copy_nonoverlapping(
+        self.0[4..].as_ptr(),
+        mem.as_mut_ptr() as *mut u8,
+        core::mem::size_of::<i32>(),
+      );
+      mem.assume_init()
+    }.from_little_endian()
+  }
+
+  pub fn set_b(&mut self, x: i32) {
+    let x_le = x.to_little_endian();
+    unsafe {
+      core::ptr::copy_nonoverlapping(
+        &x_le as *const i32 as *const u8,
+        self.0[4..].as_mut_ptr(),
+        core::mem::size_of::<i32>(),
+      );
+    }
+  }
+
+  pub fn unpack(&self) -> StructInNestedNST {
+    StructInNestedNST {
+      a: self.a(),
+      b: self.b(),
+    }
+  }
+}
+
+#[derive(Debug, Clone, PartialEq, Default)]
+pub struct StructInNestedNST {
+  pub a: i32,
+  pub b: i32,
+}
+impl StructInNestedNST {
+  pub fn pack(&self) -> StructInNestedNS {
+    StructInNestedNS::new(
+      self.a,
+      self.b,
+    )
+  }
+}
+
diff --git a/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs
new file mode 100644
index 0000000..10d5b7c
--- /dev/null
+++ b/tests/namespace_test/namespace_a/namespace_b/table_in_nested_ns_generated.rs
@@ -0,0 +1,133 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+extern crate flatbuffers;
+use std::mem;
+use std::cmp::Ordering;
+use self::flatbuffers::{EndianScalar, Follow};
+use super::*;
+pub enum TableInNestedNSOffset {}
+#[derive(Copy, Clone, PartialEq)]
+
+pub struct TableInNestedNS<'a> {
+  pub _tab: flatbuffers::Table<'a>,
+}
+
+impl<'a> flatbuffers::Follow<'a> for TableInNestedNS<'a> {
+  type Inner = TableInNestedNS<'a>;
+  #[inline]
+  fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
+    Self { _tab: flatbuffers::Table { buf, loc } }
+  }
+}
+
+impl<'a> TableInNestedNS<'a> {
+  pub const VT_FOO: flatbuffers::VOffsetT = 4;
+
+  pub const fn get_fully_qualified_name() -> &'static str {
+    "NamespaceA.NamespaceB.TableInNestedNS"
+  }
+
+  #[inline]
+  pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
+    TableInNestedNS { _tab: table }
+  }
+  #[allow(unused_mut)]
+  pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
+    _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
+    args: &'args TableInNestedNSArgs
+  ) -> flatbuffers::WIPOffset<TableInNestedNS<'bldr>> {
+    let mut builder = TableInNestedNSBuilder::new(_fbb);
+    builder.add_foo(args.foo);
+    builder.finish()
+  }
+
+  pub fn unpack(&self) -> TableInNestedNST {
+    let foo = self.foo();
+    TableInNestedNST {
+      foo,
+    }
+  }
+
+  #[inline]
+  pub fn foo(&self) -> i32 {
+    self._tab.get::<i32>(TableInNestedNS::VT_FOO, Some(0)).unwrap()
+  }
+}
+
+impl flatbuffers::Verifiable for TableInNestedNS<'_> {
+  #[inline]
+  fn run_verifier(
+    v: &mut flatbuffers::Verifier, pos: usize
+  ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
+    use self::flatbuffers::Verifiable;
+    v.visit_table(pos)?
+     .visit_field::<i32>("foo", Self::VT_FOO, false)?
+     .finish();
+    Ok(())
+  }
+}
+pub struct TableInNestedNSArgs {
+    pub foo: i32,
+}
+impl<'a> Default for TableInNestedNSArgs {
+  #[inline]
+  fn default() -> Self {
+    TableInNestedNSArgs {
+      foo: 0,
+    }
+  }
+}
+
+pub struct TableInNestedNSBuilder<'a: 'b, 'b> {
+  fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
+  start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
+}
+impl<'a: 'b, 'b> TableInNestedNSBuilder<'a, 'b> {
+  #[inline]
+  pub fn add_foo(&mut self, foo: i32) {
+    self.fbb_.push_slot::<i32>(TableInNestedNS::VT_FOO, foo, 0);
+  }
+  #[inline]
+  pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> TableInNestedNSBuilder<'a, 'b> {
+    let start = _fbb.start_table();
+    TableInNestedNSBuilder {
+      fbb_: _fbb,
+      start_: start,
+    }
+  }
+  #[inline]
+  pub fn finish(self) -> flatbuffers::WIPOffset<TableInNestedNS<'a>> {
+    let o = self.fbb_.end_table(self.start_);
+    flatbuffers::WIPOffset::new(o.value())
+  }
+}
+
+impl std::fmt::Debug for TableInNestedNS<'_> {
+  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+    let mut ds = f.debug_struct("TableInNestedNS");
+      ds.field("foo", &self.foo());
+      ds.finish()
+  }
+}
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq)]
+pub struct TableInNestedNST {
+  pub foo: i32,
+}
+impl Default for TableInNestedNST {
+  fn default() -> Self {
+    Self {
+      foo: 0,
+    }
+  }
+}
+impl TableInNestedNST {
+  pub fn pack<'b>(
+    &self,
+    _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
+  ) -> flatbuffers::WIPOffset<TableInNestedNS<'b>> {
+    let foo = self.foo;
+    TableInNestedNS::create(_fbb, &TableInNestedNSArgs{
+      foo,
+    })
+  }
+}
diff --git a/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs b/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs
new file mode 100644
index 0000000..8d650a5
--- /dev/null
+++ b/tests/namespace_test/namespace_a/namespace_b/union_in_nested_ns_generated.rs
@@ -0,0 +1,142 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+extern crate flatbuffers;
+use std::mem;
+use std::cmp::Ordering;
+use self::flatbuffers::{EndianScalar, Follow};
+use super::*;
+#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
+pub const ENUM_MIN_UNION_IN_NESTED_NS: u8 = 0;
+#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
+pub const ENUM_MAX_UNION_IN_NESTED_NS: u8 = 1;
+#[deprecated(since = "2.0.0", note = "Use associated constants instead. This will no longer be generated in 2021.")]
+#[allow(non_camel_case_types)]
+pub const ENUM_VALUES_UNION_IN_NESTED_NS: [UnionInNestedNS; 2] = [
+  UnionInNestedNS::NONE,
+  UnionInNestedNS::TableInNestedNS,
+];
+
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
+#[repr(transparent)]
+pub struct UnionInNestedNS(pub u8);
+#[allow(non_upper_case_globals)]
+impl UnionInNestedNS {
+  pub const NONE: Self = Self(0);
+  pub const TableInNestedNS: Self = Self(1);
+
+  pub const ENUM_MIN: u8 = 0;
+  pub const ENUM_MAX: u8 = 1;
+  pub const ENUM_VALUES: &'static [Self] = &[
+    Self::NONE,
+    Self::TableInNestedNS,
+  ];
+  /// Returns the variant's name or "" if unknown.
+  pub fn variant_name(self) -> Option<&'static str> {
+    match self {
+      Self::NONE => Some("NONE"),
+      Self::TableInNestedNS => Some("TableInNestedNS"),
+      _ => None,
+    }
+  }
+}
+impl std::fmt::Debug for UnionInNestedNS {
+  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
+    if let Some(name) = self.variant_name() {
+      f.write_str(name)
+    } else {
+      f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
+    }
+  }
+}
+impl<'a> flatbuffers::Follow<'a> for UnionInNestedNS {
+  type Inner = Self;
+  #[inline]
+  fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
+    let b = unsafe {
+      flatbuffers::read_scalar_at::<u8>(buf, loc)
+    };
+    Self(b)
+  }
+}
+
+impl flatbuffers::Push for UnionInNestedNS {
+    type Output = UnionInNestedNS;
+    #[inline]
+    fn push(&self, dst: &mut [u8], _rest: &[u8]) {
+        unsafe { flatbuffers::emplace_scalar::<u8>(dst, self.0); }
+    }
+}
+
+impl flatbuffers::EndianScalar for UnionInNestedNS {
+  #[inline]
+  fn to_little_endian(self) -> Self {
+    let b = u8::to_le(self.0);
+    Self(b)
+  }
+  #[inline]
+  #[allow(clippy::wrong_self_convention)]
+  fn from_little_endian(self) -> Self {
+    let b = u8::from_le(self.0);
+    Self(b)
+  }
+}
+
+impl<'a> flatbuffers::Verifiable for UnionInNestedNS {
+  #[inline]
+  fn run_verifier(
+    v: &mut flatbuffers::Verifier, pos: usize
+  ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
+    use self::flatbuffers::Verifiable;
+    u8::run_verifier(v, pos)
+  }
+}
+
+impl flatbuffers::SimpleToVerifyInSlice for UnionInNestedNS {}
+pub struct UnionInNestedNSUnionTableOffset {}
+
+#[allow(clippy::upper_case_acronyms)]
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq)]
+pub enum UnionInNestedNST {
+  NONE,
+  TableInNestedNS(Box<TableInNestedNST>),
+}
+impl Default for UnionInNestedNST {
+  fn default() -> Self {
+    Self::NONE
+  }
+}
+impl UnionInNestedNST {
+  pub fn union_in_nested_ns_type(&self) -> UnionInNestedNS {
+    match self {
+      Self::NONE => UnionInNestedNS::NONE,
+      Self::TableInNestedNS(_) => UnionInNestedNS::TableInNestedNS,
+    }
+  }
+  pub fn pack(&self, fbb: &mut flatbuffers::FlatBufferBuilder) -> Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>> {
+    match self {
+      Self::NONE => None,
+      Self::TableInNestedNS(v) => Some(v.pack(fbb).as_union_value()),
+    }
+  }
+  /// If the union variant matches, return the owned TableInNestedNST, setting the union to NONE.
+  pub fn take_table_in_nested_ns(&mut self) -> Option<Box<TableInNestedNST>> {
+    if let Self::TableInNestedNS(_) = self {
+      let v = std::mem::replace(self, Self::NONE);
+      if let Self::TableInNestedNS(w) = v {
+        Some(w)
+      } else {
+        unreachable!()
+      }
+    } else {
+      None
+    }
+  }
+  /// If the union variant matches, return a reference to the TableInNestedNST.
+  pub fn as_table_in_nested_ns(&self) -> Option<&TableInNestedNST> {
+    if let Self::TableInNestedNS(v) = self { Some(v.as_ref()) } else { None }
+  }
+  /// If the union variant matches, return a mutable reference to the TableInNestedNST.
+  pub fn as_table_in_nested_ns_mut(&mut self) -> Option<&mut TableInNestedNST> {
+    if let Self::TableInNestedNS(v) = self { Some(v.as_mut()) } else { None }
+  }
+}
diff --git a/tests/namespace_test/namespace_a/second_table_in_a_generated.rs b/tests/namespace_test/namespace_a/second_table_in_a_generated.rs
new file mode 100644
index 0000000..d63438b
--- /dev/null
+++ b/tests/namespace_test/namespace_a/second_table_in_a_generated.rs
@@ -0,0 +1,137 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+extern crate flatbuffers;
+use std::mem;
+use std::cmp::Ordering;
+use self::flatbuffers::{EndianScalar, Follow};
+use super::*;
+pub enum SecondTableInAOffset {}
+#[derive(Copy, Clone, PartialEq)]
+
+pub struct SecondTableInA<'a> {
+  pub _tab: flatbuffers::Table<'a>,
+}
+
+impl<'a> flatbuffers::Follow<'a> for SecondTableInA<'a> {
+  type Inner = SecondTableInA<'a>;
+  #[inline]
+  fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
+    Self { _tab: flatbuffers::Table { buf, loc } }
+  }
+}
+
+impl<'a> SecondTableInA<'a> {
+  pub const VT_REFER_TO_C: flatbuffers::VOffsetT = 4;
+
+  pub const fn get_fully_qualified_name() -> &'static str {
+    "NamespaceA.SecondTableInA"
+  }
+
+  #[inline]
+  pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
+    SecondTableInA { _tab: table }
+  }
+  #[allow(unused_mut)]
+  pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
+    _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
+    args: &'args SecondTableInAArgs<'args>
+  ) -> flatbuffers::WIPOffset<SecondTableInA<'bldr>> {
+    let mut builder = SecondTableInABuilder::new(_fbb);
+    if let Some(x) = args.refer_to_c { builder.add_refer_to_c(x); }
+    builder.finish()
+  }
+
+  pub fn unpack(&self) -> SecondTableInAT {
+    let refer_to_c = self.refer_to_c().map(|x| {
+      Box::new(x.unpack())
+    });
+    SecondTableInAT {
+      refer_to_c,
+    }
+  }
+
+  #[inline]
+  pub fn refer_to_c(&self) -> Option<super::namespace_c::TableInC<'a>> {
+    self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_c::TableInC>>(SecondTableInA::VT_REFER_TO_C, None)
+  }
+}
+
+impl flatbuffers::Verifiable for SecondTableInA<'_> {
+  #[inline]
+  fn run_verifier(
+    v: &mut flatbuffers::Verifier, pos: usize
+  ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
+    use self::flatbuffers::Verifiable;
+    v.visit_table(pos)?
+     .visit_field::<flatbuffers::ForwardsUOffset<super::namespace_c::TableInC>>("refer_to_c", Self::VT_REFER_TO_C, false)?
+     .finish();
+    Ok(())
+  }
+}
+pub struct SecondTableInAArgs<'a> {
+    pub refer_to_c: Option<flatbuffers::WIPOffset<super::namespace_c::TableInC<'a>>>,
+}
+impl<'a> Default for SecondTableInAArgs<'a> {
+  #[inline]
+  fn default() -> Self {
+    SecondTableInAArgs {
+      refer_to_c: None,
+    }
+  }
+}
+
+pub struct SecondTableInABuilder<'a: 'b, 'b> {
+  fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
+  start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
+}
+impl<'a: 'b, 'b> SecondTableInABuilder<'a, 'b> {
+  #[inline]
+  pub fn add_refer_to_c(&mut self, refer_to_c: flatbuffers::WIPOffset<super::namespace_c::TableInC<'b >>) {
+    self.fbb_.push_slot_always::<flatbuffers::WIPOffset<super::namespace_c::TableInC>>(SecondTableInA::VT_REFER_TO_C, refer_to_c);
+  }
+  #[inline]
+  pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> SecondTableInABuilder<'a, 'b> {
+    let start = _fbb.start_table();
+    SecondTableInABuilder {
+      fbb_: _fbb,
+      start_: start,
+    }
+  }
+  #[inline]
+  pub fn finish(self) -> flatbuffers::WIPOffset<SecondTableInA<'a>> {
+    let o = self.fbb_.end_table(self.start_);
+    flatbuffers::WIPOffset::new(o.value())
+  }
+}
+
+impl std::fmt::Debug for SecondTableInA<'_> {
+  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+    let mut ds = f.debug_struct("SecondTableInA");
+      ds.field("refer_to_c", &self.refer_to_c());
+      ds.finish()
+  }
+}
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq)]
+pub struct SecondTableInAT {
+  pub refer_to_c: Option<Box<super::namespace_c::TableInCT>>,
+}
+impl Default for SecondTableInAT {
+  fn default() -> Self {
+    Self {
+      refer_to_c: None,
+    }
+  }
+}
+impl SecondTableInAT {
+  pub fn pack<'b>(
+    &self,
+    _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
+  ) -> flatbuffers::WIPOffset<SecondTableInA<'b>> {
+    let refer_to_c = self.refer_to_c.as_ref().map(|x|{
+      x.pack(_fbb)
+    });
+    SecondTableInA::create(_fbb, &SecondTableInAArgs{
+      refer_to_c,
+    })
+  }
+}
diff --git a/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs b/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs
new file mode 100644
index 0000000..0a16074
--- /dev/null
+++ b/tests/namespace_test/namespace_a/table_in_first_ns_generated.rs
@@ -0,0 +1,250 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+extern crate flatbuffers;
+use std::mem;
+use std::cmp::Ordering;
+use self::flatbuffers::{EndianScalar, Follow};
+use super::*;
+pub enum TableInFirstNSOffset {}
+#[derive(Copy, Clone, PartialEq)]
+
+pub struct TableInFirstNS<'a> {
+  pub _tab: flatbuffers::Table<'a>,
+}
+
+impl<'a> flatbuffers::Follow<'a> for TableInFirstNS<'a> {
+  type Inner = TableInFirstNS<'a>;
+  #[inline]
+  fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
+    Self { _tab: flatbuffers::Table { buf, loc } }
+  }
+}
+
+impl<'a> TableInFirstNS<'a> {
+  pub const VT_FOO_TABLE: flatbuffers::VOffsetT = 4;
+  pub const VT_FOO_ENUM: flatbuffers::VOffsetT = 6;
+  pub const VT_FOO_UNION_TYPE: flatbuffers::VOffsetT = 8;
+  pub const VT_FOO_UNION: flatbuffers::VOffsetT = 10;
+  pub const VT_FOO_STRUCT: flatbuffers::VOffsetT = 12;
+
+  pub const fn get_fully_qualified_name() -> &'static str {
+    "NamespaceA.TableInFirstNS"
+  }
+
+  #[inline]
+  pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
+    TableInFirstNS { _tab: table }
+  }
+  #[allow(unused_mut)]
+  pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
+    _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
+    args: &'args TableInFirstNSArgs<'args>
+  ) -> flatbuffers::WIPOffset<TableInFirstNS<'bldr>> {
+    let mut builder = TableInFirstNSBuilder::new(_fbb);
+    if let Some(x) = args.foo_struct { builder.add_foo_struct(x); }
+    if let Some(x) = args.foo_union { builder.add_foo_union(x); }
+    if let Some(x) = args.foo_table { builder.add_foo_table(x); }
+    builder.add_foo_union_type(args.foo_union_type);
+    builder.add_foo_enum(args.foo_enum);
+    builder.finish()
+  }
+
+  pub fn unpack(&self) -> TableInFirstNST {
+    let foo_table = self.foo_table().map(|x| {
+      Box::new(x.unpack())
+    });
+    let foo_enum = self.foo_enum();
+    let foo_union = match self.foo_union_type() {
+      namespace_b::UnionInNestedNS::NONE => namespace_b::UnionInNestedNST::NONE,
+      namespace_b::UnionInNestedNS::TableInNestedNS => namespace_b::UnionInNestedNST::TableInNestedNS(Box::new(
+        self.foo_union_as_table_in_nested_ns()
+            .expect("Invalid union table, expected `namespace_b::UnionInNestedNS::TableInNestedNS`.")
+            .unpack()
+      )),
+      _ => namespace_b::UnionInNestedNST::NONE,
+    };
+    let foo_struct = self.foo_struct().map(|x| {
+      x.unpack()
+    });
+    TableInFirstNST {
+      foo_table,
+      foo_enum,
+      foo_union,
+      foo_struct,
+    }
+  }
+
+  #[inline]
+  pub fn foo_table(&self) -> Option<namespace_b::TableInNestedNS<'a>> {
+    self._tab.get::<flatbuffers::ForwardsUOffset<namespace_b::TableInNestedNS>>(TableInFirstNS::VT_FOO_TABLE, None)
+  }
+  #[inline]
+  pub fn foo_enum(&self) -> namespace_b::EnumInNestedNS {
+    self._tab.get::<namespace_b::EnumInNestedNS>(TableInFirstNS::VT_FOO_ENUM, Some(namespace_b::EnumInNestedNS::A)).unwrap()
+  }
+  #[inline]
+  pub fn foo_union_type(&self) -> namespace_b::UnionInNestedNS {
+    self._tab.get::<namespace_b::UnionInNestedNS>(TableInFirstNS::VT_FOO_UNION_TYPE, Some(namespace_b::UnionInNestedNS::NONE)).unwrap()
+  }
+  #[inline]
+  pub fn foo_union(&self) -> Option<flatbuffers::Table<'a>> {
+    self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Table<'a>>>(TableInFirstNS::VT_FOO_UNION, None)
+  }
+  #[inline]
+  pub fn foo_struct(&self) -> Option<&'a namespace_b::StructInNestedNS> {
+    self._tab.get::<namespace_b::StructInNestedNS>(TableInFirstNS::VT_FOO_STRUCT, None)
+  }
+  #[inline]
+  #[allow(non_snake_case)]
+  pub fn foo_union_as_table_in_nested_ns(&self) -> Option<namespace_b::TableInNestedNS<'a>> {
+    if self.foo_union_type() == namespace_b::UnionInNestedNS::TableInNestedNS {
+      self.foo_union().map(namespace_b::TableInNestedNS::init_from_table)
+    } else {
+      None
+    }
+  }
+
+}
+
+impl flatbuffers::Verifiable for TableInFirstNS<'_> {
+  #[inline]
+  fn run_verifier(
+    v: &mut flatbuffers::Verifier, pos: usize
+  ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
+    use self::flatbuffers::Verifiable;
+    v.visit_table(pos)?
+     .visit_field::<flatbuffers::ForwardsUOffset<namespace_b::TableInNestedNS>>("foo_table", Self::VT_FOO_TABLE, false)?
+     .visit_field::<namespace_b::EnumInNestedNS>("foo_enum", Self::VT_FOO_ENUM, false)?
+     .visit_union::<namespace_b::UnionInNestedNS, _>("foo_union_type", Self::VT_FOO_UNION_TYPE, "foo_union", Self::VT_FOO_UNION, false, |key, v, pos| {
+        match key {
+          namespace_b::UnionInNestedNS::TableInNestedNS => v.verify_union_variant::<flatbuffers::ForwardsUOffset<namespace_b::TableInNestedNS>>("namespace_b::UnionInNestedNS::TableInNestedNS", pos),
+          _ => Ok(()),
+        }
+     })?
+     .visit_field::<namespace_b::StructInNestedNS>("foo_struct", Self::VT_FOO_STRUCT, false)?
+     .finish();
+    Ok(())
+  }
+}
+pub struct TableInFirstNSArgs<'a> {
+    pub foo_table: Option<flatbuffers::WIPOffset<namespace_b::TableInNestedNS<'a>>>,
+    pub foo_enum: namespace_b::EnumInNestedNS,
+    pub foo_union_type: namespace_b::UnionInNestedNS,
+    pub foo_union: Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>,
+    pub foo_struct: Option<&'a namespace_b::StructInNestedNS>,
+}
+impl<'a> Default for TableInFirstNSArgs<'a> {
+  #[inline]
+  fn default() -> Self {
+    TableInFirstNSArgs {
+      foo_table: None,
+      foo_enum: namespace_b::EnumInNestedNS::A,
+      foo_union_type: namespace_b::UnionInNestedNS::NONE,
+      foo_union: None,
+      foo_struct: None,
+    }
+  }
+}
+
+pub struct TableInFirstNSBuilder<'a: 'b, 'b> {
+  fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
+  start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
+}
+impl<'a: 'b, 'b> TableInFirstNSBuilder<'a, 'b> {
+  #[inline]
+  pub fn add_foo_table(&mut self, foo_table: flatbuffers::WIPOffset<namespace_b::TableInNestedNS<'b >>) {
+    self.fbb_.push_slot_always::<flatbuffers::WIPOffset<namespace_b::TableInNestedNS>>(TableInFirstNS::VT_FOO_TABLE, foo_table);
+  }
+  #[inline]
+  pub fn add_foo_enum(&mut self, foo_enum: namespace_b::EnumInNestedNS) {
+    self.fbb_.push_slot::<namespace_b::EnumInNestedNS>(TableInFirstNS::VT_FOO_ENUM, foo_enum, namespace_b::EnumInNestedNS::A);
+  }
+  #[inline]
+  pub fn add_foo_union_type(&mut self, foo_union_type: namespace_b::UnionInNestedNS) {
+    self.fbb_.push_slot::<namespace_b::UnionInNestedNS>(TableInFirstNS::VT_FOO_UNION_TYPE, foo_union_type, namespace_b::UnionInNestedNS::NONE);
+  }
+  #[inline]
+  pub fn add_foo_union(&mut self, foo_union: flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>) {
+    self.fbb_.push_slot_always::<flatbuffers::WIPOffset<_>>(TableInFirstNS::VT_FOO_UNION, foo_union);
+  }
+  #[inline]
+  pub fn add_foo_struct(&mut self, foo_struct: &namespace_b::StructInNestedNS) {
+    self.fbb_.push_slot_always::<&namespace_b::StructInNestedNS>(TableInFirstNS::VT_FOO_STRUCT, foo_struct);
+  }
+  #[inline]
+  pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> TableInFirstNSBuilder<'a, 'b> {
+    let start = _fbb.start_table();
+    TableInFirstNSBuilder {
+      fbb_: _fbb,
+      start_: start,
+    }
+  }
+  #[inline]
+  pub fn finish(self) -> flatbuffers::WIPOffset<TableInFirstNS<'a>> {
+    let o = self.fbb_.end_table(self.start_);
+    flatbuffers::WIPOffset::new(o.value())
+  }
+}
+
+impl std::fmt::Debug for TableInFirstNS<'_> {
+  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+    let mut ds = f.debug_struct("TableInFirstNS");
+      ds.field("foo_table", &self.foo_table());
+      ds.field("foo_enum", &self.foo_enum());
+      ds.field("foo_union_type", &self.foo_union_type());
+      match self.foo_union_type() {
+        namespace_b::UnionInNestedNS::TableInNestedNS => {
+          if let Some(x) = self.foo_union_as_table_in_nested_ns() {
+            ds.field("foo_union", &x)
+          } else {
+            ds.field("foo_union", &"InvalidFlatbuffer: Union discriminant does not match value.")
+          }
+        },
+        _ => {
+          let x: Option<()> = None;
+          ds.field("foo_union", &x)
+        },
+      };
+      ds.field("foo_struct", &self.foo_struct());
+      ds.finish()
+  }
+}
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq)]
+pub struct TableInFirstNST {
+  pub foo_table: Option<Box<namespace_b::TableInNestedNST>>,
+  pub foo_enum: namespace_b::EnumInNestedNS,
+  pub foo_union: namespace_b::UnionInNestedNST,
+  pub foo_struct: Option<namespace_b::StructInNestedNST>,
+}
+impl Default for TableInFirstNST {
+  fn default() -> Self {
+    Self {
+      foo_table: None,
+      foo_enum: namespace_b::EnumInNestedNS::A,
+      foo_union: namespace_b::UnionInNestedNST::NONE,
+      foo_struct: None,
+    }
+  }
+}
+impl TableInFirstNST {
+  pub fn pack<'b>(
+    &self,
+    _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
+  ) -> flatbuffers::WIPOffset<TableInFirstNS<'b>> {
+    let foo_table = self.foo_table.as_ref().map(|x|{
+      x.pack(_fbb)
+    });
+    let foo_enum = self.foo_enum;
+    let foo_union_type = self.foo_union.union_in_nested_ns_type();
+    let foo_union = self.foo_union.pack(_fbb);
+    let foo_struct_tmp = self.foo_struct.as_ref().map(|x| x.pack());
+    let foo_struct = foo_struct_tmp.as_ref();
+    TableInFirstNS::create(_fbb, &TableInFirstNSArgs{
+      foo_table,
+      foo_enum,
+      foo_union_type,
+      foo_union,
+      foo_struct,
+    })
+  }
+}
diff --git a/tests/namespace_test/namespace_c/table_in_c_generated.rs b/tests/namespace_test/namespace_c/table_in_c_generated.rs
new file mode 100644
index 0000000..d4ac783
--- /dev/null
+++ b/tests/namespace_test/namespace_c/table_in_c_generated.rs
@@ -0,0 +1,161 @@
+// automatically generated by the FlatBuffers compiler, do not modify
+extern crate flatbuffers;
+use std::mem;
+use std::cmp::Ordering;
+use self::flatbuffers::{EndianScalar, Follow};
+use super::*;
+pub enum TableInCOffset {}
+#[derive(Copy, Clone, PartialEq)]
+
+pub struct TableInC<'a> {
+  pub _tab: flatbuffers::Table<'a>,
+}
+
+impl<'a> flatbuffers::Follow<'a> for TableInC<'a> {
+  type Inner = TableInC<'a>;
+  #[inline]
+  fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
+    Self { _tab: flatbuffers::Table { buf, loc } }
+  }
+}
+
+impl<'a> TableInC<'a> {
+  pub const VT_REFER_TO_A1: flatbuffers::VOffsetT = 4;
+  pub const VT_REFER_TO_A2: flatbuffers::VOffsetT = 6;
+
+  pub const fn get_fully_qualified_name() -> &'static str {
+    "NamespaceC.TableInC"
+  }
+
+  #[inline]
+  pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
+    TableInC { _tab: table }
+  }
+  #[allow(unused_mut)]
+  pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
+    _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
+    args: &'args TableInCArgs<'args>
+  ) -> flatbuffers::WIPOffset<TableInC<'bldr>> {
+    let mut builder = TableInCBuilder::new(_fbb);
+    if let Some(x) = args.refer_to_a2 { builder.add_refer_to_a2(x); }
+    if let Some(x) = args.refer_to_a1 { builder.add_refer_to_a1(x); }
+    builder.finish()
+  }
+
+  pub fn unpack(&self) -> TableInCT {
+    let refer_to_a1 = self.refer_to_a1().map(|x| {
+      Box::new(x.unpack())
+    });
+    let refer_to_a2 = self.refer_to_a2().map(|x| {
+      Box::new(x.unpack())
+    });
+    TableInCT {
+      refer_to_a1,
+      refer_to_a2,
+    }
+  }
+
+  #[inline]
+  pub fn refer_to_a1(&self) -> Option<super::namespace_a::TableInFirstNS<'a>> {
+    self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_a::TableInFirstNS>>(TableInC::VT_REFER_TO_A1, None)
+  }
+  #[inline]
+  pub fn refer_to_a2(&self) -> Option<super::namespace_a::SecondTableInA<'a>> {
+    self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_a::SecondTableInA>>(TableInC::VT_REFER_TO_A2, None)
+  }
+}
+
+impl flatbuffers::Verifiable for TableInC<'_> {
+  #[inline]
+  fn run_verifier(
+    v: &mut flatbuffers::Verifier, pos: usize
+  ) -> Result<(), flatbuffers::InvalidFlatbuffer> {
+    use self::flatbuffers::Verifiable;
+    v.visit_table(pos)?
+     .visit_field::<flatbuffers::ForwardsUOffset<super::namespace_a::TableInFirstNS>>("refer_to_a1", Self::VT_REFER_TO_A1, false)?
+     .visit_field::<flatbuffers::ForwardsUOffset<super::namespace_a::SecondTableInA>>("refer_to_a2", Self::VT_REFER_TO_A2, false)?
+     .finish();
+    Ok(())
+  }
+}
+pub struct TableInCArgs<'a> {
+    pub refer_to_a1: Option<flatbuffers::WIPOffset<super::namespace_a::TableInFirstNS<'a>>>,
+    pub refer_to_a2: Option<flatbuffers::WIPOffset<super::namespace_a::SecondTableInA<'a>>>,
+}
+impl<'a> Default for TableInCArgs<'a> {
+  #[inline]
+  fn default() -> Self {
+    TableInCArgs {
+      refer_to_a1: None,
+      refer_to_a2: None,
+    }
+  }
+}
+
+pub struct TableInCBuilder<'a: 'b, 'b> {
+  fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
+  start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
+}
+impl<'a: 'b, 'b> TableInCBuilder<'a, 'b> {
+  #[inline]
+  pub fn add_refer_to_a1(&mut self, refer_to_a1: flatbuffers::WIPOffset<super::namespace_a::TableInFirstNS<'b >>) {
+    self.fbb_.push_slot_always::<flatbuffers::WIPOffset<super::namespace_a::TableInFirstNS>>(TableInC::VT_REFER_TO_A1, refer_to_a1);
+  }
+  #[inline]
+  pub fn add_refer_to_a2(&mut self, refer_to_a2: flatbuffers::WIPOffset<super::namespace_a::SecondTableInA<'b >>) {
+    self.fbb_.push_slot_always::<flatbuffers::WIPOffset<super::namespace_a::SecondTableInA>>(TableInC::VT_REFER_TO_A2, refer_to_a2);
+  }
+  #[inline]
+  pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> TableInCBuilder<'a, 'b> {
+    let start = _fbb.start_table();
+    TableInCBuilder {
+      fbb_: _fbb,
+      start_: start,
+    }
+  }
+  #[inline]
+  pub fn finish(self) -> flatbuffers::WIPOffset<TableInC<'a>> {
+    let o = self.fbb_.end_table(self.start_);
+    flatbuffers::WIPOffset::new(o.value())
+  }
+}
+
+impl std::fmt::Debug for TableInC<'_> {
+  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+    let mut ds = f.debug_struct("TableInC");
+      ds.field("refer_to_a1", &self.refer_to_a1());
+      ds.field("refer_to_a2", &self.refer_to_a2());
+      ds.finish()
+  }
+}
+#[non_exhaustive]
+#[derive(Debug, Clone, PartialEq)]
+pub struct TableInCT {
+  pub refer_to_a1: Option<Box<super::namespace_a::TableInFirstNST>>,
+  pub refer_to_a2: Option<Box<super::namespace_a::SecondTableInAT>>,
+}
+impl Default for TableInCT {
+  fn default() -> Self {
+    Self {
+      refer_to_a1: None,
+      refer_to_a2: None,
+    }
+  }
+}
+impl TableInCT {
+  pub fn pack<'b>(
+    &self,
+    _fbb: &mut flatbuffers::FlatBufferBuilder<'b>
+  ) -> flatbuffers::WIPOffset<TableInC<'b>> {
+    let refer_to_a1 = self.refer_to_a1.as_ref().map(|x|{
+      x.pack(_fbb)
+    });
+    let refer_to_a2 = self.refer_to_a2.as_ref().map(|x|{
+      x.pack(_fbb)
+    });
+    TableInC::create(_fbb, &TableInCArgs{
+      refer_to_a1,
+      refer_to_a2,
+    })
+  }
+}
diff --git a/tests/namespace_test/namespace_test1.fbs b/tests/namespace_test/namespace_test1.fbs
index 49449bf..f0b9c16 100644
--- a/tests/namespace_test/namespace_test1.fbs
+++ b/tests/namespace_test/namespace_test1.fbs
@@ -5,6 +5,10 @@
     foo:int;
 }
 
+union UnionInNestedNS {
+    TableInNestedNS,
+}
+
 enum EnumInNestedNS:byte
 {
 	A, B, C
diff --git a/tests/namespace_test/namespace_test1.ts b/tests/namespace_test/namespace_test1.ts
new file mode 100644
index 0000000..9d8cf33
--- /dev/null
+++ b/tests/namespace_test/namespace_test1.ts
@@ -0,0 +1,3 @@
+export { StructInNestedNS, StructInNestedNST } from './namespace-a/namespace-b/struct-in-nested-n-s';
+export { TableInNestedNS, TableInNestedNST } from './namespace-a/namespace-b/table-in-nested-n-s';
+export { UnionInNestedNS, unionToUnionInNestedNS, unionListToUnionInNestedNS } from './namespace-a/namespace-b/union-in-nested-n-s';
diff --git a/tests/namespace_test/namespace_test1_generated.h b/tests/namespace_test/namespace_test1_generated.h
index 5ec21f8..bb82236 100644
--- a/tests/namespace_test/namespace_test1_generated.h
+++ b/tests/namespace_test/namespace_test1_generated.h
@@ -24,7 +24,117 @@
 
 inline const flatbuffers::TypeTable *StructInNestedNSTypeTable();
 
-enum EnumInNestedNS {
+enum UnionInNestedNS : uint8_t {
+  UnionInNestedNS_NONE = 0,
+  UnionInNestedNS_TableInNestedNS = 1,
+  UnionInNestedNS_MIN = UnionInNestedNS_NONE,
+  UnionInNestedNS_MAX = UnionInNestedNS_TableInNestedNS
+};
+
+inline const UnionInNestedNS (&EnumValuesUnionInNestedNS())[2] {
+  static const UnionInNestedNS values[] = {
+    UnionInNestedNS_NONE,
+    UnionInNestedNS_TableInNestedNS
+  };
+  return values;
+}
+
+inline const char * const *EnumNamesUnionInNestedNS() {
+  static const char * const names[3] = {
+    "NONE",
+    "TableInNestedNS",
+    nullptr
+  };
+  return names;
+}
+
+inline const char *EnumNameUnionInNestedNS(UnionInNestedNS e) {
+  if (flatbuffers::IsOutRange(e, UnionInNestedNS_NONE, UnionInNestedNS_TableInNestedNS)) return "";
+  const size_t index = static_cast<size_t>(e);
+  return EnumNamesUnionInNestedNS()[index];
+}
+
+template<typename T> struct UnionInNestedNSTraits {
+  static const UnionInNestedNS enum_value = UnionInNestedNS_NONE;
+};
+
+template<> struct UnionInNestedNSTraits<NamespaceA::NamespaceB::TableInNestedNS> {
+  static const UnionInNestedNS enum_value = UnionInNestedNS_TableInNestedNS;
+};
+
+template<typename T> struct UnionInNestedNSUnionTraits {
+  static const UnionInNestedNS enum_value = UnionInNestedNS_NONE;
+};
+
+template<> struct UnionInNestedNSUnionTraits<NamespaceA::NamespaceB::TableInNestedNST> {
+  static const UnionInNestedNS enum_value = UnionInNestedNS_TableInNestedNS;
+};
+
+struct UnionInNestedNSUnion {
+  UnionInNestedNS type;
+  void *value;
+
+  UnionInNestedNSUnion() : type(UnionInNestedNS_NONE), value(nullptr) {}
+  UnionInNestedNSUnion(UnionInNestedNSUnion&& u) FLATBUFFERS_NOEXCEPT :
+    type(UnionInNestedNS_NONE), value(nullptr)
+    { std::swap(type, u.type); std::swap(value, u.value); }
+  UnionInNestedNSUnion(const UnionInNestedNSUnion &);
+  UnionInNestedNSUnion &operator=(const UnionInNestedNSUnion &u)
+    { UnionInNestedNSUnion t(u); std::swap(type, t.type); std::swap(value, t.value); return *this; }
+  UnionInNestedNSUnion &operator=(UnionInNestedNSUnion &&u) FLATBUFFERS_NOEXCEPT
+    { std::swap(type, u.type); std::swap(value, u.value); return *this; }
+  ~UnionInNestedNSUnion() { Reset(); }
+
+  void Reset();
+
+  template <typename T>
+  void Set(T&& val) {
+    typedef typename std::remove_reference<T>::type RT;
+    Reset();
+    type = UnionInNestedNSUnionTraits<RT>::enum_value;
+    if (type != UnionInNestedNS_NONE) {
+      value = new RT(std::forward<T>(val));
+    }
+  }
+
+  static void *UnPack(const void *obj, UnionInNestedNS type, const flatbuffers::resolver_function_t *resolver);
+  flatbuffers::Offset<void> Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher = nullptr) const;
+
+  NamespaceA::NamespaceB::TableInNestedNST *AsTableInNestedNS() {
+    return type == UnionInNestedNS_TableInNestedNS ?
+      reinterpret_cast<NamespaceA::NamespaceB::TableInNestedNST *>(value) : nullptr;
+  }
+  const NamespaceA::NamespaceB::TableInNestedNST *AsTableInNestedNS() const {
+    return type == UnionInNestedNS_TableInNestedNS ?
+      reinterpret_cast<const NamespaceA::NamespaceB::TableInNestedNST *>(value) : nullptr;
+  }
+};
+
+
+inline bool operator==(const UnionInNestedNSUnion &lhs, const UnionInNestedNSUnion &rhs) {
+  if (lhs.type != rhs.type) return false;
+  switch (lhs.type) {
+    case UnionInNestedNS_NONE: {
+      return true;
+    }
+    case UnionInNestedNS_TableInNestedNS: {
+      return *(reinterpret_cast<const NamespaceA::NamespaceB::TableInNestedNST *>(lhs.value)) ==
+             *(reinterpret_cast<const NamespaceA::NamespaceB::TableInNestedNST *>(rhs.value));
+    }
+    default: {
+      return false;
+    }
+  }
+}
+
+inline bool operator!=(const UnionInNestedNSUnion &lhs, const UnionInNestedNSUnion &rhs) {
+    return !(lhs == rhs);
+}
+
+bool VerifyUnionInNestedNS(flatbuffers::Verifier &verifier, const void *obj, UnionInNestedNS type);
+bool VerifyUnionInNestedNSVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types);
+
+enum EnumInNestedNS : int8_t {
   EnumInNestedNS_A = 0,
   EnumInNestedNS_B = 1,
   EnumInNestedNS_C = 2,
@@ -66,7 +176,7 @@
   static const flatbuffers::TypeTable *MiniReflectTypeTable() {
     return StructInNestedNSTypeTable();
   }
-  static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() {
+  static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
     return "NamespaceA.NamespaceB.StructInNestedNS";
   }
   StructInNestedNS()
@@ -105,32 +215,19 @@
 
 struct TableInNestedNST : public flatbuffers::NativeTable {
   typedef TableInNestedNS TableType;
-  static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() {
+  static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
     return "NamespaceA.NamespaceB.TableInNestedNST";
   }
-  int32_t foo;
-  TableInNestedNST()
-      : foo(0) {
-  }
+  int32_t foo = 0;
 };
 
-inline bool operator==(const TableInNestedNST &lhs, const TableInNestedNST &rhs) {
-  return
-      (lhs.foo == rhs.foo);
-}
-
-inline bool operator!=(const TableInNestedNST &lhs, const TableInNestedNST &rhs) {
-    return !(lhs == rhs);
-}
-
-
 struct TableInNestedNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
   typedef TableInNestedNST NativeTableType;
   typedef TableInNestedNSBuilder Builder;
   static const flatbuffers::TypeTable *MiniReflectTypeTable() {
     return TableInNestedNSTypeTable();
   }
-  static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() {
+  static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
     return "NamespaceA.NamespaceB.TableInNestedNS";
   }
   enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
@@ -139,12 +236,12 @@
   int32_t foo() const {
     return GetField<int32_t>(VT_FOO, 0);
   }
-  bool mutate_foo(int32_t _foo) {
+  bool mutate_foo(int32_t _foo = 0) {
     return SetField<int32_t>(VT_FOO, _foo, 0);
   }
   bool Verify(flatbuffers::Verifier &verifier) const {
     return VerifyTableStart(verifier) &&
-           VerifyField<int32_t>(verifier, VT_FOO) &&
+           VerifyField<int32_t>(verifier, VT_FOO, 4) &&
            verifier.EndTable();
   }
   TableInNestedNST *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
@@ -180,8 +277,19 @@
 
 flatbuffers::Offset<TableInNestedNS> CreateTableInNestedNS(flatbuffers::FlatBufferBuilder &_fbb, const TableInNestedNST *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
 
+
+inline bool operator==(const TableInNestedNST &lhs, const TableInNestedNST &rhs) {
+  return
+      (lhs.foo == rhs.foo);
+}
+
+inline bool operator!=(const TableInNestedNST &lhs, const TableInNestedNST &rhs) {
+    return !(lhs == rhs);
+}
+
+
 inline TableInNestedNST *TableInNestedNS::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
-  flatbuffers::unique_ptr<NamespaceA::NamespaceB::TableInNestedNST> _o = flatbuffers::unique_ptr<NamespaceA::NamespaceB::TableInNestedNST>(new TableInNestedNST());
+  auto _o = std::unique_ptr<TableInNestedNST>(new TableInNestedNST());
   UnPackTo(_o.get(), _resolver);
   return _o.release();
 }
@@ -206,6 +314,95 @@
       _foo);
 }
 
+inline bool VerifyUnionInNestedNS(flatbuffers::Verifier &verifier, const void *obj, UnionInNestedNS type) {
+  switch (type) {
+    case UnionInNestedNS_NONE: {
+      return true;
+    }
+    case UnionInNestedNS_TableInNestedNS: {
+      auto ptr = reinterpret_cast<const NamespaceA::NamespaceB::TableInNestedNS *>(obj);
+      return verifier.VerifyTable(ptr);
+    }
+    default: return true;
+  }
+}
+
+inline bool VerifyUnionInNestedNSVector(flatbuffers::Verifier &verifier, const flatbuffers::Vector<flatbuffers::Offset<void>> *values, const flatbuffers::Vector<uint8_t> *types) {
+  if (!values || !types) return !values && !types;
+  if (values->size() != types->size()) return false;
+  for (flatbuffers::uoffset_t i = 0; i < values->size(); ++i) {
+    if (!VerifyUnionInNestedNS(
+        verifier,  values->Get(i), types->GetEnum<UnionInNestedNS>(i))) {
+      return false;
+    }
+  }
+  return true;
+}
+
+inline void *UnionInNestedNSUnion::UnPack(const void *obj, UnionInNestedNS type, const flatbuffers::resolver_function_t *resolver) {
+  (void)resolver;
+  switch (type) {
+    case UnionInNestedNS_TableInNestedNS: {
+      auto ptr = reinterpret_cast<const NamespaceA::NamespaceB::TableInNestedNS *>(obj);
+      return ptr->UnPack(resolver);
+    }
+    default: return nullptr;
+  }
+}
+
+inline flatbuffers::Offset<void> UnionInNestedNSUnion::Pack(flatbuffers::FlatBufferBuilder &_fbb, const flatbuffers::rehasher_function_t *_rehasher) const {
+  (void)_rehasher;
+  switch (type) {
+    case UnionInNestedNS_TableInNestedNS: {
+      auto ptr = reinterpret_cast<const NamespaceA::NamespaceB::TableInNestedNST *>(value);
+      return CreateTableInNestedNS(_fbb, ptr, _rehasher).Union();
+    }
+    default: return 0;
+  }
+}
+
+inline UnionInNestedNSUnion::UnionInNestedNSUnion(const UnionInNestedNSUnion &u) : type(u.type), value(nullptr) {
+  switch (type) {
+    case UnionInNestedNS_TableInNestedNS: {
+      value = new NamespaceA::NamespaceB::TableInNestedNST(*reinterpret_cast<NamespaceA::NamespaceB::TableInNestedNST *>(u.value));
+      break;
+    }
+    default:
+      break;
+  }
+}
+
+inline void UnionInNestedNSUnion::Reset() {
+  switch (type) {
+    case UnionInNestedNS_TableInNestedNS: {
+      auto ptr = reinterpret_cast<NamespaceA::NamespaceB::TableInNestedNST *>(value);
+      delete ptr;
+      break;
+    }
+    default: break;
+  }
+  value = nullptr;
+  type = UnionInNestedNS_NONE;
+}
+
+inline const flatbuffers::TypeTable *UnionInNestedNSTypeTable() {
+  static const flatbuffers::TypeCode type_codes[] = {
+    { flatbuffers::ET_SEQUENCE, 0, -1 },
+    { flatbuffers::ET_SEQUENCE, 0, 0 }
+  };
+  static const flatbuffers::TypeFunction type_refs[] = {
+    NamespaceA::NamespaceB::TableInNestedNSTypeTable
+  };
+  static const char * const names[] = {
+    "NONE",
+    "TableInNestedNS"
+  };
+  static const flatbuffers::TypeTable tt = {
+    flatbuffers::ST_UNION, 2, type_codes, type_refs, nullptr, nullptr, names
+  };
+  return &tt;
+}
+
 inline const flatbuffers::TypeTable *EnumInNestedNSTypeTable() {
   static const flatbuffers::TypeCode type_codes[] = {
     { flatbuffers::ET_CHAR, 0, 0 },
diff --git a/tests/namespace_test/namespace_test1_generated.js b/tests/namespace_test/namespace_test1_generated.js
deleted file mode 100644
index 7331f64..0000000
--- a/tests/namespace_test/namespace_test1_generated.js
+++ /dev/null
@@ -1,229 +0,0 @@
-// automatically generated by the FlatBuffers compiler, do not modify
-
-/**
- * @const
- * @namespace
- */
-var NamespaceA = NamespaceA || {};
-
-/**
- * @const
- * @namespace
- */
-NamespaceA.NamespaceB = NamespaceA.NamespaceB || {};
-
-/**
- * @enum {number}
- */
-NamespaceA.NamespaceB.EnumInNestedNS = {
-  A: 0,
-  B: 1,
-  C: 2
-};
-
-/**
- * @enum {string}
- */
-NamespaceA.NamespaceB.EnumInNestedNSName = {
-  '0': 'A',
-  '1': 'B',
-  '2': 'C'
-};
-
-/**
- * @constructor
- */
-NamespaceA.NamespaceB.TableInNestedNS = function() {
-  /**
-   * @type {flatbuffers.ByteBuffer}
-   */
-  this.bb = null;
-
-  /**
-   * @type {number}
-   */
-  this.bb_pos = 0;
-};
-
-/**
- * @param {number} i
- * @param {flatbuffers.ByteBuffer} bb
- * @returns {NamespaceA.NamespaceB.TableInNestedNS}
- */
-NamespaceA.NamespaceB.TableInNestedNS.prototype.__init = function(i, bb) {
-  this.bb_pos = i;
-  this.bb = bb;
-  return this;
-};
-
-/**
- * @param {flatbuffers.ByteBuffer} bb
- * @param {NamespaceA.NamespaceB.TableInNestedNS=} obj
- * @returns {NamespaceA.NamespaceB.TableInNestedNS}
- */
-NamespaceA.NamespaceB.TableInNestedNS.getRootAsTableInNestedNS = function(bb, obj) {
-  return (obj || new NamespaceA.NamespaceB.TableInNestedNS).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param {flatbuffers.ByteBuffer} bb
- * @param {NamespaceA.NamespaceB.TableInNestedNS=} obj
- * @returns {NamespaceA.NamespaceB.TableInNestedNS}
- */
-NamespaceA.NamespaceB.TableInNestedNS.getSizePrefixedRootAsTableInNestedNS = function(bb, obj) {
-  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
-  return (obj || new NamespaceA.NamespaceB.TableInNestedNS).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @returns {number}
- */
-NamespaceA.NamespaceB.TableInNestedNS.prototype.foo = function() {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
-};
-
-/**
- * @param {number} value
- * @returns {boolean}
- */
-NamespaceA.NamespaceB.TableInNestedNS.prototype.mutate_foo = function(value) {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-
-  if (offset === 0) {
-    return false;
-  }
-
-  this.bb.writeInt32(this.bb_pos + offset, value);
-  return true;
-};
-
-/**
- * @returns {string}
- */
-NamespaceA.NamespaceB.TableInNestedNS.getFullyQualifiedName = function() {
-  return 'NamespaceA.NamespaceB.TableInNestedNS';
-}
-
-/**
- * @param {flatbuffers.Builder} builder
- */
-NamespaceA.NamespaceB.TableInNestedNS.startTableInNestedNS = function(builder) {
-  builder.startObject(1);
-};
-
-/**
- * @param {flatbuffers.Builder} builder
- * @param {number} foo
- */
-NamespaceA.NamespaceB.TableInNestedNS.addFoo = function(builder, foo) {
-  builder.addFieldInt32(0, foo, 0);
-};
-
-/**
- * @param {flatbuffers.Builder} builder
- * @returns {flatbuffers.Offset}
- */
-NamespaceA.NamespaceB.TableInNestedNS.endTableInNestedNS = function(builder) {
-  var offset = builder.endObject();
-  return offset;
-};
-
-/**
- * @param {flatbuffers.Builder} builder
- * @param {number} foo
- * @returns {flatbuffers.Offset}
- */
-NamespaceA.NamespaceB.TableInNestedNS.createTableInNestedNS = function(builder, foo) {
-  NamespaceA.NamespaceB.TableInNestedNS.startTableInNestedNS(builder);
-  NamespaceA.NamespaceB.TableInNestedNS.addFoo(builder, foo);
-  return NamespaceA.NamespaceB.TableInNestedNS.endTableInNestedNS(builder);
-}
-
-/**
- * @constructor
- */
-NamespaceA.NamespaceB.StructInNestedNS = function() {
-  /**
-   * @type {flatbuffers.ByteBuffer}
-   */
-  this.bb = null;
-
-  /**
-   * @type {number}
-   */
-  this.bb_pos = 0;
-};
-
-/**
- * @param {number} i
- * @param {flatbuffers.ByteBuffer} bb
- * @returns {NamespaceA.NamespaceB.StructInNestedNS}
- */
-NamespaceA.NamespaceB.StructInNestedNS.prototype.__init = function(i, bb) {
-  this.bb_pos = i;
-  this.bb = bb;
-  return this;
-};
-
-/**
- * @returns {number}
- */
-NamespaceA.NamespaceB.StructInNestedNS.prototype.a = function() {
-  return this.bb.readInt32(this.bb_pos);
-};
-
-/**
- * @param {number} value
- * @returns {boolean}
- */
-NamespaceA.NamespaceB.StructInNestedNS.prototype.mutate_a = function(value) {
-  this.bb.writeInt32(this.bb_pos + 0, value);
-  return true;
-};
-
-/**
- * @returns {number}
- */
-NamespaceA.NamespaceB.StructInNestedNS.prototype.b = function() {
-  return this.bb.readInt32(this.bb_pos + 4);
-};
-
-/**
- * @param {number} value
- * @returns {boolean}
- */
-NamespaceA.NamespaceB.StructInNestedNS.prototype.mutate_b = function(value) {
-  this.bb.writeInt32(this.bb_pos + 4, value);
-  return true;
-};
-
-/**
- * @returns {string}
- */
-NamespaceA.NamespaceB.StructInNestedNS.getFullyQualifiedName = function() {
-  return 'NamespaceA.NamespaceB.StructInNestedNS';
-}
-
-/**
- * @returns {number}
- */
-NamespaceA.NamespaceB.StructInNestedNS.sizeOf = function() {
-  return 8;
-}
-
-/**
- * @param {flatbuffers.Builder} builder
- * @param {number} a
- * @param {number} b
- * @returns {flatbuffers.Offset}
- */
-NamespaceA.NamespaceB.StructInNestedNS.createStructInNestedNS = function(builder, a, b) {
-  builder.prep(4, 8);
-  builder.writeInt32(b);
-  builder.writeInt32(a);
-  return builder.offset();
-};
-
-// Exports for Node.js and RequireJS
-this.NamespaceA = NamespaceA;
diff --git a/tests/namespace_test/namespace_test1_generated.lobster b/tests/namespace_test/namespace_test1_generated.lobster
index 6503005..5721b8f 100644
--- a/tests/namespace_test/namespace_test1_generated.lobster
+++ b/tests/namespace_test/namespace_test1_generated.lobster
@@ -3,6 +3,10 @@
 
 namespace NamespaceA_NamespaceB
 
+enum UnionInNestedNS:
+    UnionInNestedNS_NONE = 0
+    UnionInNestedNS_TableInNestedNS = 1
+
 enum EnumInNestedNS:
     EnumInNestedNS_A = 0
     EnumInNestedNS_B = 1
diff --git a/tests/namespace_test/namespace_test1_generated.rs b/tests/namespace_test/namespace_test1_generated.rs
deleted file mode 100644
index dd735a6..0000000
--- a/tests/namespace_test/namespace_test1_generated.rs
+++ /dev/null
@@ -1,264 +0,0 @@
-// automatically generated by the FlatBuffers compiler, do not modify
-
-
-#![allow(unused_imports, dead_code)]
-
-use std::mem;
-use std::cmp::Ordering;
-
-extern crate flatbuffers;
-use self::flatbuffers::EndianScalar;
-
-#[allow(unused_imports, dead_code)]
-pub mod namespace_a {
-
-  use std::mem;
-  use std::cmp::Ordering;
-
-  extern crate flatbuffers;
-  use self::flatbuffers::EndianScalar;
-#[allow(unused_imports, dead_code)]
-pub mod namespace_b {
-
-  use std::mem;
-  use std::cmp::Ordering;
-
-  extern crate flatbuffers;
-  use self::flatbuffers::EndianScalar;
-
-#[deprecated(since = "1.13", note = "Use associated constants instead. This will no longer be generated in 2021.")]
-pub const ENUM_MIN_ENUM_IN_NESTED_NS: i8 = 0;
-#[deprecated(since = "1.13", note = "Use associated constants instead. This will no longer be generated in 2021.")]
-pub const ENUM_MAX_ENUM_IN_NESTED_NS: i8 = 2;
-#[deprecated(since = "1.13", note = "Use associated constants instead. This will no longer be generated in 2021.")]
-#[allow(non_camel_case_types)]
-pub const ENUM_VALUES_ENUM_IN_NESTED_NS: [EnumInNestedNS; 3] = [
-  EnumInNestedNS::A,
-  EnumInNestedNS::B,
-  EnumInNestedNS::C,
-];
-
-#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
-#[repr(transparent)]
-pub struct EnumInNestedNS(pub i8);
-#[allow(non_upper_case_globals)]
-impl EnumInNestedNS {
-  pub const A: Self = Self(0);
-  pub const B: Self = Self(1);
-  pub const C: Self = Self(2);
-
-  pub const ENUM_MIN: i8 = 0;
-  pub const ENUM_MAX: i8 = 2;
-  pub const ENUM_VALUES: &'static [Self] = &[
-    Self::A,
-    Self::B,
-    Self::C,
-  ];
-  /// Returns the variant's name or "" if unknown.
-  pub fn variant_name(self) -> Option<&'static str> {
-    match self {
-      Self::A => Some("A"),
-      Self::B => Some("B"),
-      Self::C => Some("C"),
-      _ => None,
-    }
-  }
-}
-impl std::fmt::Debug for EnumInNestedNS {
-  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
-    if let Some(name) = self.variant_name() {
-      f.write_str(name)
-    } else {
-      f.write_fmt(format_args!("<UNKNOWN {:?}>", self.0))
-    }
-  }
-}
-impl<'a> flatbuffers::Follow<'a> for EnumInNestedNS {
-  type Inner = Self;
-  #[inline]
-  fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
-    Self(flatbuffers::read_scalar_at::<i8>(buf, loc))
-  }
-}
-
-impl flatbuffers::Push for EnumInNestedNS {
-    type Output = EnumInNestedNS;
-    #[inline]
-    fn push(&self, dst: &mut [u8], _rest: &[u8]) {
-        flatbuffers::emplace_scalar::<i8>(dst, self.0);
-    }
-}
-
-impl flatbuffers::EndianScalar for EnumInNestedNS {
-  #[inline]
-  fn to_little_endian(self) -> Self {
-    Self(i8::to_le(self.0))
-  }
-  #[inline]
-  fn from_little_endian(self) -> Self {
-    Self(i8::from_le(self.0))
-  }
-}
-
-// struct StructInNestedNS, aligned to 4
-#[repr(C, align(4))]
-#[derive(Clone, Copy, PartialEq)]
-pub struct StructInNestedNS {
-  a_: i32,
-  b_: i32,
-} // pub struct StructInNestedNS
-impl std::fmt::Debug for StructInNestedNS {
-  fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
-    f.debug_struct("StructInNestedNS")
-      .field("a", &self.a())
-      .field("b", &self.b())
-      .finish()
-  }
-}
-
-impl flatbuffers::SafeSliceAccess for StructInNestedNS {}
-impl<'a> flatbuffers::Follow<'a> for StructInNestedNS {
-  type Inner = &'a StructInNestedNS;
-  #[inline]
-  fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
-    <&'a StructInNestedNS>::follow(buf, loc)
-  }
-}
-impl<'a> flatbuffers::Follow<'a> for &'a StructInNestedNS {
-  type Inner = &'a StructInNestedNS;
-  #[inline]
-  fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
-    flatbuffers::follow_cast_ref::<StructInNestedNS>(buf, loc)
-  }
-}
-impl<'b> flatbuffers::Push for StructInNestedNS {
-    type Output = StructInNestedNS;
-    #[inline]
-    fn push(&self, dst: &mut [u8], _rest: &[u8]) {
-        let src = unsafe {
-            ::std::slice::from_raw_parts(self as *const StructInNestedNS as *const u8, Self::size())
-        };
-        dst.copy_from_slice(src);
-    }
-}
-impl<'b> flatbuffers::Push for &'b StructInNestedNS {
-    type Output = StructInNestedNS;
-
-    #[inline]
-    fn push(&self, dst: &mut [u8], _rest: &[u8]) {
-        let src = unsafe {
-            ::std::slice::from_raw_parts(*self as *const StructInNestedNS as *const u8, Self::size())
-        };
-        dst.copy_from_slice(src);
-    }
-}
-
-
-impl StructInNestedNS {
-  pub fn new(_a: i32, _b: i32) -> Self {
-    StructInNestedNS {
-      a_: _a.to_little_endian(),
-      b_: _b.to_little_endian(),
-
-    }
-  }
-    pub const fn get_fully_qualified_name() -> &'static str {
-        "NamespaceA.NamespaceB.StructInNestedNS"
-    }
-
-  pub fn a(&self) -> i32 {
-    self.a_.from_little_endian()
-  }
-  pub fn b(&self) -> i32 {
-    self.b_.from_little_endian()
-  }
-}
-
-pub enum TableInNestedNSOffset {}
-#[derive(Copy, Clone, PartialEq)]
-
-pub struct TableInNestedNS<'a> {
-  pub _tab: flatbuffers::Table<'a>,
-}
-
-impl<'a> flatbuffers::Follow<'a> for TableInNestedNS<'a> {
-    type Inner = TableInNestedNS<'a>;
-    #[inline]
-    fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
-        Self { _tab: flatbuffers::Table { buf, loc } }
-    }
-}
-
-impl<'a> TableInNestedNS<'a> {
-    pub const fn get_fully_qualified_name() -> &'static str {
-        "NamespaceA.NamespaceB.TableInNestedNS"
-    }
-
-    #[inline]
-    pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
-        TableInNestedNS {
-            _tab: table,
-        }
-    }
-    #[allow(unused_mut)]
-    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
-        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
-        args: &'args TableInNestedNSArgs) -> flatbuffers::WIPOffset<TableInNestedNS<'bldr>> {
-      let mut builder = TableInNestedNSBuilder::new(_fbb);
-      builder.add_foo(args.foo);
-      builder.finish()
-    }
-
-    pub const VT_FOO: flatbuffers::VOffsetT = 4;
-
-  #[inline]
-  pub fn foo(&self) -> i32 {
-    self._tab.get::<i32>(TableInNestedNS::VT_FOO, Some(0)).unwrap()
-  }
-}
-
-pub struct TableInNestedNSArgs {
-    pub foo: i32,
-}
-impl<'a> Default for TableInNestedNSArgs {
-    #[inline]
-    fn default() -> Self {
-        TableInNestedNSArgs {
-            foo: 0,
-        }
-    }
-}
-pub struct TableInNestedNSBuilder<'a: 'b, 'b> {
-  fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
-  start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
-}
-impl<'a: 'b, 'b> TableInNestedNSBuilder<'a, 'b> {
-  #[inline]
-  pub fn add_foo(&mut self, foo: i32) {
-    self.fbb_.push_slot::<i32>(TableInNestedNS::VT_FOO, foo, 0);
-  }
-  #[inline]
-  pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> TableInNestedNSBuilder<'a, 'b> {
-    let start = _fbb.start_table();
-    TableInNestedNSBuilder {
-      fbb_: _fbb,
-      start_: start,
-    }
-  }
-  #[inline]
-  pub fn finish(self) -> flatbuffers::WIPOffset<TableInNestedNS<'a>> {
-    let o = self.fbb_.end_table(self.start_);
-    flatbuffers::WIPOffset::new(o.value())
-  }
-}
-
-impl std::fmt::Debug for TableInNestedNS<'_> {
-  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-    let mut ds = f.debug_struct("TableInNestedNS");
-      ds.field("foo", &self.foo());
-      ds.finish()
-  }
-}
-}  // pub mod NamespaceB
-}  // pub mod NamespaceA
-
diff --git a/tests/namespace_test/namespace_test1_generated.ts b/tests/namespace_test/namespace_test1_generated.ts
deleted file mode 100644
index 933a43d..0000000
--- a/tests/namespace_test/namespace_test1_generated.ts
+++ /dev/null
@@ -1,269 +0,0 @@
-// automatically generated by the FlatBuffers compiler, do not modify
-
-/**
- * @enum {number}
- */
-export namespace NamespaceA.NamespaceB{
-export enum EnumInNestedNS{
-  A= 0,
-  B= 1,
-  C= 2
-};
-}
-
-/**
- * @constructor
- */
-export namespace NamespaceA.NamespaceB{
-export class TableInNestedNS {
-  bb: flatbuffers.ByteBuffer|null = null;
-
-  bb_pos:number = 0;
-/**
- * @param number i
- * @param flatbuffers.ByteBuffer bb
- * @returns TableInNestedNS
- */
-__init(i:number, bb:flatbuffers.ByteBuffer):TableInNestedNS {
-  this.bb_pos = i;
-  this.bb = bb;
-  return this;
-};
-
-/**
- * @param flatbuffers.ByteBuffer bb
- * @param TableInNestedNS= obj
- * @returns TableInNestedNS
- */
-static getRootAsTableInNestedNS(bb:flatbuffers.ByteBuffer, obj?:TableInNestedNS):TableInNestedNS {
-  return (obj || new TableInNestedNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param flatbuffers.ByteBuffer bb
- * @param TableInNestedNS= obj
- * @returns TableInNestedNS
- */
-static getSizePrefixedRootAsTableInNestedNS(bb:flatbuffers.ByteBuffer, obj?:TableInNestedNS):TableInNestedNS {
-  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
-  return (obj || new TableInNestedNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @returns number
- */
-foo():number {
-  var offset = this.bb!.__offset(this.bb_pos, 4);
-  return offset ? this.bb!.readInt32(this.bb_pos + offset) : 0;
-};
-
-/**
- * @param number value
- * @returns boolean
- */
-mutate_foo(value:number):boolean {
-  var offset = this.bb!.__offset(this.bb_pos, 4);
-
-  if (offset === 0) {
-    return false;
-  }
-
-  this.bb!.writeInt32(this.bb_pos + offset, value);
-  return true;
-};
-
-/**
- * @returns string
- */
-static getFullyQualifiedName():string {
-  return 'NamespaceA.NamespaceB.TableInNestedNS';
-}
-
-/**
- * @param flatbuffers.Builder builder
- */
-static startTableInNestedNS(builder:flatbuffers.Builder) {
-  builder.startObject(1);
-};
-
-/**
- * @param flatbuffers.Builder builder
- * @param number foo
- */
-static addFoo(builder:flatbuffers.Builder, foo:number) {
-  builder.addFieldInt32(0, foo, 0);
-};
-
-/**
- * @param flatbuffers.Builder builder
- * @returns flatbuffers.Offset
- */
-static endTableInNestedNS(builder:flatbuffers.Builder):flatbuffers.Offset {
-  var offset = builder.endObject();
-  return offset;
-};
-
-static createTableInNestedNS(builder:flatbuffers.Builder, foo:number):flatbuffers.Offset {
-  TableInNestedNS.startTableInNestedNS(builder);
-  TableInNestedNS.addFoo(builder, foo);
-  return TableInNestedNS.endTableInNestedNS(builder);
-}
-
-/**
- * @returns TableInNestedNST
- */
-unpack(): TableInNestedNST {
-  return new TableInNestedNST(
-    this.foo()
-  );
-};
-
-/**
- * @param TableInNestedNST _o
- */
-unpackTo(_o: TableInNestedNST): void {
-  _o.foo = this.foo();
-};
-}
-
-export class TableInNestedNST {
-/**
- * @constructor
- * @param number foo
- */
-constructor(
-  public foo: number = 0
-){};
-
-/**
- * @param flatbuffers.Builder builder
- * @returns flatbuffers.Offset
- */
-pack(builder:flatbuffers.Builder): flatbuffers.Offset {
-  return NamespaceA.NamespaceB.TableInNestedNS.createTableInNestedNS(builder,
-    this.foo
-  );
-};
-}
-}
-/**
- * @constructor
- */
-export namespace NamespaceA.NamespaceB{
-export class StructInNestedNS {
-  bb: flatbuffers.ByteBuffer|null = null;
-
-  bb_pos:number = 0;
-/**
- * @param number i
- * @param flatbuffers.ByteBuffer bb
- * @returns StructInNestedNS
- */
-__init(i:number, bb:flatbuffers.ByteBuffer):StructInNestedNS {
-  this.bb_pos = i;
-  this.bb = bb;
-  return this;
-};
-
-/**
- * @returns number
- */
-a():number {
-  return this.bb!.readInt32(this.bb_pos);
-};
-
-/**
- * @param number value
- * @returns boolean
- */
-mutate_a(value:number):boolean {
-  this.bb!.writeInt32(this.bb_pos + 0, value);
-  return true;
-};
-
-/**
- * @returns number
- */
-b():number {
-  return this.bb!.readInt32(this.bb_pos + 4);
-};
-
-/**
- * @param number value
- * @returns boolean
- */
-mutate_b(value:number):boolean {
-  this.bb!.writeInt32(this.bb_pos + 4, value);
-  return true;
-};
-
-/**
- * @returns string
- */
-static getFullyQualifiedName():string {
-  return 'NamespaceA.NamespaceB.StructInNestedNS';
-}
-
-/**
- * @returns number
- */
-static sizeOf():number {
-  return 8;
-}
-
-/**
- * @param flatbuffers.Builder builder
- * @param number a
- * @param number b
- * @returns flatbuffers.Offset
- */
-static createStructInNestedNS(builder:flatbuffers.Builder, a: number, b: number):flatbuffers.Offset {
-  builder.prep(4, 8);
-  builder.writeInt32(b);
-  builder.writeInt32(a);
-  return builder.offset();
-};
-
-
-/**
- * @returns StructInNestedNST
- */
-unpack(): StructInNestedNST {
-  return new StructInNestedNST(
-    this.a(),
-    this.b()
-  );
-};
-
-/**
- * @param StructInNestedNST _o
- */
-unpackTo(_o: StructInNestedNST): void {
-  _o.a = this.a();
-  _o.b = this.b();
-};
-}
-
-export class StructInNestedNST {
-/**
- * @constructor
- * @param number a
- * @param number b
- */
-constructor(
-  public a: number = 0,
-  public b: number = 0
-){};
-
-/**
- * @param flatbuffers.Builder builder
- * @returns flatbuffers.Offset
- */
-pack(builder:flatbuffers.Builder): flatbuffers.Offset {
-  return NamespaceA.NamespaceB.StructInNestedNS.createStructInNestedNS(builder,
-    this.a,
-    this.b
-  );
-};
-}
-}
diff --git a/tests/namespace_test/namespace_test1_namespace_a.namespace_b_generated.dart b/tests/namespace_test/namespace_test1_namespace_a.namespace_b_generated.dart
index cc936c3..5e0fb1d 100644
--- a/tests/namespace_test/namespace_test1_namespace_a.namespace_b_generated.dart
+++ b/tests/namespace_test/namespace_test1_namespace_a.namespace_b_generated.dart
@@ -1,5 +1,5 @@
 // automatically generated by the FlatBuffers compiler, do not modify
-// ignore_for_file: unused_import, unused_field, unused_local_variable
+// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
 
 library namespace_a.namespace_b;
 
@@ -7,28 +7,78 @@
 import 'package:flat_buffers/flat_buffers.dart' as fb;
 
 
+class UnionInNestedNSTypeId {
+  final int value;
+  const UnionInNestedNSTypeId._(this.value);
+
+  factory UnionInNestedNSTypeId.fromValue(int value) {
+    final result = values[value];
+    if (result == null) {
+      throw StateError('Invalid value $value for bit flag enum UnionInNestedNSTypeId');
+    }
+    return result;
+  }
+
+  static UnionInNestedNSTypeId? _createOrNull(int? value) => 
+      value == null ? null : UnionInNestedNSTypeId.fromValue(value);
+
+  static const int minValue = 0;
+  static const int maxValue = 1;
+  static bool containsValue(int value) => values.containsKey(value);
+
+  static const UnionInNestedNSTypeId NONE = UnionInNestedNSTypeId._(0);
+  static const UnionInNestedNSTypeId TableInNestedNS = UnionInNestedNSTypeId._(1);
+  static const Map<int, UnionInNestedNSTypeId> values = {
+    0: NONE,
+    1: TableInNestedNS};
+
+  static const fb.Reader<UnionInNestedNSTypeId> reader = _UnionInNestedNSTypeIdReader();
+
+  @override
+  String toString() {
+    return 'UnionInNestedNSTypeId{value: $value}';
+  }
+}
+
+class _UnionInNestedNSTypeIdReader extends fb.Reader<UnionInNestedNSTypeId> {
+  const _UnionInNestedNSTypeIdReader();
+
+  @override
+  int get size => 1;
+
+  @override
+  UnionInNestedNSTypeId read(fb.BufferContext bc, int offset) =>
+      UnionInNestedNSTypeId.fromValue(const fb.Uint8Reader().read(bc, offset));
+}
+
 class EnumInNestedNS {
   final int value;
   const EnumInNestedNS._(this.value);
 
   factory EnumInNestedNS.fromValue(int value) {
-    if (value == null) value = 0;
-    if (!values.containsKey(value)) {
-      throw new StateError('Invalid value $value for bit flag enum EnumInNestedNS');
+    final result = values[value];
+    if (result == null) {
+      throw StateError('Invalid value $value for bit flag enum EnumInNestedNS');
     }
-    return values[value];
+    return result;
   }
 
+  static EnumInNestedNS? _createOrNull(int? value) => 
+      value == null ? null : EnumInNestedNS.fromValue(value);
+
   static const int minValue = 0;
   static const int maxValue = 2;
   static bool containsValue(int value) => values.containsKey(value);
 
-  static const EnumInNestedNS A = const EnumInNestedNS._(0);
-  static const EnumInNestedNS B = const EnumInNestedNS._(1);
-  static const EnumInNestedNS C = const EnumInNestedNS._(2);
-  static const values = {0: A,1: B,2: C,};
+  static const EnumInNestedNS A = EnumInNestedNS._(0);
+  static const EnumInNestedNS B = EnumInNestedNS._(1);
+  static const EnumInNestedNS C = EnumInNestedNS._(2);
+  static const Map<int, EnumInNestedNS> values = {
+    0: A,
+    1: B,
+    2: C};
 
-  static const fb.Reader<EnumInNestedNS> reader = const _EnumInNestedNSReader();
+  static const fb.Reader<EnumInNestedNS> reader = _EnumInNestedNSReader();
 
   @override
   String toString() {
@@ -44,17 +94,17 @@
 
   @override
   EnumInNestedNS read(fb.BufferContext bc, int offset) =>
-      new EnumInNestedNS.fromValue(const fb.Int8Reader().read(bc, offset));
+      EnumInNestedNS.fromValue(const fb.Int8Reader().read(bc, offset));
 }
 
 class TableInNestedNS {
   TableInNestedNS._(this._bc, this._bcOffset);
   factory TableInNestedNS(List<int> bytes) {
-    fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes);
+    final rootRef = fb.BufferContext.fromBytes(bytes);
     return reader.read(rootRef, 0);
   }
 
-  static const fb.Reader<TableInNestedNS> reader = const _TableInNestedNSReader();
+  static const fb.Reader<TableInNestedNS> reader = _TableInNestedNSReader();
 
   final fb.BufferContext _bc;
   final int _bcOffset;
@@ -65,6 +115,33 @@
   String toString() {
     return 'TableInNestedNS{foo: $foo}';
   }
+
+  TableInNestedNST unpack() => TableInNestedNST(
+      foo: foo);
+
+  static int pack(fb.Builder fbBuilder, TableInNestedNST? object) {
+    if (object == null) return 0;
+    return object.pack(fbBuilder);
+  }
+}
+
+class TableInNestedNST implements fb.Packable {
+  int foo;
+
+  TableInNestedNST({
+      this.foo = 0});
+
+  @override
+  int pack(fb.Builder fbBuilder) {
+    fbBuilder.startTable(1);
+    fbBuilder.addInt32(0, foo);
+    return fbBuilder.endTable();
+  }
+
+  @override
+  String toString() {
+    return 'TableInNestedNST{foo: $foo}';
+  }
 }
 
 class _TableInNestedNSReader extends fb.TableReader<TableInNestedNS> {
@@ -72,21 +149,19 @@
 
   @override
   TableInNestedNS createObject(fb.BufferContext bc, int offset) => 
-    new TableInNestedNS._(bc, offset);
+    TableInNestedNS._(bc, offset);
 }
 
 class TableInNestedNSBuilder {
-  TableInNestedNSBuilder(this.fbBuilder) {
-    assert(fbBuilder != null);
-  }
+  TableInNestedNSBuilder(this.fbBuilder);
 
   final fb.Builder fbBuilder;
 
   void begin() {
-    fbBuilder.startTable();
+    fbBuilder.startTable(1);
   }
 
-  int addFoo(int foo) {
+  int addFoo(int? foo) {
     fbBuilder.addInt32(0, foo);
     return fbBuilder.offset;
   }
@@ -97,36 +172,33 @@
 }
 
 class TableInNestedNSObjectBuilder extends fb.ObjectBuilder {
-  final int _foo;
+  final int? _foo;
 
   TableInNestedNSObjectBuilder({
-    int foo,
+    int? foo,
   })
       : _foo = foo;
 
   /// Finish building, and store into the [fbBuilder].
   @override
-  int finish(
-    fb.Builder fbBuilder) {
-    assert(fbBuilder != null);
-
-    fbBuilder.startTable();
+  int finish(fb.Builder fbBuilder) {
+    fbBuilder.startTable(1);
     fbBuilder.addInt32(0, _foo);
     return fbBuilder.endTable();
   }
 
   /// Convenience method to serialize to byte list.
   @override
-  Uint8List toBytes([String fileIdentifier]) {
-    fb.Builder fbBuilder = new fb.Builder();
-    int offset = finish(fbBuilder);
-    return fbBuilder.finish(offset, fileIdentifier);
+  Uint8List toBytes([String? fileIdentifier]) {
+    final fbBuilder = fb.Builder(deduplicateTables: false);
+    fbBuilder.finish(finish(fbBuilder), fileIdentifier);
+    return fbBuilder.buffer;
   }
 }
 class StructInNestedNS {
   StructInNestedNS._(this._bc, this._bcOffset);
 
-  static const fb.Reader<StructInNestedNS> reader = const _StructInNestedNSReader();
+  static const fb.Reader<StructInNestedNS> reader = _StructInNestedNSReader();
 
   final fb.BufferContext _bc;
   final int _bcOffset;
@@ -138,6 +210,36 @@
   String toString() {
     return 'StructInNestedNS{a: $a, b: $b}';
   }
+
+  StructInNestedNST unpack() => StructInNestedNST(
+      a: a,
+      b: b);
+
+  static int pack(fb.Builder fbBuilder, StructInNestedNST? object) {
+    if (object == null) return 0;
+    return object.pack(fbBuilder);
+  }
+}
+
+class StructInNestedNST implements fb.Packable {
+  int a;
+  int b;
+
+  StructInNestedNST({
+      required this.a,
+      required this.b});
+
+  @override
+  int pack(fb.Builder fbBuilder) {
+    fbBuilder.putInt32(b);
+    fbBuilder.putInt32(a);
+    return fbBuilder.offset;
+  }
+
+  @override
+  String toString() {
+    return 'StructInNestedNST{a: $a, b: $b}';
+  }
 }
 
 class _StructInNestedNSReader extends fb.StructReader<StructInNestedNS> {
@@ -148,13 +250,11 @@
 
   @override
   StructInNestedNS createObject(fb.BufferContext bc, int offset) => 
-    new StructInNestedNS._(bc, offset);
+    StructInNestedNS._(bc, offset);
 }
 
 class StructInNestedNSBuilder {
-  StructInNestedNSBuilder(this.fbBuilder) {
-    assert(fbBuilder != null);
-  }
+  StructInNestedNSBuilder(this.fbBuilder);
 
   final fb.Builder fbBuilder;
 
@@ -171,18 +271,15 @@
   final int _b;
 
   StructInNestedNSObjectBuilder({
-    int a,
-    int b,
+    required int a,
+    required int b,
   })
       : _a = a,
         _b = b;
 
   /// Finish building, and store into the [fbBuilder].
   @override
-  int finish(
-    fb.Builder fbBuilder) {
-    assert(fbBuilder != null);
-
+  int finish(fb.Builder fbBuilder) {
     fbBuilder.putInt32(_b);
     fbBuilder.putInt32(_a);
     return fbBuilder.offset;
@@ -190,9 +287,9 @@
 
   /// Convenience method to serialize to byte list.
   @override
-  Uint8List toBytes([String fileIdentifier]) {
-    fb.Builder fbBuilder = new fb.Builder();
-    int offset = finish(fbBuilder);
-    return fbBuilder.finish(offset, fileIdentifier);
+  Uint8List toBytes([String? fileIdentifier]) {
+    final fbBuilder = fb.Builder(deduplicateTables: false);
+    fbBuilder.finish(finish(fbBuilder), fileIdentifier);
+    return fbBuilder.buffer;
   }
 }
diff --git a/tests/namespace_test/namespace_test2.fbs b/tests/namespace_test/namespace_test2.fbs
index 11d7dea..e1440e7 100644
--- a/tests/namespace_test/namespace_test2.fbs
+++ b/tests/namespace_test/namespace_test2.fbs
@@ -6,6 +6,7 @@
 {
     foo_table:NamespaceB.TableInNestedNS;
 	foo_enum:NamespaceB.EnumInNestedNS;
+    foo_union:NamespaceB.UnionInNestedNS;
 	foo_struct:NamespaceB.StructInNestedNS;
 }
 
diff --git a/tests/namespace_test/namespace_test2.ts b/tests/namespace_test/namespace_test2.ts
new file mode 100644
index 0000000..01f1bd4
--- /dev/null
+++ b/tests/namespace_test/namespace_test2.ts
@@ -0,0 +1,7 @@
+export { EnumInNestedNS } from './namespace-a/namespace-b/enum-in-nested-n-s';
+export { StructInNestedNS, StructInNestedNST } from './namespace-a/namespace-b/struct-in-nested-n-s';
+export { TableInNestedNS, TableInNestedNST } from './namespace-a/namespace-b/table-in-nested-n-s';
+export { UnionInNestedNS, unionToUnionInNestedNS, unionListToUnionInNestedNS } from './namespace-a/namespace-b/union-in-nested-n-s';
+export { SecondTableInA, SecondTableInAT } from './namespace-a/second-table-in-a';
+export { TableInFirstNS, TableInFirstNST } from './namespace-a/table-in-first-n-s';
+export { TableInC, TableInCT } from './namespace-c/table-in-c';
diff --git a/tests/namespace_test/namespace_test2_generated.h b/tests/namespace_test/namespace_test2_generated.h
index 9c0a1b6..ff164cc 100644
--- a/tests/namespace_test/namespace_test2_generated.h
+++ b/tests/namespace_test/namespace_test2_generated.h
@@ -59,42 +59,34 @@
 
 struct TableInFirstNST : public flatbuffers::NativeTable {
   typedef TableInFirstNS TableType;
-  static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() {
+  static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
     return "NamespaceA.TableInFirstNST";
   }
-  flatbuffers::unique_ptr<NamespaceA::NamespaceB::TableInNestedNST> foo_table;
-  NamespaceA::NamespaceB::EnumInNestedNS foo_enum;
-  flatbuffers::unique_ptr<NamespaceA::NamespaceB::StructInNestedNS> foo_struct;
-  TableInFirstNST()
-      : foo_enum(NamespaceA::NamespaceB::EnumInNestedNS_A) {
-  }
+  flatbuffers::unique_ptr<NamespaceA::NamespaceB::TableInNestedNST> foo_table{};
+  NamespaceA::NamespaceB::EnumInNestedNS foo_enum = NamespaceA::NamespaceB::EnumInNestedNS_A;
+  NamespaceA::NamespaceB::UnionInNestedNSUnion foo_union{};
+  flatbuffers::unique_ptr<NamespaceA::NamespaceB::StructInNestedNS> foo_struct{};
+  TableInFirstNST() = default;
+  TableInFirstNST(const TableInFirstNST &o);
+  TableInFirstNST(TableInFirstNST&&) FLATBUFFERS_NOEXCEPT = default;
+  TableInFirstNST &operator=(TableInFirstNST o) FLATBUFFERS_NOEXCEPT;
 };
 
-inline bool operator==(const TableInFirstNST &lhs, const TableInFirstNST &rhs) {
-  return
-      (lhs.foo_table == rhs.foo_table) &&
-      (lhs.foo_enum == rhs.foo_enum) &&
-      (lhs.foo_struct == rhs.foo_struct);
-}
-
-inline bool operator!=(const TableInFirstNST &lhs, const TableInFirstNST &rhs) {
-    return !(lhs == rhs);
-}
-
-
 struct TableInFirstNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
   typedef TableInFirstNST NativeTableType;
   typedef TableInFirstNSBuilder Builder;
   static const flatbuffers::TypeTable *MiniReflectTypeTable() {
     return TableInFirstNSTypeTable();
   }
-  static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() {
+  static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
     return "NamespaceA.TableInFirstNS";
   }
   enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
     VT_FOO_TABLE = 4,
     VT_FOO_ENUM = 6,
-    VT_FOO_STRUCT = 8
+    VT_FOO_UNION_TYPE = 8,
+    VT_FOO_UNION = 10,
+    VT_FOO_STRUCT = 12
   };
   const NamespaceA::NamespaceB::TableInNestedNS *foo_table() const {
     return GetPointer<const NamespaceA::NamespaceB::TableInNestedNS *>(VT_FOO_TABLE);
@@ -105,9 +97,22 @@
   NamespaceA::NamespaceB::EnumInNestedNS foo_enum() const {
     return static_cast<NamespaceA::NamespaceB::EnumInNestedNS>(GetField<int8_t>(VT_FOO_ENUM, 0));
   }
-  bool mutate_foo_enum(NamespaceA::NamespaceB::EnumInNestedNS _foo_enum) {
+  bool mutate_foo_enum(NamespaceA::NamespaceB::EnumInNestedNS _foo_enum = static_cast<NamespaceA::NamespaceB::EnumInNestedNS>(0)) {
     return SetField<int8_t>(VT_FOO_ENUM, static_cast<int8_t>(_foo_enum), 0);
   }
+  NamespaceA::NamespaceB::UnionInNestedNS foo_union_type() const {
+    return static_cast<NamespaceA::NamespaceB::UnionInNestedNS>(GetField<uint8_t>(VT_FOO_UNION_TYPE, 0));
+  }
+  const void *foo_union() const {
+    return GetPointer<const void *>(VT_FOO_UNION);
+  }
+  template<typename T> const T *foo_union_as() const;
+  const NamespaceA::NamespaceB::TableInNestedNS *foo_union_as_TableInNestedNS() const {
+    return foo_union_type() == NamespaceA::NamespaceB::UnionInNestedNS_TableInNestedNS ? static_cast<const NamespaceA::NamespaceB::TableInNestedNS *>(foo_union()) : nullptr;
+  }
+  void *mutable_foo_union() {
+    return GetPointer<void *>(VT_FOO_UNION);
+  }
   const NamespaceA::NamespaceB::StructInNestedNS *foo_struct() const {
     return GetStruct<const NamespaceA::NamespaceB::StructInNestedNS *>(VT_FOO_STRUCT);
   }
@@ -118,8 +123,11 @@
     return VerifyTableStart(verifier) &&
            VerifyOffset(verifier, VT_FOO_TABLE) &&
            verifier.VerifyTable(foo_table()) &&
-           VerifyField<int8_t>(verifier, VT_FOO_ENUM) &&
-           VerifyField<NamespaceA::NamespaceB::StructInNestedNS>(verifier, VT_FOO_STRUCT) &&
+           VerifyField<int8_t>(verifier, VT_FOO_ENUM, 1) &&
+           VerifyField<uint8_t>(verifier, VT_FOO_UNION_TYPE, 1) &&
+           VerifyOffset(verifier, VT_FOO_UNION) &&
+           VerifyUnionInNestedNS(verifier, foo_union(), foo_union_type()) &&
+           VerifyField<NamespaceA::NamespaceB::StructInNestedNS>(verifier, VT_FOO_STRUCT, 4) &&
            verifier.EndTable();
   }
   TableInFirstNST *UnPack(const flatbuffers::resolver_function_t *_resolver = nullptr) const;
@@ -127,6 +135,10 @@
   static flatbuffers::Offset<TableInFirstNS> Pack(flatbuffers::FlatBufferBuilder &_fbb, const TableInFirstNST* _o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
 };
 
+template<> inline const NamespaceA::NamespaceB::TableInNestedNS *TableInFirstNS::foo_union_as<NamespaceA::NamespaceB::TableInNestedNS>() const {
+  return foo_union_as_TableInNestedNS();
+}
+
 struct TableInFirstNSBuilder {
   typedef TableInFirstNS Table;
   flatbuffers::FlatBufferBuilder &fbb_;
@@ -137,6 +149,12 @@
   void add_foo_enum(NamespaceA::NamespaceB::EnumInNestedNS foo_enum) {
     fbb_.AddElement<int8_t>(TableInFirstNS::VT_FOO_ENUM, static_cast<int8_t>(foo_enum), 0);
   }
+  void add_foo_union_type(NamespaceA::NamespaceB::UnionInNestedNS foo_union_type) {
+    fbb_.AddElement<uint8_t>(TableInFirstNS::VT_FOO_UNION_TYPE, static_cast<uint8_t>(foo_union_type), 0);
+  }
+  void add_foo_union(flatbuffers::Offset<void> foo_union) {
+    fbb_.AddOffset(TableInFirstNS::VT_FOO_UNION, foo_union);
+  }
   void add_foo_struct(const NamespaceA::NamespaceB::StructInNestedNS *foo_struct) {
     fbb_.AddStruct(TableInFirstNS::VT_FOO_STRUCT, foo_struct);
   }
@@ -155,10 +173,14 @@
     flatbuffers::FlatBufferBuilder &_fbb,
     flatbuffers::Offset<NamespaceA::NamespaceB::TableInNestedNS> foo_table = 0,
     NamespaceA::NamespaceB::EnumInNestedNS foo_enum = NamespaceA::NamespaceB::EnumInNestedNS_A,
-    const NamespaceA::NamespaceB::StructInNestedNS *foo_struct = 0) {
+    NamespaceA::NamespaceB::UnionInNestedNS foo_union_type = NamespaceA::NamespaceB::UnionInNestedNS_NONE,
+    flatbuffers::Offset<void> foo_union = 0,
+    const NamespaceA::NamespaceB::StructInNestedNS *foo_struct = nullptr) {
   TableInFirstNSBuilder builder_(_fbb);
   builder_.add_foo_struct(foo_struct);
+  builder_.add_foo_union(foo_union);
   builder_.add_foo_table(foo_table);
+  builder_.add_foo_union_type(foo_union_type);
   builder_.add_foo_enum(foo_enum);
   return builder_.Finish();
 }
@@ -171,33 +193,24 @@
 
 struct TableInCT : public flatbuffers::NativeTable {
   typedef TableInC TableType;
-  static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() {
+  static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
     return "NamespaceC.TableInCT";
   }
-  flatbuffers::unique_ptr<NamespaceA::TableInFirstNST> refer_to_a1;
-  flatbuffers::unique_ptr<NamespaceA::SecondTableInAT> refer_to_a2;
-  TableInCT() {
-  }
+  flatbuffers::unique_ptr<NamespaceA::TableInFirstNST> refer_to_a1{};
+  flatbuffers::unique_ptr<NamespaceA::SecondTableInAT> refer_to_a2{};
+  TableInCT() = default;
+  TableInCT(const TableInCT &o);
+  TableInCT(TableInCT&&) FLATBUFFERS_NOEXCEPT = default;
+  TableInCT &operator=(TableInCT o) FLATBUFFERS_NOEXCEPT;
 };
 
-inline bool operator==(const TableInCT &lhs, const TableInCT &rhs) {
-  return
-      (lhs.refer_to_a1 == rhs.refer_to_a1) &&
-      (lhs.refer_to_a2 == rhs.refer_to_a2);
-}
-
-inline bool operator!=(const TableInCT &lhs, const TableInCT &rhs) {
-    return !(lhs == rhs);
-}
-
-
 struct TableInC FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
   typedef TableInCT NativeTableType;
   typedef TableInCBuilder Builder;
   static const flatbuffers::TypeTable *MiniReflectTypeTable() {
     return TableInCTypeTable();
   }
-  static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() {
+  static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
     return "NamespaceC.TableInC";
   }
   enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
@@ -268,31 +281,23 @@
 
 struct SecondTableInAT : public flatbuffers::NativeTable {
   typedef SecondTableInA TableType;
-  static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() {
+  static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
     return "NamespaceA.SecondTableInAT";
   }
-  flatbuffers::unique_ptr<NamespaceC::TableInCT> refer_to_c;
-  SecondTableInAT() {
-  }
+  flatbuffers::unique_ptr<NamespaceC::TableInCT> refer_to_c{};
+  SecondTableInAT() = default;
+  SecondTableInAT(const SecondTableInAT &o);
+  SecondTableInAT(SecondTableInAT&&) FLATBUFFERS_NOEXCEPT = default;
+  SecondTableInAT &operator=(SecondTableInAT o) FLATBUFFERS_NOEXCEPT;
 };
 
-inline bool operator==(const SecondTableInAT &lhs, const SecondTableInAT &rhs) {
-  return
-      (lhs.refer_to_c == rhs.refer_to_c);
-}
-
-inline bool operator!=(const SecondTableInAT &lhs, const SecondTableInAT &rhs) {
-    return !(lhs == rhs);
-}
-
-
 struct SecondTableInA FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table {
   typedef SecondTableInAT NativeTableType;
   typedef SecondTableInABuilder Builder;
   static const flatbuffers::TypeTable *MiniReflectTypeTable() {
     return SecondTableInATypeTable();
   }
-  static FLATBUFFERS_CONSTEXPR const char *GetFullyQualifiedName() {
+  static FLATBUFFERS_CONSTEXPR_CPP11 const char *GetFullyQualifiedName() {
     return "NamespaceA.SecondTableInA";
   }
   enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {
@@ -343,8 +348,37 @@
 
 flatbuffers::Offset<SecondTableInA> CreateSecondTableInA(flatbuffers::FlatBufferBuilder &_fbb, const SecondTableInAT *_o, const flatbuffers::rehasher_function_t *_rehasher = nullptr);
 
+
+inline bool operator==(const TableInFirstNST &lhs, const TableInFirstNST &rhs) {
+  return
+      ((lhs.foo_table == rhs.foo_table) || (lhs.foo_table && rhs.foo_table && *lhs.foo_table == *rhs.foo_table)) &&
+      (lhs.foo_enum == rhs.foo_enum) &&
+      (lhs.foo_union == rhs.foo_union) &&
+      ((lhs.foo_struct == rhs.foo_struct) || (lhs.foo_struct && rhs.foo_struct && *lhs.foo_struct == *rhs.foo_struct));
+}
+
+inline bool operator!=(const TableInFirstNST &lhs, const TableInFirstNST &rhs) {
+    return !(lhs == rhs);
+}
+
+
+inline TableInFirstNST::TableInFirstNST(const TableInFirstNST &o)
+      : foo_table((o.foo_table) ? new NamespaceA::NamespaceB::TableInNestedNST(*o.foo_table) : nullptr),
+        foo_enum(o.foo_enum),
+        foo_union(o.foo_union),
+        foo_struct((o.foo_struct) ? new NamespaceA::NamespaceB::StructInNestedNS(*o.foo_struct) : nullptr) {
+}
+
+inline TableInFirstNST &TableInFirstNST::operator=(TableInFirstNST o) FLATBUFFERS_NOEXCEPT {
+  std::swap(foo_table, o.foo_table);
+  std::swap(foo_enum, o.foo_enum);
+  std::swap(foo_union, o.foo_union);
+  std::swap(foo_struct, o.foo_struct);
+  return *this;
+}
+
 inline TableInFirstNST *TableInFirstNS::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
-  flatbuffers::unique_ptr<NamespaceA::TableInFirstNST> _o = flatbuffers::unique_ptr<NamespaceA::TableInFirstNST>(new TableInFirstNST());
+  auto _o = std::unique_ptr<TableInFirstNST>(new TableInFirstNST());
   UnPackTo(_o.get(), _resolver);
   return _o.release();
 }
@@ -352,8 +386,10 @@
 inline void TableInFirstNS::UnPackTo(TableInFirstNST *_o, const flatbuffers::resolver_function_t *_resolver) const {
   (void)_o;
   (void)_resolver;
-  { auto _e = foo_table(); if (_e) _o->foo_table = flatbuffers::unique_ptr<NamespaceA::NamespaceB::TableInNestedNST>(_e->UnPack(_resolver)); }
+  { auto _e = foo_table(); if (_e) { if(_o->foo_table) { _e->UnPackTo(_o->foo_table.get(), _resolver); } else { _o->foo_table = flatbuffers::unique_ptr<NamespaceA::NamespaceB::TableInNestedNST>(_e->UnPack(_resolver)); } } }
   { auto _e = foo_enum(); _o->foo_enum = _e; }
+  { auto _e = foo_union_type(); _o->foo_union.type = _e; }
+  { auto _e = foo_union(); if (_e) _o->foo_union.value = NamespaceA::NamespaceB::UnionInNestedNSUnion::UnPack(_e, foo_union_type(), _resolver); }
   { auto _e = foo_struct(); if (_e) _o->foo_struct = flatbuffers::unique_ptr<NamespaceA::NamespaceB::StructInNestedNS>(new NamespaceA::NamespaceB::StructInNestedNS(*_e)); }
 }
 
@@ -367,11 +403,15 @@
   struct _VectorArgs { flatbuffers::FlatBufferBuilder *__fbb; const TableInFirstNST* __o; const flatbuffers::rehasher_function_t *__rehasher; } _va = { &_fbb, _o, _rehasher}; (void)_va;
   auto _foo_table = _o->foo_table ? CreateTableInNestedNS(_fbb, _o->foo_table.get(), _rehasher) : 0;
   auto _foo_enum = _o->foo_enum;
+  auto _foo_union_type = _o->foo_union.type;
+  auto _foo_union = _o->foo_union.Pack(_fbb);
   auto _foo_struct = _o->foo_struct ? _o->foo_struct.get() : 0;
   return NamespaceA::CreateTableInFirstNS(
       _fbb,
       _foo_table,
       _foo_enum,
+      _foo_union_type,
+      _foo_union,
       _foo_struct);
 }
 
@@ -379,8 +419,31 @@
 
 namespace NamespaceC {
 
+
+inline bool operator==(const TableInCT &lhs, const TableInCT &rhs) {
+  return
+      ((lhs.refer_to_a1 == rhs.refer_to_a1) || (lhs.refer_to_a1 && rhs.refer_to_a1 && *lhs.refer_to_a1 == *rhs.refer_to_a1)) &&
+      ((lhs.refer_to_a2 == rhs.refer_to_a2) || (lhs.refer_to_a2 && rhs.refer_to_a2 && *lhs.refer_to_a2 == *rhs.refer_to_a2));
+}
+
+inline bool operator!=(const TableInCT &lhs, const TableInCT &rhs) {
+    return !(lhs == rhs);
+}
+
+
+inline TableInCT::TableInCT(const TableInCT &o)
+      : refer_to_a1((o.refer_to_a1) ? new NamespaceA::TableInFirstNST(*o.refer_to_a1) : nullptr),
+        refer_to_a2((o.refer_to_a2) ? new NamespaceA::SecondTableInAT(*o.refer_to_a2) : nullptr) {
+}
+
+inline TableInCT &TableInCT::operator=(TableInCT o) FLATBUFFERS_NOEXCEPT {
+  std::swap(refer_to_a1, o.refer_to_a1);
+  std::swap(refer_to_a2, o.refer_to_a2);
+  return *this;
+}
+
 inline TableInCT *TableInC::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
-  flatbuffers::unique_ptr<NamespaceC::TableInCT> _o = flatbuffers::unique_ptr<NamespaceC::TableInCT>(new TableInCT());
+  auto _o = std::unique_ptr<TableInCT>(new TableInCT());
   UnPackTo(_o.get(), _resolver);
   return _o.release();
 }
@@ -388,8 +451,8 @@
 inline void TableInC::UnPackTo(TableInCT *_o, const flatbuffers::resolver_function_t *_resolver) const {
   (void)_o;
   (void)_resolver;
-  { auto _e = refer_to_a1(); if (_e) _o->refer_to_a1 = flatbuffers::unique_ptr<NamespaceA::TableInFirstNST>(_e->UnPack(_resolver)); }
-  { auto _e = refer_to_a2(); if (_e) _o->refer_to_a2 = flatbuffers::unique_ptr<NamespaceA::SecondTableInAT>(_e->UnPack(_resolver)); }
+  { auto _e = refer_to_a1(); if (_e) { if(_o->refer_to_a1) { _e->UnPackTo(_o->refer_to_a1.get(), _resolver); } else { _o->refer_to_a1 = flatbuffers::unique_ptr<NamespaceA::TableInFirstNST>(_e->UnPack(_resolver)); } } }
+  { auto _e = refer_to_a2(); if (_e) { if(_o->refer_to_a2) { _e->UnPackTo(_o->refer_to_a2.get(), _resolver); } else { _o->refer_to_a2 = flatbuffers::unique_ptr<NamespaceA::SecondTableInAT>(_e->UnPack(_resolver)); } } }
 }
 
 inline flatbuffers::Offset<TableInC> TableInC::Pack(flatbuffers::FlatBufferBuilder &_fbb, const TableInCT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
@@ -412,8 +475,28 @@
 
 namespace NamespaceA {
 
+
+inline bool operator==(const SecondTableInAT &lhs, const SecondTableInAT &rhs) {
+  return
+      ((lhs.refer_to_c == rhs.refer_to_c) || (lhs.refer_to_c && rhs.refer_to_c && *lhs.refer_to_c == *rhs.refer_to_c));
+}
+
+inline bool operator!=(const SecondTableInAT &lhs, const SecondTableInAT &rhs) {
+    return !(lhs == rhs);
+}
+
+
+inline SecondTableInAT::SecondTableInAT(const SecondTableInAT &o)
+      : refer_to_c((o.refer_to_c) ? new NamespaceC::TableInCT(*o.refer_to_c) : nullptr) {
+}
+
+inline SecondTableInAT &SecondTableInAT::operator=(SecondTableInAT o) FLATBUFFERS_NOEXCEPT {
+  std::swap(refer_to_c, o.refer_to_c);
+  return *this;
+}
+
 inline SecondTableInAT *SecondTableInA::UnPack(const flatbuffers::resolver_function_t *_resolver) const {
-  flatbuffers::unique_ptr<NamespaceA::SecondTableInAT> _o = flatbuffers::unique_ptr<NamespaceA::SecondTableInAT>(new SecondTableInAT());
+  auto _o = std::unique_ptr<SecondTableInAT>(new SecondTableInAT());
   UnPackTo(_o.get(), _resolver);
   return _o.release();
 }
@@ -421,7 +504,7 @@
 inline void SecondTableInA::UnPackTo(SecondTableInAT *_o, const flatbuffers::resolver_function_t *_resolver) const {
   (void)_o;
   (void)_resolver;
-  { auto _e = refer_to_c(); if (_e) _o->refer_to_c = flatbuffers::unique_ptr<NamespaceC::TableInCT>(_e->UnPack(_resolver)); }
+  { auto _e = refer_to_c(); if (_e) { if(_o->refer_to_c) { _e->UnPackTo(_o->refer_to_c.get(), _resolver); } else { _o->refer_to_c = flatbuffers::unique_ptr<NamespaceC::TableInCT>(_e->UnPack(_resolver)); } } }
 }
 
 inline flatbuffers::Offset<SecondTableInA> SecondTableInA::Pack(flatbuffers::FlatBufferBuilder &_fbb, const SecondTableInAT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
@@ -442,20 +525,25 @@
   static const flatbuffers::TypeCode type_codes[] = {
     { flatbuffers::ET_SEQUENCE, 0, 0 },
     { flatbuffers::ET_CHAR, 0, 1 },
-    { flatbuffers::ET_SEQUENCE, 0, 2 }
+    { flatbuffers::ET_UTYPE, 0, 2 },
+    { flatbuffers::ET_SEQUENCE, 0, 2 },
+    { flatbuffers::ET_SEQUENCE, 0, 3 }
   };
   static const flatbuffers::TypeFunction type_refs[] = {
     NamespaceA::NamespaceB::TableInNestedNSTypeTable,
     NamespaceA::NamespaceB::EnumInNestedNSTypeTable,
+    NamespaceA::NamespaceB::UnionInNestedNSTypeTable,
     NamespaceA::NamespaceB::StructInNestedNSTypeTable
   };
   static const char * const names[] = {
     "foo_table",
     "foo_enum",
+    "foo_union_type",
+    "foo_union",
     "foo_struct"
   };
   static const flatbuffers::TypeTable tt = {
-    flatbuffers::ST_TABLE, 3, type_codes, type_refs, nullptr, nullptr, names
+    flatbuffers::ST_TABLE, 5, type_codes, type_refs, nullptr, nullptr, names
   };
   return &tt;
 }
diff --git a/tests/namespace_test/namespace_test2_generated.js b/tests/namespace_test/namespace_test2_generated.js
deleted file mode 100644
index 9b2668c..0000000
--- a/tests/namespace_test/namespace_test2_generated.js
+++ /dev/null
@@ -1,354 +0,0 @@
-// automatically generated by the FlatBuffers compiler, do not modify
-
-/**
- * @const
- * @namespace
- */
-var NamespaceA = NamespaceA || {};
-
-/**
- * @const
- * @namespace
- */
-NamespaceA.NamespaceB = NamespaceA.NamespaceB || {};
-
-/**
- * @const
- * @namespace
- */
-var NamespaceC = NamespaceC || {};
-
-/**
- * @constructor
- */
-NamespaceA.TableInFirstNS = function() {
-  /**
-   * @type {flatbuffers.ByteBuffer}
-   */
-  this.bb = null;
-
-  /**
-   * @type {number}
-   */
-  this.bb_pos = 0;
-};
-
-/**
- * @param {number} i
- * @param {flatbuffers.ByteBuffer} bb
- * @returns {NamespaceA.TableInFirstNS}
- */
-NamespaceA.TableInFirstNS.prototype.__init = function(i, bb) {
-  this.bb_pos = i;
-  this.bb = bb;
-  return this;
-};
-
-/**
- * @param {flatbuffers.ByteBuffer} bb
- * @param {NamespaceA.TableInFirstNS=} obj
- * @returns {NamespaceA.TableInFirstNS}
- */
-NamespaceA.TableInFirstNS.getRootAsTableInFirstNS = function(bb, obj) {
-  return (obj || new NamespaceA.TableInFirstNS).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param {flatbuffers.ByteBuffer} bb
- * @param {NamespaceA.TableInFirstNS=} obj
- * @returns {NamespaceA.TableInFirstNS}
- */
-NamespaceA.TableInFirstNS.getSizePrefixedRootAsTableInFirstNS = function(bb, obj) {
-  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
-  return (obj || new NamespaceA.TableInFirstNS).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param {NamespaceA.NamespaceB.TableInNestedNS=} obj
- * @returns {NamespaceA.NamespaceB.TableInNestedNS|null}
- */
-NamespaceA.TableInFirstNS.prototype.fooTable = function(obj) {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? (obj || new NamespaceA.NamespaceB.TableInNestedNS).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
-};
-
-/**
- * @returns {NamespaceA.NamespaceB.EnumInNestedNS}
- */
-NamespaceA.TableInFirstNS.prototype.fooEnum = function() {
-  var offset = this.bb.__offset(this.bb_pos, 6);
-  return offset ? /** @type {NamespaceA.NamespaceB.EnumInNestedNS} */ (this.bb.readInt8(this.bb_pos + offset)) : NamespaceA.NamespaceB.EnumInNestedNS.A;
-};
-
-/**
- * @param {NamespaceA.NamespaceB.EnumInNestedNS} value
- * @returns {boolean}
- */
-NamespaceA.TableInFirstNS.prototype.mutate_foo_enum = function(value) {
-  var offset = this.bb.__offset(this.bb_pos, 6);
-
-  if (offset === 0) {
-    return false;
-  }
-
-  this.bb.writeInt8(this.bb_pos + offset, value);
-  return true;
-};
-
-/**
- * @param {NamespaceA.NamespaceB.StructInNestedNS=} obj
- * @returns {NamespaceA.NamespaceB.StructInNestedNS|null}
- */
-NamespaceA.TableInFirstNS.prototype.fooStruct = function(obj) {
-  var offset = this.bb.__offset(this.bb_pos, 8);
-  return offset ? (obj || new NamespaceA.NamespaceB.StructInNestedNS).__init(this.bb_pos + offset, this.bb) : null;
-};
-
-/**
- * @returns {string}
- */
-NamespaceA.TableInFirstNS.getFullyQualifiedName = function() {
-  return 'NamespaceA.TableInFirstNS';
-}
-
-/**
- * @param {flatbuffers.Builder} builder
- */
-NamespaceA.TableInFirstNS.startTableInFirstNS = function(builder) {
-  builder.startObject(3);
-};
-
-/**
- * @param {flatbuffers.Builder} builder
- * @param {flatbuffers.Offset} fooTableOffset
- */
-NamespaceA.TableInFirstNS.addFooTable = function(builder, fooTableOffset) {
-  builder.addFieldOffset(0, fooTableOffset, 0);
-};
-
-/**
- * @param {flatbuffers.Builder} builder
- * @param {NamespaceA.NamespaceB.EnumInNestedNS} fooEnum
- */
-NamespaceA.TableInFirstNS.addFooEnum = function(builder, fooEnum) {
-  builder.addFieldInt8(1, fooEnum, NamespaceA.NamespaceB.EnumInNestedNS.A);
-};
-
-/**
- * @param {flatbuffers.Builder} builder
- * @param {flatbuffers.Offset} fooStructOffset
- */
-NamespaceA.TableInFirstNS.addFooStruct = function(builder, fooStructOffset) {
-  builder.addFieldStruct(2, fooStructOffset, 0);
-};
-
-/**
- * @param {flatbuffers.Builder} builder
- * @returns {flatbuffers.Offset}
- */
-NamespaceA.TableInFirstNS.endTableInFirstNS = function(builder) {
-  var offset = builder.endObject();
-  return offset;
-};
-
-/**
- * @constructor
- */
-NamespaceC.TableInC = function() {
-  /**
-   * @type {flatbuffers.ByteBuffer}
-   */
-  this.bb = null;
-
-  /**
-   * @type {number}
-   */
-  this.bb_pos = 0;
-};
-
-/**
- * @param {number} i
- * @param {flatbuffers.ByteBuffer} bb
- * @returns {NamespaceC.TableInC}
- */
-NamespaceC.TableInC.prototype.__init = function(i, bb) {
-  this.bb_pos = i;
-  this.bb = bb;
-  return this;
-};
-
-/**
- * @param {flatbuffers.ByteBuffer} bb
- * @param {NamespaceC.TableInC=} obj
- * @returns {NamespaceC.TableInC}
- */
-NamespaceC.TableInC.getRootAsTableInC = function(bb, obj) {
-  return (obj || new NamespaceC.TableInC).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param {flatbuffers.ByteBuffer} bb
- * @param {NamespaceC.TableInC=} obj
- * @returns {NamespaceC.TableInC}
- */
-NamespaceC.TableInC.getSizePrefixedRootAsTableInC = function(bb, obj) {
-  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
-  return (obj || new NamespaceC.TableInC).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param {NamespaceA.TableInFirstNS=} obj
- * @returns {NamespaceA.TableInFirstNS|null}
- */
-NamespaceC.TableInC.prototype.referToA1 = function(obj) {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? (obj || new NamespaceA.TableInFirstNS).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
-};
-
-/**
- * @param {NamespaceA.SecondTableInA=} obj
- * @returns {NamespaceA.SecondTableInA|null}
- */
-NamespaceC.TableInC.prototype.referToA2 = function(obj) {
-  var offset = this.bb.__offset(this.bb_pos, 6);
-  return offset ? (obj || new NamespaceA.SecondTableInA).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
-};
-
-/**
- * @returns {string}
- */
-NamespaceC.TableInC.getFullyQualifiedName = function() {
-  return 'NamespaceC.TableInC';
-}
-
-/**
- * @param {flatbuffers.Builder} builder
- */
-NamespaceC.TableInC.startTableInC = function(builder) {
-  builder.startObject(2);
-};
-
-/**
- * @param {flatbuffers.Builder} builder
- * @param {flatbuffers.Offset} referToA1Offset
- */
-NamespaceC.TableInC.addReferToA1 = function(builder, referToA1Offset) {
-  builder.addFieldOffset(0, referToA1Offset, 0);
-};
-
-/**
- * @param {flatbuffers.Builder} builder
- * @param {flatbuffers.Offset} referToA2Offset
- */
-NamespaceC.TableInC.addReferToA2 = function(builder, referToA2Offset) {
-  builder.addFieldOffset(1, referToA2Offset, 0);
-};
-
-/**
- * @param {flatbuffers.Builder} builder
- * @returns {flatbuffers.Offset}
- */
-NamespaceC.TableInC.endTableInC = function(builder) {
-  var offset = builder.endObject();
-  return offset;
-};
-
-/**
- * @constructor
- */
-NamespaceA.SecondTableInA = function() {
-  /**
-   * @type {flatbuffers.ByteBuffer}
-   */
-  this.bb = null;
-
-  /**
-   * @type {number}
-   */
-  this.bb_pos = 0;
-};
-
-/**
- * @param {number} i
- * @param {flatbuffers.ByteBuffer} bb
- * @returns {NamespaceA.SecondTableInA}
- */
-NamespaceA.SecondTableInA.prototype.__init = function(i, bb) {
-  this.bb_pos = i;
-  this.bb = bb;
-  return this;
-};
-
-/**
- * @param {flatbuffers.ByteBuffer} bb
- * @param {NamespaceA.SecondTableInA=} obj
- * @returns {NamespaceA.SecondTableInA}
- */
-NamespaceA.SecondTableInA.getRootAsSecondTableInA = function(bb, obj) {
-  return (obj || new NamespaceA.SecondTableInA).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param {flatbuffers.ByteBuffer} bb
- * @param {NamespaceA.SecondTableInA=} obj
- * @returns {NamespaceA.SecondTableInA}
- */
-NamespaceA.SecondTableInA.getSizePrefixedRootAsSecondTableInA = function(bb, obj) {
-  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
-  return (obj || new NamespaceA.SecondTableInA).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param {NamespaceC.TableInC=} obj
- * @returns {NamespaceC.TableInC|null}
- */
-NamespaceA.SecondTableInA.prototype.referToC = function(obj) {
-  var offset = this.bb.__offset(this.bb_pos, 4);
-  return offset ? (obj || new NamespaceC.TableInC).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
-};
-
-/**
- * @returns {string}
- */
-NamespaceA.SecondTableInA.getFullyQualifiedName = function() {
-  return 'NamespaceA.SecondTableInA';
-}
-
-/**
- * @param {flatbuffers.Builder} builder
- */
-NamespaceA.SecondTableInA.startSecondTableInA = function(builder) {
-  builder.startObject(1);
-};
-
-/**
- * @param {flatbuffers.Builder} builder
- * @param {flatbuffers.Offset} referToCOffset
- */
-NamespaceA.SecondTableInA.addReferToC = function(builder, referToCOffset) {
-  builder.addFieldOffset(0, referToCOffset, 0);
-};
-
-/**
- * @param {flatbuffers.Builder} builder
- * @returns {flatbuffers.Offset}
- */
-NamespaceA.SecondTableInA.endSecondTableInA = function(builder) {
-  var offset = builder.endObject();
-  return offset;
-};
-
-/**
- * @param {flatbuffers.Builder} builder
- * @param {flatbuffers.Offset} referToCOffset
- * @returns {flatbuffers.Offset}
- */
-NamespaceA.SecondTableInA.createSecondTableInA = function(builder, referToCOffset) {
-  NamespaceA.SecondTableInA.startSecondTableInA(builder);
-  NamespaceA.SecondTableInA.addReferToC(builder, referToCOffset);
-  return NamespaceA.SecondTableInA.endSecondTableInA(builder);
-}
-
-// Exports for Node.js and RequireJS
-this.NamespaceA = NamespaceA;
-this.NamespaceC = NamespaceC;
diff --git a/tests/namespace_test/namespace_test2_generated.lobster b/tests/namespace_test/namespace_test2_generated.lobster
index 4383e68..3820928 100644
--- a/tests/namespace_test/namespace_test2_generated.lobster
+++ b/tests/namespace_test/namespace_test2_generated.lobster
@@ -19,8 +19,12 @@
         return if o: NamespaceA_NamespaceB_TableInNestedNS { buf_, o } else: nil
     def foo_enum():
         return EnumInNestedNS(buf_.flatbuffers_field_int8(pos_, 6, 0))
+    def foo_union_type():
+        return UnionInNestedNS(buf_.flatbuffers_field_int8(pos_, 8, 0))
+    def foo_union_as_TableInNestedNS():
+        return NamespaceA_NamespaceB_TableInNestedNS { buf_, buf_.flatbuffers_field_table(pos_, 10) }
     def foo_struct():
-        let o = buf_.flatbuffers_field_struct(pos_, 8)
+        let o = buf_.flatbuffers_field_struct(pos_, 12)
         return if o: NamespaceA_NamespaceB_StructInNestedNS { buf_, o } else: nil
 
 def GetRootAsTableInFirstNS(buf:string): return TableInFirstNS { buf, buf.flatbuffers_indirect(0) }
@@ -28,7 +32,7 @@
 struct TableInFirstNSBuilder:
     b_:flatbuffers_builder
     def start():
-        b_.StartObject(3)
+        b_.StartObject(5)
         return this
     def add_foo_table(foo_table:flatbuffers_offset):
         b_.PrependUOffsetTRelativeSlot(0, foo_table)
@@ -36,8 +40,14 @@
     def add_foo_enum(foo_enum:EnumInNestedNS):
         b_.PrependInt8Slot(1, foo_enum, 0)
         return this
+    def add_foo_union_type(foo_union_type:UnionInNestedNS):
+        b_.PrependUint8Slot(2, foo_union_type, 0)
+        return this
+    def add_foo_union(foo_union:flatbuffers_offset):
+        b_.PrependUOffsetTRelativeSlot(3, foo_union)
+        return this
     def add_foo_struct(foo_struct:flatbuffers_offset):
-        b_.PrependStructSlot(2, foo_struct)
+        b_.PrependStructSlot(4, foo_struct)
         return this
     def end():
         return b_.EndObject()
diff --git a/tests/namespace_test/namespace_test2_generated.rs b/tests/namespace_test/namespace_test2_generated.rs
deleted file mode 100644
index b1d84cf..0000000
--- a/tests/namespace_test/namespace_test2_generated.rs
+++ /dev/null
@@ -1,330 +0,0 @@
-// automatically generated by the FlatBuffers compiler, do not modify
-
-
-#![allow(unused_imports, dead_code)]
-
-use crate::namespace_test1_generated::*;
-use std::mem;
-use std::cmp::Ordering;
-
-extern crate flatbuffers;
-use self::flatbuffers::EndianScalar;
-
-#[allow(unused_imports, dead_code)]
-pub mod namespace_a {
-
-  use crate::namespace_test1_generated::*;
-  use std::mem;
-  use std::cmp::Ordering;
-
-  extern crate flatbuffers;
-  use self::flatbuffers::EndianScalar;
-
-pub enum TableInFirstNSOffset {}
-#[derive(Copy, Clone, PartialEq)]
-
-pub struct TableInFirstNS<'a> {
-  pub _tab: flatbuffers::Table<'a>,
-}
-
-impl<'a> flatbuffers::Follow<'a> for TableInFirstNS<'a> {
-    type Inner = TableInFirstNS<'a>;
-    #[inline]
-    fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
-        Self { _tab: flatbuffers::Table { buf, loc } }
-    }
-}
-
-impl<'a> TableInFirstNS<'a> {
-    pub const fn get_fully_qualified_name() -> &'static str {
-        "NamespaceA.TableInFirstNS"
-    }
-
-    #[inline]
-    pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
-        TableInFirstNS {
-            _tab: table,
-        }
-    }
-    #[allow(unused_mut)]
-    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
-        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
-        args: &'args TableInFirstNSArgs<'args>) -> flatbuffers::WIPOffset<TableInFirstNS<'bldr>> {
-      let mut builder = TableInFirstNSBuilder::new(_fbb);
-      if let Some(x) = args.foo_struct { builder.add_foo_struct(x); }
-      if let Some(x) = args.foo_table { builder.add_foo_table(x); }
-      builder.add_foo_enum(args.foo_enum);
-      builder.finish()
-    }
-
-    pub const VT_FOO_TABLE: flatbuffers::VOffsetT = 4;
-    pub const VT_FOO_ENUM: flatbuffers::VOffsetT = 6;
-    pub const VT_FOO_STRUCT: flatbuffers::VOffsetT = 8;
-
-  #[inline]
-  pub fn foo_table(&self) -> Option<namespace_b::TableInNestedNS<'a>> {
-    self._tab.get::<flatbuffers::ForwardsUOffset<namespace_b::TableInNestedNS<'a>>>(TableInFirstNS::VT_FOO_TABLE, None)
-  }
-  #[inline]
-  pub fn foo_enum(&self) -> namespace_b::EnumInNestedNS {
-    self._tab.get::<namespace_b::EnumInNestedNS>(TableInFirstNS::VT_FOO_ENUM, Some(namespace_b::EnumInNestedNS::A)).unwrap()
-  }
-  #[inline]
-  pub fn foo_struct(&self) -> Option<&'a namespace_b::StructInNestedNS> {
-    self._tab.get::<namespace_b::StructInNestedNS>(TableInFirstNS::VT_FOO_STRUCT, None)
-  }
-}
-
-pub struct TableInFirstNSArgs<'a> {
-    pub foo_table: Option<flatbuffers::WIPOffset<namespace_b::TableInNestedNS<'a>>>,
-    pub foo_enum: namespace_b::EnumInNestedNS,
-    pub foo_struct: Option<&'a namespace_b::StructInNestedNS>,
-}
-impl<'a> Default for TableInFirstNSArgs<'a> {
-    #[inline]
-    fn default() -> Self {
-        TableInFirstNSArgs {
-            foo_table: None,
-            foo_enum: namespace_b::EnumInNestedNS::A,
-            foo_struct: None,
-        }
-    }
-}
-pub struct TableInFirstNSBuilder<'a: 'b, 'b> {
-  fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
-  start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
-}
-impl<'a: 'b, 'b> TableInFirstNSBuilder<'a, 'b> {
-  #[inline]
-  pub fn add_foo_table(&mut self, foo_table: flatbuffers::WIPOffset<namespace_b::TableInNestedNS<'b >>) {
-    self.fbb_.push_slot_always::<flatbuffers::WIPOffset<namespace_b::TableInNestedNS>>(TableInFirstNS::VT_FOO_TABLE, foo_table);
-  }
-  #[inline]
-  pub fn add_foo_enum(&mut self, foo_enum: namespace_b::EnumInNestedNS) {
-    self.fbb_.push_slot::<namespace_b::EnumInNestedNS>(TableInFirstNS::VT_FOO_ENUM, foo_enum, namespace_b::EnumInNestedNS::A);
-  }
-  #[inline]
-  pub fn add_foo_struct(&mut self, foo_struct: &namespace_b::StructInNestedNS) {
-    self.fbb_.push_slot_always::<&namespace_b::StructInNestedNS>(TableInFirstNS::VT_FOO_STRUCT, foo_struct);
-  }
-  #[inline]
-  pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> TableInFirstNSBuilder<'a, 'b> {
-    let start = _fbb.start_table();
-    TableInFirstNSBuilder {
-      fbb_: _fbb,
-      start_: start,
-    }
-  }
-  #[inline]
-  pub fn finish(self) -> flatbuffers::WIPOffset<TableInFirstNS<'a>> {
-    let o = self.fbb_.end_table(self.start_);
-    flatbuffers::WIPOffset::new(o.value())
-  }
-}
-
-impl std::fmt::Debug for TableInFirstNS<'_> {
-  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-    let mut ds = f.debug_struct("TableInFirstNS");
-      ds.field("foo_table", &self.foo_table());
-      ds.field("foo_enum", &self.foo_enum());
-      ds.field("foo_struct", &self.foo_struct());
-      ds.finish()
-  }
-}
-pub enum SecondTableInAOffset {}
-#[derive(Copy, Clone, PartialEq)]
-
-pub struct SecondTableInA<'a> {
-  pub _tab: flatbuffers::Table<'a>,
-}
-
-impl<'a> flatbuffers::Follow<'a> for SecondTableInA<'a> {
-    type Inner = SecondTableInA<'a>;
-    #[inline]
-    fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
-        Self { _tab: flatbuffers::Table { buf, loc } }
-    }
-}
-
-impl<'a> SecondTableInA<'a> {
-    pub const fn get_fully_qualified_name() -> &'static str {
-        "NamespaceA.SecondTableInA"
-    }
-
-    #[inline]
-    pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
-        SecondTableInA {
-            _tab: table,
-        }
-    }
-    #[allow(unused_mut)]
-    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
-        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
-        args: &'args SecondTableInAArgs<'args>) -> flatbuffers::WIPOffset<SecondTableInA<'bldr>> {
-      let mut builder = SecondTableInABuilder::new(_fbb);
-      if let Some(x) = args.refer_to_c { builder.add_refer_to_c(x); }
-      builder.finish()
-    }
-
-    pub const VT_REFER_TO_C: flatbuffers::VOffsetT = 4;
-
-  #[inline]
-  pub fn refer_to_c(&self) -> Option<super::namespace_c::TableInC<'a>> {
-    self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_c::TableInC<'a>>>(SecondTableInA::VT_REFER_TO_C, None)
-  }
-}
-
-pub struct SecondTableInAArgs<'a> {
-    pub refer_to_c: Option<flatbuffers::WIPOffset<super::namespace_c::TableInC<'a>>>,
-}
-impl<'a> Default for SecondTableInAArgs<'a> {
-    #[inline]
-    fn default() -> Self {
-        SecondTableInAArgs {
-            refer_to_c: None,
-        }
-    }
-}
-pub struct SecondTableInABuilder<'a: 'b, 'b> {
-  fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
-  start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
-}
-impl<'a: 'b, 'b> SecondTableInABuilder<'a, 'b> {
-  #[inline]
-  pub fn add_refer_to_c(&mut self, refer_to_c: flatbuffers::WIPOffset<super::namespace_c::TableInC<'b >>) {
-    self.fbb_.push_slot_always::<flatbuffers::WIPOffset<super::namespace_c::TableInC>>(SecondTableInA::VT_REFER_TO_C, refer_to_c);
-  }
-  #[inline]
-  pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> SecondTableInABuilder<'a, 'b> {
-    let start = _fbb.start_table();
-    SecondTableInABuilder {
-      fbb_: _fbb,
-      start_: start,
-    }
-  }
-  #[inline]
-  pub fn finish(self) -> flatbuffers::WIPOffset<SecondTableInA<'a>> {
-    let o = self.fbb_.end_table(self.start_);
-    flatbuffers::WIPOffset::new(o.value())
-  }
-}
-
-impl std::fmt::Debug for SecondTableInA<'_> {
-  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-    let mut ds = f.debug_struct("SecondTableInA");
-      ds.field("refer_to_c", &self.refer_to_c());
-      ds.finish()
-  }
-}
-}  // pub mod NamespaceA
-
-#[allow(unused_imports, dead_code)]
-pub mod namespace_c {
-
-  use crate::namespace_test1_generated::*;
-  use std::mem;
-  use std::cmp::Ordering;
-
-  extern crate flatbuffers;
-  use self::flatbuffers::EndianScalar;
-
-pub enum TableInCOffset {}
-#[derive(Copy, Clone, PartialEq)]
-
-pub struct TableInC<'a> {
-  pub _tab: flatbuffers::Table<'a>,
-}
-
-impl<'a> flatbuffers::Follow<'a> for TableInC<'a> {
-    type Inner = TableInC<'a>;
-    #[inline]
-    fn follow(buf: &'a [u8], loc: usize) -> Self::Inner {
-        Self { _tab: flatbuffers::Table { buf, loc } }
-    }
-}
-
-impl<'a> TableInC<'a> {
-    pub const fn get_fully_qualified_name() -> &'static str {
-        "NamespaceC.TableInC"
-    }
-
-    #[inline]
-    pub fn init_from_table(table: flatbuffers::Table<'a>) -> Self {
-        TableInC {
-            _tab: table,
-        }
-    }
-    #[allow(unused_mut)]
-    pub fn create<'bldr: 'args, 'args: 'mut_bldr, 'mut_bldr>(
-        _fbb: &'mut_bldr mut flatbuffers::FlatBufferBuilder<'bldr>,
-        args: &'args TableInCArgs<'args>) -> flatbuffers::WIPOffset<TableInC<'bldr>> {
-      let mut builder = TableInCBuilder::new(_fbb);
-      if let Some(x) = args.refer_to_a2 { builder.add_refer_to_a2(x); }
-      if let Some(x) = args.refer_to_a1 { builder.add_refer_to_a1(x); }
-      builder.finish()
-    }
-
-    pub const VT_REFER_TO_A1: flatbuffers::VOffsetT = 4;
-    pub const VT_REFER_TO_A2: flatbuffers::VOffsetT = 6;
-
-  #[inline]
-  pub fn refer_to_a1(&self) -> Option<super::namespace_a::TableInFirstNS<'a>> {
-    self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_a::TableInFirstNS<'a>>>(TableInC::VT_REFER_TO_A1, None)
-  }
-  #[inline]
-  pub fn refer_to_a2(&self) -> Option<super::namespace_a::SecondTableInA<'a>> {
-    self._tab.get::<flatbuffers::ForwardsUOffset<super::namespace_a::SecondTableInA<'a>>>(TableInC::VT_REFER_TO_A2, None)
-  }
-}
-
-pub struct TableInCArgs<'a> {
-    pub refer_to_a1: Option<flatbuffers::WIPOffset<super::namespace_a::TableInFirstNS<'a>>>,
-    pub refer_to_a2: Option<flatbuffers::WIPOffset<super::namespace_a::SecondTableInA<'a>>>,
-}
-impl<'a> Default for TableInCArgs<'a> {
-    #[inline]
-    fn default() -> Self {
-        TableInCArgs {
-            refer_to_a1: None,
-            refer_to_a2: None,
-        }
-    }
-}
-pub struct TableInCBuilder<'a: 'b, 'b> {
-  fbb_: &'b mut flatbuffers::FlatBufferBuilder<'a>,
-  start_: flatbuffers::WIPOffset<flatbuffers::TableUnfinishedWIPOffset>,
-}
-impl<'a: 'b, 'b> TableInCBuilder<'a, 'b> {
-  #[inline]
-  pub fn add_refer_to_a1(&mut self, refer_to_a1: flatbuffers::WIPOffset<super::namespace_a::TableInFirstNS<'b >>) {
-    self.fbb_.push_slot_always::<flatbuffers::WIPOffset<super::namespace_a::TableInFirstNS>>(TableInC::VT_REFER_TO_A1, refer_to_a1);
-  }
-  #[inline]
-  pub fn add_refer_to_a2(&mut self, refer_to_a2: flatbuffers::WIPOffset<super::namespace_a::SecondTableInA<'b >>) {
-    self.fbb_.push_slot_always::<flatbuffers::WIPOffset<super::namespace_a::SecondTableInA>>(TableInC::VT_REFER_TO_A2, refer_to_a2);
-  }
-  #[inline]
-  pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> TableInCBuilder<'a, 'b> {
-    let start = _fbb.start_table();
-    TableInCBuilder {
-      fbb_: _fbb,
-      start_: start,
-    }
-  }
-  #[inline]
-  pub fn finish(self) -> flatbuffers::WIPOffset<TableInC<'a>> {
-    let o = self.fbb_.end_table(self.start_);
-    flatbuffers::WIPOffset::new(o.value())
-  }
-}
-
-impl std::fmt::Debug for TableInC<'_> {
-  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
-    let mut ds = f.debug_struct("TableInC");
-      ds.field("refer_to_a1", &self.refer_to_a1());
-      ds.field("refer_to_a2", &self.refer_to_a2());
-      ds.finish()
-  }
-}
-}  // pub mod NamespaceC
-
diff --git a/tests/namespace_test/namespace_test2_generated.ts b/tests/namespace_test/namespace_test2_generated.ts
deleted file mode 100644
index bd3c903..0000000
--- a/tests/namespace_test/namespace_test2_generated.ts
+++ /dev/null
@@ -1,438 +0,0 @@
-// automatically generated by the FlatBuffers compiler, do not modify
-
-import * as NS8755221360535654258 from "./namespace_test1_generated";
-/**
- * @constructor
- */
-export namespace NamespaceA{
-export class TableInFirstNS {
-  bb: flatbuffers.ByteBuffer|null = null;
-
-  bb_pos:number = 0;
-/**
- * @param number i
- * @param flatbuffers.ByteBuffer bb
- * @returns TableInFirstNS
- */
-__init(i:number, bb:flatbuffers.ByteBuffer):TableInFirstNS {
-  this.bb_pos = i;
-  this.bb = bb;
-  return this;
-};
-
-/**
- * @param flatbuffers.ByteBuffer bb
- * @param TableInFirstNS= obj
- * @returns TableInFirstNS
- */
-static getRootAsTableInFirstNS(bb:flatbuffers.ByteBuffer, obj?:TableInFirstNS):TableInFirstNS {
-  return (obj || new TableInFirstNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param flatbuffers.ByteBuffer bb
- * @param TableInFirstNS= obj
- * @returns TableInFirstNS
- */
-static getSizePrefixedRootAsTableInFirstNS(bb:flatbuffers.ByteBuffer, obj?:TableInFirstNS):TableInFirstNS {
-  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
-  return (obj || new TableInFirstNS()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param NamespaceA.NamespaceB.TableInNestedNS= obj
- * @returns NamespaceA.NamespaceB.TableInNestedNS|null
- */
-fooTable(obj?:NS8755221360535654258.NamespaceA.NamespaceB.TableInNestedNS):NS8755221360535654258.NamespaceA.NamespaceB.TableInNestedNS|null {
-  var offset = this.bb!.__offset(this.bb_pos, 4);
-  return offset ? (obj || new NS8755221360535654258.NamespaceA.NamespaceB.TableInNestedNS()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
-};
-
-/**
- * @returns NamespaceA.NamespaceB.EnumInNestedNS
- */
-fooEnum():NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS {
-  var offset = this.bb!.__offset(this.bb_pos, 6);
-  return offset ? /**  */ (this.bb!.readInt8(this.bb_pos + offset)) : NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS.A;
-};
-
-/**
- * @param NamespaceA.NamespaceB.EnumInNestedNS value
- * @returns boolean
- */
-mutate_foo_enum(value:NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS):boolean {
-  var offset = this.bb!.__offset(this.bb_pos, 6);
-
-  if (offset === 0) {
-    return false;
-  }
-
-  this.bb!.writeInt8(this.bb_pos + offset, value);
-  return true;
-};
-
-/**
- * @param NamespaceA.NamespaceB.StructInNestedNS= obj
- * @returns NamespaceA.NamespaceB.StructInNestedNS|null
- */
-fooStruct(obj?:NS8755221360535654258.NamespaceA.NamespaceB.StructInNestedNS):NS8755221360535654258.NamespaceA.NamespaceB.StructInNestedNS|null {
-  var offset = this.bb!.__offset(this.bb_pos, 8);
-  return offset ? (obj || new NS8755221360535654258.NamespaceA.NamespaceB.StructInNestedNS()).__init(this.bb_pos + offset, this.bb!) : null;
-};
-
-/**
- * @returns string
- */
-static getFullyQualifiedName():string {
-  return 'NamespaceA.TableInFirstNS';
-}
-
-/**
- * @param flatbuffers.Builder builder
- */
-static startTableInFirstNS(builder:flatbuffers.Builder) {
-  builder.startObject(3);
-};
-
-/**
- * @param flatbuffers.Builder builder
- * @param flatbuffers.Offset fooTableOffset
- */
-static addFooTable(builder:flatbuffers.Builder, fooTableOffset:flatbuffers.Offset) {
-  builder.addFieldOffset(0, fooTableOffset, 0);
-};
-
-/**
- * @param flatbuffers.Builder builder
- * @param NamespaceA.NamespaceB.EnumInNestedNS fooEnum
- */
-static addFooEnum(builder:flatbuffers.Builder, fooEnum:NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS) {
-  builder.addFieldInt8(1, fooEnum, NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS.A);
-};
-
-/**
- * @param flatbuffers.Builder builder
- * @param flatbuffers.Offset fooStructOffset
- */
-static addFooStruct(builder:flatbuffers.Builder, fooStructOffset:flatbuffers.Offset) {
-  builder.addFieldStruct(2, fooStructOffset, 0);
-};
-
-/**
- * @param flatbuffers.Builder builder
- * @returns flatbuffers.Offset
- */
-static endTableInFirstNS(builder:flatbuffers.Builder):flatbuffers.Offset {
-  var offset = builder.endObject();
-  return offset;
-};
-
-
-/**
- * @returns TableInFirstNST
- */
-unpack(): TableInFirstNST {
-  return new TableInFirstNST(
-    (this.fooTable() !== null ? this.fooTable()!.unpack() : null),
-    this.fooEnum(),
-    (this.fooStruct() !== null ? this.fooStruct()!.unpack() : null)
-  );
-};
-
-/**
- * @param TableInFirstNST _o
- */
-unpackTo(_o: TableInFirstNST): void {
-  _o.fooTable = (this.fooTable() !== null ? this.fooTable()!.unpack() : null);
-  _o.fooEnum = this.fooEnum();
-  _o.fooStruct = (this.fooStruct() !== null ? this.fooStruct()!.unpack() : null);
-};
-}
-
-export class TableInFirstNST {
-/**
- * @constructor
- * @param NS8755221360535654258.NamespaceA.NamespaceB.TableInNestedNST|null fooTable
- * @param NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS fooEnum
- * @param NS8755221360535654258.NamespaceA.NamespaceB.StructInNestedNST|null fooStruct
- */
-constructor(
-  public fooTable: NS8755221360535654258.NamespaceA.NamespaceB.TableInNestedNST|null = null,
-  public fooEnum: NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS = NS8755221360535654258.NamespaceA.NamespaceB.EnumInNestedNS.A,
-  public fooStruct: NS8755221360535654258.NamespaceA.NamespaceB.StructInNestedNST|null = null
-){};
-
-/**
- * @param flatbuffers.Builder builder
- * @returns flatbuffers.Offset
- */
-pack(builder:flatbuffers.Builder): flatbuffers.Offset {
-  NamespaceA.TableInFirstNS.start(builder);
-  NamespaceA.TableInFirstNS.addFooTable(builder, (this.fooTable !== null ? this.fooTable!.pack(builder) : 0));
-  NamespaceA.TableInFirstNS.addFooEnum(builder, this.fooEnum);
-  NamespaceA.TableInFirstNS.addFooStruct(builder, (this.fooStruct !== null ? this.fooStruct!.pack(builder) : 0));
-
-  return NamespaceA.TableInFirstNS.end(builder);
-};
-}
-}
-/**
- * @constructor
- */
-export namespace NamespaceC{
-export class TableInC {
-  bb: flatbuffers.ByteBuffer|null = null;
-
-  bb_pos:number = 0;
-/**
- * @param number i
- * @param flatbuffers.ByteBuffer bb
- * @returns TableInC
- */
-__init(i:number, bb:flatbuffers.ByteBuffer):TableInC {
-  this.bb_pos = i;
-  this.bb = bb;
-  return this;
-};
-
-/**
- * @param flatbuffers.ByteBuffer bb
- * @param TableInC= obj
- * @returns TableInC
- */
-static getRootAsTableInC(bb:flatbuffers.ByteBuffer, obj?:TableInC):TableInC {
-  return (obj || new TableInC()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param flatbuffers.ByteBuffer bb
- * @param TableInC= obj
- * @returns TableInC
- */
-static getSizePrefixedRootAsTableInC(bb:flatbuffers.ByteBuffer, obj?:TableInC):TableInC {
-  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
-  return (obj || new TableInC()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param NamespaceA.TableInFirstNS= obj
- * @returns NamespaceA.TableInFirstNS|null
- */
-referToA1(obj?:NamespaceA.TableInFirstNS):NamespaceA.TableInFirstNS|null {
-  var offset = this.bb!.__offset(this.bb_pos, 4);
-  return offset ? (obj || new NamespaceA.TableInFirstNS()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
-};
-
-/**
- * @param NamespaceA.SecondTableInA= obj
- * @returns NamespaceA.SecondTableInA|null
- */
-referToA2(obj?:NamespaceA.SecondTableInA):NamespaceA.SecondTableInA|null {
-  var offset = this.bb!.__offset(this.bb_pos, 6);
-  return offset ? (obj || new NamespaceA.SecondTableInA()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
-};
-
-/**
- * @returns string
- */
-static getFullyQualifiedName():string {
-  return 'NamespaceC.TableInC';
-}
-
-/**
- * @param flatbuffers.Builder builder
- */
-static startTableInC(builder:flatbuffers.Builder) {
-  builder.startObject(2);
-};
-
-/**
- * @param flatbuffers.Builder builder
- * @param flatbuffers.Offset referToA1Offset
- */
-static addReferToA1(builder:flatbuffers.Builder, referToA1Offset:flatbuffers.Offset) {
-  builder.addFieldOffset(0, referToA1Offset, 0);
-};
-
-/**
- * @param flatbuffers.Builder builder
- * @param flatbuffers.Offset referToA2Offset
- */
-static addReferToA2(builder:flatbuffers.Builder, referToA2Offset:flatbuffers.Offset) {
-  builder.addFieldOffset(1, referToA2Offset, 0);
-};
-
-/**
- * @param flatbuffers.Builder builder
- * @returns flatbuffers.Offset
- */
-static endTableInC(builder:flatbuffers.Builder):flatbuffers.Offset {
-  var offset = builder.endObject();
-  return offset;
-};
-
-
-/**
- * @returns TableInCT
- */
-unpack(): TableInCT {
-  return new TableInCT(
-    (this.referToA1() !== null ? this.referToA1()!.unpack() : null),
-    (this.referToA2() !== null ? this.referToA2()!.unpack() : null)
-  );
-};
-
-/**
- * @param TableInCT _o
- */
-unpackTo(_o: TableInCT): void {
-  _o.referToA1 = (this.referToA1() !== null ? this.referToA1()!.unpack() : null);
-  _o.referToA2 = (this.referToA2() !== null ? this.referToA2()!.unpack() : null);
-};
-}
-
-export class TableInCT {
-/**
- * @constructor
- * @param NamespaceA.TableInFirstNST|null referToA1
- * @param NamespaceA.SecondTableInAT|null referToA2
- */
-constructor(
-  public referToA1: NamespaceA.TableInFirstNST|null = null,
-  public referToA2: NamespaceA.SecondTableInAT|null = null
-){};
-
-/**
- * @param flatbuffers.Builder builder
- * @returns flatbuffers.Offset
- */
-pack(builder:flatbuffers.Builder): flatbuffers.Offset {
-  NamespaceC.TableInC.start(builder);
-  NamespaceC.TableInC.addReferToA1(builder, (this.referToA1 !== null ? this.referToA1!.pack(builder) : 0));
-  NamespaceC.TableInC.addReferToA2(builder, (this.referToA2 !== null ? this.referToA2!.pack(builder) : 0));
-
-  return NamespaceC.TableInC.end(builder);
-};
-}
-}
-/**
- * @constructor
- */
-export namespace NamespaceA{
-export class SecondTableInA {
-  bb: flatbuffers.ByteBuffer|null = null;
-
-  bb_pos:number = 0;
-/**
- * @param number i
- * @param flatbuffers.ByteBuffer bb
- * @returns SecondTableInA
- */
-__init(i:number, bb:flatbuffers.ByteBuffer):SecondTableInA {
-  this.bb_pos = i;
-  this.bb = bb;
-  return this;
-};
-
-/**
- * @param flatbuffers.ByteBuffer bb
- * @param SecondTableInA= obj
- * @returns SecondTableInA
- */
-static getRootAsSecondTableInA(bb:flatbuffers.ByteBuffer, obj?:SecondTableInA):SecondTableInA {
-  return (obj || new SecondTableInA()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param flatbuffers.ByteBuffer bb
- * @param SecondTableInA= obj
- * @returns SecondTableInA
- */
-static getSizePrefixedRootAsSecondTableInA(bb:flatbuffers.ByteBuffer, obj?:SecondTableInA):SecondTableInA {
-  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
-  return (obj || new SecondTableInA()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
-};
-
-/**
- * @param NamespaceC.TableInC= obj
- * @returns NamespaceC.TableInC|null
- */
-referToC(obj?:NamespaceC.TableInC):NamespaceC.TableInC|null {
-  var offset = this.bb!.__offset(this.bb_pos, 4);
-  return offset ? (obj || new NamespaceC.TableInC()).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null;
-};
-
-/**
- * @returns string
- */
-static getFullyQualifiedName():string {
-  return 'NamespaceA.SecondTableInA';
-}
-
-/**
- * @param flatbuffers.Builder builder
- */
-static startSecondTableInA(builder:flatbuffers.Builder) {
-  builder.startObject(1);
-};
-
-/**
- * @param flatbuffers.Builder builder
- * @param flatbuffers.Offset referToCOffset
- */
-static addReferToC(builder:flatbuffers.Builder, referToCOffset:flatbuffers.Offset) {
-  builder.addFieldOffset(0, referToCOffset, 0);
-};
-
-/**
- * @param flatbuffers.Builder builder
- * @returns flatbuffers.Offset
- */
-static endSecondTableInA(builder:flatbuffers.Builder):flatbuffers.Offset {
-  var offset = builder.endObject();
-  return offset;
-};
-
-static createSecondTableInA(builder:flatbuffers.Builder, referToCOffset:flatbuffers.Offset):flatbuffers.Offset {
-  SecondTableInA.startSecondTableInA(builder);
-  SecondTableInA.addReferToC(builder, referToCOffset);
-  return SecondTableInA.endSecondTableInA(builder);
-}
-
-/**
- * @returns SecondTableInAT
- */
-unpack(): SecondTableInAT {
-  return new SecondTableInAT(
-    (this.referToC() !== null ? this.referToC()!.unpack() : null)
-  );
-};
-
-/**
- * @param SecondTableInAT _o
- */
-unpackTo(_o: SecondTableInAT): void {
-  _o.referToC = (this.referToC() !== null ? this.referToC()!.unpack() : null);
-};
-}
-
-export class SecondTableInAT {
-/**
- * @constructor
- * @param NamespaceC.TableInCT|null referToC
- */
-constructor(
-  public referToC: NamespaceC.TableInCT|null = null
-){};
-
-/**
- * @param flatbuffers.Builder builder
- * @returns flatbuffers.Offset
- */
-pack(builder:flatbuffers.Builder): flatbuffers.Offset {
-  return NamespaceA.SecondTableInA.createSecondTableInA(builder,
-    (this.referToC !== null ? this.referToC!.pack(builder) : 0)
-  );
-};
-}
-}
diff --git a/tests/namespace_test/namespace_test2_namespace_a_generated.dart b/tests/namespace_test/namespace_test2_namespace_a_generated.dart
index e10ad4b..070cb5f 100644
--- a/tests/namespace_test/namespace_test2_namespace_a_generated.dart
+++ b/tests/namespace_test/namespace_test2_namespace_a_generated.dart
@@ -1,5 +1,5 @@
 // automatically generated by the FlatBuffers compiler, do not modify
-// ignore_for_file: unused_import, unused_field, unused_local_variable
+// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
 
 library namespace_a;
 
@@ -11,22 +11,76 @@
 class TableInFirstNS {
   TableInFirstNS._(this._bc, this._bcOffset);
   factory TableInFirstNS(List<int> bytes) {
-    fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes);
+    final rootRef = fb.BufferContext.fromBytes(bytes);
     return reader.read(rootRef, 0);
   }
 
-  static const fb.Reader<TableInFirstNS> reader = const _TableInFirstNSReader();
+  static const fb.Reader<TableInFirstNS> reader = _TableInFirstNSReader();
 
   final fb.BufferContext _bc;
   final int _bcOffset;
 
-  namespace_a_namespace_b.TableInNestedNS get fooTable => namespace_a_namespace_b.TableInNestedNS.reader.vTableGet(_bc, _bcOffset, 4, null);
-  EnumInNestedNS get fooEnum => new EnumInNestedNS.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 6, 0));
-  namespace_a_namespace_b.StructInNestedNS get fooStruct => namespace_a_namespace_b.StructInNestedNS.reader.vTableGet(_bc, _bcOffset, 8, null);
+  namespace_a_namespace_b.TableInNestedNS? get fooTable => namespace_a_namespace_b.TableInNestedNS.reader.vTableGetNullable(_bc, _bcOffset, 4);
+  EnumInNestedNS get fooEnum => EnumInNestedNS.fromValue(const fb.Int8Reader().vTableGet(_bc, _bcOffset, 6, 0));
+  UnionInNestedNSTypeId? get fooUnionType => UnionInNestedNSTypeId._createOrNull(const fb.Uint8Reader().vTableGetNullable(_bc, _bcOffset, 8));
+  dynamic get fooUnion {
+    switch (fooUnionType?.value) {
+      case 1: return TableInNestedNS.reader.vTableGetNullable(_bc, _bcOffset, 10);
+      default: return null;
+    }
+  }
+  namespace_a_namespace_b.StructInNestedNS? get fooStruct => namespace_a_namespace_b.StructInNestedNS.reader.vTableGetNullable(_bc, _bcOffset, 12);
 
   @override
   String toString() {
-    return 'TableInFirstNS{fooTable: $fooTable, fooEnum: $fooEnum, fooStruct: $fooStruct}';
+    return 'TableInFirstNS{fooTable: $fooTable, fooEnum: $fooEnum, fooUnionType: $fooUnionType, fooUnion: $fooUnion, fooStruct: $fooStruct}';
+  }
+
+  TableInFirstNST unpack() => TableInFirstNST(
+      fooTable: fooTable?.unpack(),
+      fooEnum: fooEnum,
+      fooUnionType: fooUnionType,
+      fooUnion: fooUnion,
+      fooStruct: fooStruct?.unpack());
+
+  static int pack(fb.Builder fbBuilder, TableInFirstNST? object) {
+    if (object == null) return 0;
+    return object.pack(fbBuilder);
+  }
+}
+
+class TableInFirstNST implements fb.Packable {
+  namespace_a_namespace_b.TableInNestedNST? fooTable;
+  EnumInNestedNS fooEnum;
+  UnionInNestedNSTypeId? fooUnionType;
+  dynamic fooUnion;
+  namespace_a_namespace_b.StructInNestedNST? fooStruct;
+
+  TableInFirstNST({
+      this.fooTable,
+      this.fooEnum = EnumInNestedNS.A,
+      this.fooUnionType,
+      this.fooUnion,
+      this.fooStruct});
+
+  @override
+  int pack(fb.Builder fbBuilder) {
+    final int? fooTableOffset = fooTable?.pack(fbBuilder);
+    final int? fooUnionOffset = fooUnion?.pack(fbBuilder);
+    fbBuilder.startTable(5);
+    fbBuilder.addOffset(0, fooTableOffset);
+    fbBuilder.addInt8(1, fooEnum.value);
+    fbBuilder.addUint8(2, fooUnionType?.value);
+    fbBuilder.addOffset(3, fooUnionOffset);
+    if (fooStruct != null) {
+      fbBuilder.addStruct(4, fooStruct!.pack(fbBuilder));
+    }
+    return fbBuilder.endTable();
+  }
+
+  @override
+  String toString() {
+    return 'TableInFirstNST{fooTable: $fooTable, fooEnum: $fooEnum, fooUnionType: $fooUnionType, fooUnion: $fooUnion, fooStruct: $fooStruct}';
   }
 }
 
@@ -35,30 +89,36 @@
 
   @override
   TableInFirstNS createObject(fb.BufferContext bc, int offset) => 
-    new TableInFirstNS._(bc, offset);
+    TableInFirstNS._(bc, offset);
 }
 
 class TableInFirstNSBuilder {
-  TableInFirstNSBuilder(this.fbBuilder) {
-    assert(fbBuilder != null);
-  }
+  TableInFirstNSBuilder(this.fbBuilder);
 
   final fb.Builder fbBuilder;
 
   void begin() {
-    fbBuilder.startTable();
+    fbBuilder.startTable(5);
   }
 
-  int addFooTableOffset(int offset) {
+  int addFooTableOffset(int? offset) {
     fbBuilder.addOffset(0, offset);
     return fbBuilder.offset;
   }
-  int addFooEnum(EnumInNestedNS fooEnum) {
+  int addFooEnum(EnumInNestedNS? fooEnum) {
     fbBuilder.addInt8(1, fooEnum?.value);
     return fbBuilder.offset;
   }
+  int addFooUnionType(UnionInNestedNSTypeId? fooUnionType) {
+    fbBuilder.addUint8(2, fooUnionType?.value);
+    return fbBuilder.offset;
+  }
+  int addFooUnionOffset(int? offset) {
+    fbBuilder.addOffset(3, offset);
+    return fbBuilder.offset;
+  }
   int addFooStruct(int offset) {
-    fbBuilder.addStruct(2, offset);
+    fbBuilder.addStruct(4, offset);
     return fbBuilder.offset;
   }
 
@@ -68,63 +128,95 @@
 }
 
 class TableInFirstNSObjectBuilder extends fb.ObjectBuilder {
-  final namespace_a_namespace_b.TableInNestedNSObjectBuilder _fooTable;
-  final EnumInNestedNS _fooEnum;
-  final namespace_a_namespace_b.StructInNestedNSObjectBuilder _fooStruct;
+  final namespace_a_namespace_b.TableInNestedNSObjectBuilder? _fooTable;
+  final EnumInNestedNS? _fooEnum;
+  final UnionInNestedNSTypeId? _fooUnionType;
+  final dynamic _fooUnion;
+  final namespace_a_namespace_b.StructInNestedNSObjectBuilder? _fooStruct;
 
   TableInFirstNSObjectBuilder({
-    namespace_a_namespace_b.TableInNestedNSObjectBuilder fooTable,
-    EnumInNestedNS fooEnum,
-    namespace_a_namespace_b.StructInNestedNSObjectBuilder fooStruct,
+    namespace_a_namespace_b.TableInNestedNSObjectBuilder? fooTable,
+    EnumInNestedNS? fooEnum,
+    UnionInNestedNSTypeId? fooUnionType,
+    dynamic fooUnion,
+    namespace_a_namespace_b.StructInNestedNSObjectBuilder? fooStruct,
   })
       : _fooTable = fooTable,
         _fooEnum = fooEnum,
+        _fooUnionType = fooUnionType,
+        _fooUnion = fooUnion,
         _fooStruct = fooStruct;
 
   /// Finish building, and store into the [fbBuilder].
   @override
-  int finish(
-    fb.Builder fbBuilder) {
-    assert(fbBuilder != null);
-    final int fooTableOffset = _fooTable?.getOrCreateOffset(fbBuilder);
-
-    fbBuilder.startTable();
-    if (fooTableOffset != null) {
-      fbBuilder.addOffset(0, fooTableOffset);
-    }
+  int finish(fb.Builder fbBuilder) {
+    final int? fooTableOffset = _fooTable?.getOrCreateOffset(fbBuilder);
+    final int? fooUnionOffset = _fooUnion?.getOrCreateOffset(fbBuilder);
+    fbBuilder.startTable(5);
+    fbBuilder.addOffset(0, fooTableOffset);
     fbBuilder.addInt8(1, _fooEnum?.value);
+    fbBuilder.addUint8(2, _fooUnionType?.value);
+    fbBuilder.addOffset(3, fooUnionOffset);
     if (_fooStruct != null) {
-      fbBuilder.addStruct(2, _fooStruct.finish(fbBuilder));
+      fbBuilder.addStruct(4, _fooStruct!.finish(fbBuilder));
     }
     return fbBuilder.endTable();
   }
 
   /// Convenience method to serialize to byte list.
   @override
-  Uint8List toBytes([String fileIdentifier]) {
-    fb.Builder fbBuilder = new fb.Builder();
-    int offset = finish(fbBuilder);
-    return fbBuilder.finish(offset, fileIdentifier);
+  Uint8List toBytes([String? fileIdentifier]) {
+    final fbBuilder = fb.Builder(deduplicateTables: false);
+    fbBuilder.finish(finish(fbBuilder), fileIdentifier);
+    return fbBuilder.buffer;
   }
 }
 class SecondTableInA {
   SecondTableInA._(this._bc, this._bcOffset);
   factory SecondTableInA(List<int> bytes) {
-    fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes);
+    final rootRef = fb.BufferContext.fromBytes(bytes);
     return reader.read(rootRef, 0);
   }
 
-  static const fb.Reader<SecondTableInA> reader = const _SecondTableInAReader();
+  static const fb.Reader<SecondTableInA> reader = _SecondTableInAReader();
 
   final fb.BufferContext _bc;
   final int _bcOffset;
 
-  namespace_c.TableInC get referToC => namespace_c.TableInC.reader.vTableGet(_bc, _bcOffset, 4, null);
+  namespace_c.TableInC? get referToC => namespace_c.TableInC.reader.vTableGetNullable(_bc, _bcOffset, 4);
 
   @override
   String toString() {
     return 'SecondTableInA{referToC: $referToC}';
   }
+
+  SecondTableInAT unpack() => SecondTableInAT(
+      referToC: referToC?.unpack());
+
+  static int pack(fb.Builder fbBuilder, SecondTableInAT? object) {
+    if (object == null) return 0;
+    return object.pack(fbBuilder);
+  }
+}
+
+class SecondTableInAT implements fb.Packable {
+  namespace_c.TableInCT? referToC;
+
+  SecondTableInAT({
+      this.referToC});
+
+  @override
+  int pack(fb.Builder fbBuilder) {
+    final int? referToCOffset = referToC?.pack(fbBuilder);
+    fbBuilder.startTable(1);
+    fbBuilder.addOffset(0, referToCOffset);
+    return fbBuilder.endTable();
+  }
+
+  @override
+  String toString() {
+    return 'SecondTableInAT{referToC: $referToC}';
+  }
 }
 
 class _SecondTableInAReader extends fb.TableReader<SecondTableInA> {
@@ -132,21 +224,19 @@
 
   @override
   SecondTableInA createObject(fb.BufferContext bc, int offset) => 
-    new SecondTableInA._(bc, offset);
+    SecondTableInA._(bc, offset);
 }
 
 class SecondTableInABuilder {
-  SecondTableInABuilder(this.fbBuilder) {
-    assert(fbBuilder != null);
-  }
+  SecondTableInABuilder(this.fbBuilder);
 
   final fb.Builder fbBuilder;
 
   void begin() {
-    fbBuilder.startTable();
+    fbBuilder.startTable(1);
   }
 
-  int addReferToCOffset(int offset) {
+  int addReferToCOffset(int? offset) {
     fbBuilder.addOffset(0, offset);
     return fbBuilder.offset;
   }
@@ -157,32 +247,27 @@
 }
 
 class SecondTableInAObjectBuilder extends fb.ObjectBuilder {
-  final namespace_c.TableInCObjectBuilder _referToC;
+  final namespace_c.TableInCObjectBuilder? _referToC;
 
   SecondTableInAObjectBuilder({
-    namespace_c.TableInCObjectBuilder referToC,
+    namespace_c.TableInCObjectBuilder? referToC,
   })
       : _referToC = referToC;
 
   /// Finish building, and store into the [fbBuilder].
   @override
-  int finish(
-    fb.Builder fbBuilder) {
-    assert(fbBuilder != null);
-    final int referToCOffset = _referToC?.getOrCreateOffset(fbBuilder);
-
-    fbBuilder.startTable();
-    if (referToCOffset != null) {
-      fbBuilder.addOffset(0, referToCOffset);
-    }
+  int finish(fb.Builder fbBuilder) {
+    final int? referToCOffset = _referToC?.getOrCreateOffset(fbBuilder);
+    fbBuilder.startTable(1);
+    fbBuilder.addOffset(0, referToCOffset);
     return fbBuilder.endTable();
   }
 
   /// Convenience method to serialize to byte list.
   @override
-  Uint8List toBytes([String fileIdentifier]) {
-    fb.Builder fbBuilder = new fb.Builder();
-    int offset = finish(fbBuilder);
-    return fbBuilder.finish(offset, fileIdentifier);
+  Uint8List toBytes([String? fileIdentifier]) {
+    final fbBuilder = fb.Builder(deduplicateTables: false);
+    fbBuilder.finish(finish(fbBuilder), fileIdentifier);
+    return fbBuilder.buffer;
   }
 }
diff --git a/tests/namespace_test/namespace_test2_namespace_c_generated.dart b/tests/namespace_test/namespace_test2_namespace_c_generated.dart
index edb6ffc..1c30bb4 100644
--- a/tests/namespace_test/namespace_test2_namespace_c_generated.dart
+++ b/tests/namespace_test/namespace_test2_namespace_c_generated.dart
@@ -1,5 +1,5 @@
 // automatically generated by the FlatBuffers compiler, do not modify
-// ignore_for_file: unused_import, unused_field, unused_local_variable
+// ignore_for_file: unused_import, unused_field, unused_element, unused_local_variable
 
 library namespace_c;
 
@@ -11,22 +11,55 @@
 class TableInC {
   TableInC._(this._bc, this._bcOffset);
   factory TableInC(List<int> bytes) {
-    fb.BufferContext rootRef = new fb.BufferContext.fromBytes(bytes);
+    final rootRef = fb.BufferContext.fromBytes(bytes);
     return reader.read(rootRef, 0);
   }
 
-  static const fb.Reader<TableInC> reader = const _TableInCReader();
+  static const fb.Reader<TableInC> reader = _TableInCReader();
 
   final fb.BufferContext _bc;
   final int _bcOffset;
 
-  namespace_a.TableInFirstNS get referToA1 => namespace_a.TableInFirstNS.reader.vTableGet(_bc, _bcOffset, 4, null);
-  namespace_a.SecondTableInA get referToA2 => namespace_a.SecondTableInA.reader.vTableGet(_bc, _bcOffset, 6, null);
+  namespace_a.TableInFirstNS? get referToA1 => namespace_a.TableInFirstNS.reader.vTableGetNullable(_bc, _bcOffset, 4);
+  namespace_a.SecondTableInA? get referToA2 => namespace_a.SecondTableInA.reader.vTableGetNullable(_bc, _bcOffset, 6);
 
   @override
   String toString() {
     return 'TableInC{referToA1: $referToA1, referToA2: $referToA2}';
   }
+
+  TableInCT unpack() => TableInCT(
+      referToA1: referToA1?.unpack(),
+      referToA2: referToA2?.unpack());
+
+  static int pack(fb.Builder fbBuilder, TableInCT? object) {
+    if (object == null) return 0;
+    return object.pack(fbBuilder);
+  }
+}
+
+class TableInCT implements fb.Packable {
+  namespace_a.TableInFirstNST? referToA1;
+  namespace_a.SecondTableInAT? referToA2;
+
+  TableInCT({
+      this.referToA1,
+      this.referToA2});
+
+  @override
+  int pack(fb.Builder fbBuilder) {
+    final int? referToA1Offset = referToA1?.pack(fbBuilder);
+    final int? referToA2Offset = referToA2?.pack(fbBuilder);
+    fbBuilder.startTable(2);
+    fbBuilder.addOffset(0, referToA1Offset);
+    fbBuilder.addOffset(1, referToA2Offset);
+    return fbBuilder.endTable();
+  }
+
+  @override
+  String toString() {
+    return 'TableInCT{referToA1: $referToA1, referToA2: $referToA2}';
+  }
 }
 
 class _TableInCReader extends fb.TableReader<TableInC> {
@@ -34,25 +67,23 @@
 
   @override
   TableInC createObject(fb.BufferContext bc, int offset) => 
-    new TableInC._(bc, offset);
+    TableInC._(bc, offset);
 }
 
 class TableInCBuilder {
-  TableInCBuilder(this.fbBuilder) {
-    assert(fbBuilder != null);
-  }
+  TableInCBuilder(this.fbBuilder);
 
   final fb.Builder fbBuilder;
 
   void begin() {
-    fbBuilder.startTable();
+    fbBuilder.startTable(2);
   }
 
-  int addReferToA1Offset(int offset) {
+  int addReferToA1Offset(int? offset) {
     fbBuilder.addOffset(0, offset);
     return fbBuilder.offset;
   }
-  int addReferToA2Offset(int offset) {
+  int addReferToA2Offset(int? offset) {
     fbBuilder.addOffset(1, offset);
     return fbBuilder.offset;
   }
@@ -63,39 +94,32 @@
 }
 
 class TableInCObjectBuilder extends fb.ObjectBuilder {
-  final namespace_a.TableInFirstNSObjectBuilder _referToA1;
-  final namespace_a.SecondTableInAObjectBuilder _referToA2;
+  final namespace_a.TableInFirstNSObjectBuilder? _referToA1;
+  final namespace_a.SecondTableInAObjectBuilder? _referToA2;
 
   TableInCObjectBuilder({
-    namespace_a.TableInFirstNSObjectBuilder referToA1,
-    namespace_a.SecondTableInAObjectBuilder referToA2,
+    namespace_a.TableInFirstNSObjectBuilder? referToA1,
+    namespace_a.SecondTableInAObjectBuilder? referToA2,
   })
       : _referToA1 = referToA1,
         _referToA2 = referToA2;
 
   /// Finish building, and store into the [fbBuilder].
   @override
-  int finish(
-    fb.Builder fbBuilder) {
-    assert(fbBuilder != null);
-    final int referToA1Offset = _referToA1?.getOrCreateOffset(fbBuilder);
-    final int referToA2Offset = _referToA2?.getOrCreateOffset(fbBuilder);
-
-    fbBuilder.startTable();
-    if (referToA1Offset != null) {
-      fbBuilder.addOffset(0, referToA1Offset);
-    }
-    if (referToA2Offset != null) {
-      fbBuilder.addOffset(1, referToA2Offset);
-    }
+  int finish(fb.Builder fbBuilder) {
+    final int? referToA1Offset = _referToA1?.getOrCreateOffset(fbBuilder);
+    final int? referToA2Offset = _referToA2?.getOrCreateOffset(fbBuilder);
+    fbBuilder.startTable(2);
+    fbBuilder.addOffset(0, referToA1Offset);
+    fbBuilder.addOffset(1, referToA2Offset);
     return fbBuilder.endTable();
   }
 
   /// Convenience method to serialize to byte list.
   @override
-  Uint8List toBytes([String fileIdentifier]) {
-    fb.Builder fbBuilder = new fb.Builder();
-    int offset = finish(fbBuilder);
-    return fbBuilder.finish(offset, fileIdentifier);
+  Uint8List toBytes([String? fileIdentifier]) {
+    final fbBuilder = fb.Builder(deduplicateTables: false);
+    fbBuilder.finish(finish(fbBuilder), fileIdentifier);
+    return fbBuilder.buffer;
   }
 }