diff --git a/lib/serializer.js b/lib/serializer.js
index <HASH>..<HASH> 100644
--- a/lib/serializer.js
+++ b/lib/serializer.js
@@ -33,6 +33,7 @@ const  xml2js          = require( 'xml2js' )
 	, OBJECT         = "object"
 	, OBJECTS        = "objects"
 	, VALUE          = "value"
+	, FUNCTION       = 'function'
 	, ARRAY          = 'array'
 	, attempt
 	;
@@ -210,6 +211,12 @@ Serializer = Class({
 	 **/
 	,to_jstree: function( data, name, depth, element){
 		depth = depth == null ? 0 : depth;
+		if(data.toJSON && typeof data.toJSON =='function' ){
+			data = data.toJSON()
+		}
+		if(data.toObject && typeof data.toObject =='function' ){
+			data = data.toObject()
+		}		
 		var data_type = kindOf( data ).toLowerCase();
 
 		switch( data_type ){
@@ -253,6 +260,17 @@ Serializer = Class({
 				}
 				break;
 
+			case FUNCTION:
+				var result = data();
+				element = {
+					_attrs:{
+						type:kindOf( result ).toLowerCase()
+					}
+					,_content: String( result )
+					,_name: name || VALUE
+				}
+				break;
+				
 			default:
 				element = {
 					_attrs:{
account for functions in XML serializer.

it was returning the body of the function, not the result.
which is not so good