private List < Attachment > deserializeAttachmentList ( JsonParser parser , Map < String , Attachment > attachmentDB ) throws JsonParseException , IOException { List < Attachment > attachments = new ArrayList < Attachment > ( ) ; Attachment currentAttachment = null ; while ( ! JsonToken . END_ARRAY . equals ( parser . nextToken ( ) ) ) { String fieldName = parser . getCurrentName ( ) ; JsonToken token = parser . getCurrentToken ( ) ; if ( JsonToken . START_OBJECT . equals ( token ) ) { currentAttachment = new Attachment ( ) ; } else if ( JsonToken . END_OBJECT . equals ( token ) ) { /* * Issue 4 all attachment points have to be fully defined for * any new monomer */ if ( AttachmentLoader . validateAttachment ( currentAttachment ) ) { currentAttachment . setCapGroupSMILES ( attachmentDB . get ( currentAttachment . getAlternateId ( ) ) . getCapGroupSMILES ( ) ) ; attachments . add ( currentAttachment ) ; } } if ( fieldName != null ) { switch ( fieldName ) { case "id" : parser . nextToken ( ) ; if ( parser . getText ( ) != null ) { currentAttachment . setId ( Integer . parseInt ( parser . getText ( ) ) ) ; } break ; case "alternateId" : parser . nextToken ( ) ; currentAttachment . setAlternateId ( parser . getText ( ) ) ; break ; case "label" : parser . nextToken ( ) ; currentAttachment . setLabel ( parser . getText ( ) ) ; break ; case "capGroupName" : parser . nextToken ( ) ; currentAttachment . setCapGroupName ( parser . getText ( ) ) ; break ; case "capGroupSMILES" : parser . nextToken ( ) ; currentAttachment . setCapGroupSMILES ( parser . getText ( ) ) ; break ; default : break ; } } } return attachments ; }
Private routine to deserialize a JSON containing attachment data . This is done manually to give more freedom regarding data returned by the webservice .