mtedone / podam

PODAM - POjo DAta Mocker
https://mtedone.github.io/podam
MIT License
323 stars 750 forks source link

AttributeStrategies have priority over TypeManufacturers #276

Closed selmanjfb closed 4 years ago

selmanjfb commented 5 years ago

Hello,

Ive implemented my custom StringTypeManufacturerImp like this:

public class CustomStringManufacturer extends StringTypeManufacturerImpl {
    @Override
    public String getType(DataProviderStrategy strategy, AttributeMetadata attributeMetadata,
            Map<String, Type> genericTypesArgumentsMap) {
        String attrName = attributeMetadata.getAttributeName().toLowerCase();
        System.out.println(attrName );
               //some logic based on the name of the attribute.
               return super.getType(strategy, attributeMetadata, genericTypesArgumentsMap);
}

getType() function is not getting called for attributes of type String that are annotated with javax.validation.constraints.Size

@Data // lombok
public class Role {
    @NotNull (message = "Role Name cannot be null") // this annotation not giving me any issues
    @Size(max = 100, message = "Role name must be at most 100 characters")
    private String roleName; 
}

When i remove the @Size annotation CustomStringManufacturer works as expected.

daivanov commented 4 years ago

The problem with this, if we change order of invocation. This will force all TypeManufacturers to implement what currently AttributeStrategies do and will reduce value of AttributeStrategies. While in fact AttributeStrategies are more specific than TypeManufacturers, and in general Podam tries to go from calling more specific strategies over more generic.

Thanks, Daniil