public static Cells getCellFromBson ( BSONObject bsonObject , String tableName ) { Cells cells = tableName != null ? new Cells ( tableName ) : new Cells ( ) ; Map < String , Object > map = bsonObject . toMap ( ) ; Set < Map . Entry < String , Object > > entryBson = map . entrySet ( ) ; for ( Map . Entry < String , Object > entry : entryBson ) { try { if ( List . class . isAssignableFrom ( entry . getValue ( ) . getClass ( ) ) ) { List innerCell = new ArrayList <> ( ) ; for ( Object innerBson : ( List ) entry . getValue ( ) ) { if ( innerBson instanceof DBObject ) { innerCell . add ( getCellFromBson ( ( DBObject ) innerBson , null ) ) ; } else { innerCell . add ( innerBson ) ; } } cells . add ( Cell . create ( entry . getKey ( ) , innerCell ) ) ; } else if ( BSONObject . class . isAssignableFrom ( entry . getValue ( ) . getClass ( ) ) ) { Cells innerCells = getCellFromBson ( ( BSONObject ) entry . getValue ( ) , null ) ; cells . add ( Cell . create ( entry . getKey ( ) , innerCells ) ) ; } else { cells . add ( Cell . create ( entry . getKey ( ) , entry . getValue ( ) ) ) ; } } catch ( IllegalArgumentException e ) { LOG . error ( "impossible to create a java cell from Bson field:" + entry . getKey ( ) + ", type:" + entry . getValue ( ) . getClass ( ) + ", value:" + entry . getValue ( ) ) ; } } return cells ; }
converts from BsonObject to cell class with deep s anotations