Created
April 16, 2015 10:21
-
-
Save botic/c7fbf88cc84ab96a9561 to your computer and use it in GitHub Desktop.
Objectify Entity to Plain JS Object in Rhino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const OBJECT_CLASS = (new java.lang.Object()).getClass(); | |
| var ofyToObject = exports.ofyToObject = function(ofyObject) { | |
| let obj = {}; | |
| let beanInfo = java.beans.Introspector.getBeanInfo(ofyObject.getClass(), OBJECT_CLASS); | |
| let properties = beanInfo.getPropertyDescriptors(); | |
| for (let i = 0; i < properties.length; i++) { | |
| let pd = properties[i]; | |
| let getter = pd.getReadMethod(); | |
| obj[pd.getName()] = getter.invoke(ofyObject); | |
| } | |
| return obj; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment