I'm trying to achieve the exact same thing. Did you ever find a solution?
Or is there anyone who is able to do this?
This JSAPI team plans to add this capability in 4.0.
For a JSAIPI 3.x stop gap you can try Cereal (https://github.com/swingley/cereal) if you have a simple map, but it is very incomplete and not actively maintained.