Class ASMCreatorParameterNameResolver

  • All Implemented Interfaces:
    PropertyNameResolver

    public final class ASMCreatorParameterNameResolver
    extends Object
    implements PropertyNameResolver
    This class uses ASM library to resolve method and constructor parameter names from debug symbols generated during compilation. Most libraries are compiled with debug symbols so in most cases this class will be able to resolve them. It's pretty cool as you do not need to annotate the parameters anymore! However be careful if you decide to use this feature, you must ensure that your software is compiled with debug symbols for production! That's why this feature is disabled by default. To enable it :

     new Genson.Builder().setWithDebugInfoPropertyNameResolver(true).create();
     

    If you enabled this feature, when a class with no debug symbols is encountered no exception will be thrown, if you want you can force exceptions with

     new Genson.Builder().setWithDebugInfoPropertyNameResolver(true)
                    .setThrowExceptionIfNoDebugInfo(true).create();
     
    Author:
    Eugen Cepoi
    • Constructor Detail

      • ASMCreatorParameterNameResolver

        public ASMCreatorParameterNameResolver​(boolean doThrowException)
    • Method Detail

      • read

        protected void read​(Class<?> ofClass)
      • resolve

        public String resolve​(int parameterIdx,
                              Constructor<?> fromConstructor)
        Description copied from interface: PropertyNameResolver
        Resolve the parameter name on position parameterIdx in the constructor fromConstructor.
        Specified by:
        resolve in interface PropertyNameResolver
        Parameters:
        parameterIdx - parameter index
        fromConstructor - the constructor being processed
        Returns:
        the resolved name of the parameter or null
      • resolve

        public String resolve​(Field fromField)
        Description copied from interface: PropertyNameResolver
        Resolve the property name from this field.
        Specified by:
        resolve in interface PropertyNameResolver
        Parameters:
        fromField - - the field to use for name resolution.
        Returns:
        the resolved name or null.
      • resolve

        public String resolve​(Method fromMethod)
        Description copied from interface: PropertyNameResolver
        Resolve the property name from this method.
        Specified by:
        resolve in interface PropertyNameResolver
        Parameters:
        fromMethod - - the method to be used for name resolution.
        Returns:
        the resolved name or null.
      • resolve

        public String resolve​(int parameterIdx,
                              Method fromMethod)
        Description copied from interface: PropertyNameResolver
        Resolve the name of the parameter with parameterIdx as index in fromMethod method.
        Specified by:
        resolve in interface PropertyNameResolver
        Parameters:
        parameterIdx - parameter index
        fromMethod - the method being processed
        Returns:
        the resolved name of the parameter or null