@ SuppressWarnings ( "unchecked" ) public Object convertToEntity ( Class entityType , String id , ObjectNode document ) { try { if ( ObjectNode . class . equals ( entityType ) ) { return document ; } Object defaultValue = InMemoryDocumentSessionOperations . getDefaultValue ( entityType ) ; Object entity = defaultValue ; String documentType = _session . getConventions ( ) . getJavaClass ( id , document ) ; if ( documentType != null ) { Class type = Class . forName ( documentType ) ; if ( entityType . isAssignableFrom ( type ) ) { entity = _session . getConventions ( ) . getEntityMapper ( ) . treeToValue ( document , type ) ; } } if ( entity == defaultValue ) { entity = _session . getConventions ( ) . getEntityMapper ( ) . treeToValue ( document , entityType ) ; } if ( id != null ) { _session . getGenerateEntityIdOnTheClient ( ) . trySetIdentity ( entity , id ) ; } return entity ; } catch ( Exception e ) { throw new IllegalStateException ( "Could not convert document " + id + " to entity of type " + entityType . getName ( ) , e ) ; } }
Converts a json object to an entity .