import json
import jsonschema
import codecs
from dataobjects import DataObject

class DDDEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, DataObject):
            return obj.dumpDict(True)
        else:
            return json.JSONEncoder.default(self, obj)
        
class DDDDecoder:
    def __init__(self,repo,index,factory):
        self.index=index
        self.repo=repo
        self.factory=factory
    def __call__(self, data):
        if data.keys()[0]=='ddd_index':
            return self.index.get(data[data.keys()[0]])
        elif data.keys()[0]=='ddd_hash':
            return self.repo.get(data[data.keys()[0]])
        else:
            # Check if it is a normal dict or a ddd-object
            if 'ddd_type' in data:
                return self.factory.create_by_name(data.pop('ddd_type'),**data)
            else:
                return data

class Handler:
    def __init__(self,repo,index,factory):
        self.validators = {}
        self.decoder = DDDDecoder(repo,index,factory)
                
    def load(self,filename):
        with codecs.open(filename,'r',encoding='utf-8') as fp:
            data = json.load(fp,encoding='utf-8',object_hook=self.decoder)
        return data
    
    def dump(self,data,filename):
        with codecs.open(filename,'w',encoding='utf-8') as fp:
            json.dump(data,fp,indent=4,sort_keys=True,ensure_ascii=False,cls=DDDEncoder)
            
@@ -461,16 +461,161 @@
  data):%0A
+        if 'ddd_type' in data:%0A            return self.factory.create_by_name(data.pop('ddd_type'),**data)%0A        elif len(data.keys())==1:%0A    
         
@@ -650,32 +650,36 @@
 x':%0A            
+ 
+   
 return self.inde
@@ -710,24 +710,28 @@
 %5D%5D)%0A        
+    
 elif data.ke
@@ -755,32 +755,36 @@
 h':%0A            
+  
+  
 return self.repo
@@ -822,192 +822,46 @@
     
-else:%0A            # Check if it is a normal dict or a ddd-object%0A            if 'ddd_type' in data:%0A                return self.factory.create_by_name(data.pop('ddd_type'),**data)%0A    
+    else:%0A                return data%0A
     
@@ -862,36 +862,32 @@
 a%0A        else:%0A
-    
             retu

Support arbitrary dicts (which are not sub-DddObjects) in file-decoder