private boolean setupManyNesting ( ) { BeanAttributeInformation parentAttribute = null ; BeanAttributeInformation idAttribute = null ; BeanInformation beanInformation = BeanInformation . get ( idField . getType ( ) ) ; for ( String attributeName : beanInformation . getAttributeNames ( ) ) { BeanAttributeInformation attribute = beanInformation . getAttribute ( attributeName ) ; if ( attribute . getAnnotation ( JsonApiRelationId . class ) . isPresent ( ) ) { PreconditionUtil . verify ( parentAttribute == null , "nested identifiers can only have a single @JsonApiRelationId annotated field, got multiple for %s" , beanInformation . getImplementationClass ( ) ) ; parentAttribute = attribute ; } else if ( attribute . getAnnotation ( JsonApiId . class ) . isPresent ( ) ) { PreconditionUtil . verify ( idAttribute == null , "nested identifiers can only one attribute being annotated with @JsonApiId, got multiple for %s" , beanInformation . getImplementationClass ( ) ) ; idAttribute = attribute ; } } if ( parentAttribute != null || idAttribute != null ) { if ( ! shouldBeNested ( ) ) { LOGGER . warn ( "add @JsonApiResource(nested=true) to {} to mark it as being nested, in the future automatic discovery based on the id will be removed" , implementationClass ) ; } PreconditionUtil . verify ( idAttribute != null , "nested identifiers must have attribute annotated with @JsonApiId, got none for %s" , beanInformation . getImplementationClass ( ) ) ; PreconditionUtil . verify ( parentAttribute != null , "nested identifiers must have attribute annotated with @JsonApiRelationId, got none for %s" , beanInformation . getImplementationClass ( ) ) ; String relationshipName = parentAttribute . getName ( ) . substring ( 0 , parentAttribute . getName ( ) . length ( ) - 2 ) ; // accessors for nested and parent id, able to deal with both resources and identifiers as parameters this . parentIdAccessor = new NestedIdAccessor ( parentAttribute ) ; this . childIdAccessor = new NestedIdAccessor ( idAttribute ) ; // check whether parentField is duplicated in ID. This can be a valid use case if the nested identifier is considered // an add-on to an existing object. String parentName = parentAttribute . getName ( ) ; Optional < ResourceField > optParentField = relationshipFields . stream ( ) . filter ( it -> it . hasIdField ( ) && it . getIdName ( ) . equals ( parentName ) ) . findFirst ( ) ; if ( optParentField . isPresent ( ) ) { parentField = optParentField . get ( ) ; } else { PreconditionUtil . verify ( parentAttribute . getName ( ) . endsWith ( "Id" ) , "nested identifier must have @JsonApiRelationId field being named with a 'Id' suffix or match in name with a @JsonApiRelationId annotated field on the resource, got %s for %s" , parentAttribute . getName ( ) , beanInformation . getImplementationClass ( ) ) ; parentField = findRelationshipFieldByName ( relationshipName ) ; PreconditionUtil . verify ( parentField != null , "naming of relationship to parent resource and relationship identifier within resource identifier must " + "match, not found for %s of %s" , parentAttribute . getName ( ) , implementationClass ) ; ( ( ResourceFieldImpl ) parentField ) . setIdField ( parentAttribute . getName ( ) , parentAttribute . getImplementationClass ( ) , parentIdAccessor ) ; } return true ; } return false ; }
in the future