Class JsonSetterAnnotationProcessor


  • public class JsonSetterAnnotationProcessor
    extends Object
    This class is responsible for taking a class and determining whether there are any ambiguous setter methods defined. Then also set the JsonSetter annotation onto the correct setter method.

    To determine which is the "correct" setter function we should set the annotation to, we will look up the matching getter and use it's return type and use the setter whose argument matches the getter's return type.

    E.g. Given the below object with multiple setters defined:
     
     class AJsonObject
     {
          void setProperty(List<String>) { ... }
          // @JsonSetter would be added here since String[] is this function's argument which matches the getter's return value
          void setProperty(String[]) { ... }
          void String[] getProperty() { ... }
     }
     
     
    Using the above example object, the JsonSetter annotation would be added to the `setProperty(String[])` method since its input argument of `String[]` matches the return type of the properties' getter method.
    Since:
    4.17
    Author:
    kylegonzalez
    • Constructor Detail

      • JsonSetterAnnotationProcessor

        public JsonSetterAnnotationProcessor​(Class<?> clazz)
                                      throws javassist.NotFoundException
        The constructor which takes the Class that it will introspect with its methods.
        Parameters:
        clazz - the Class to introspect
        Throws:
        javassist.NotFoundException
    • Method Detail

      • main

        public static void main​(String[] args)
                         throws javassist.CannotCompileException,
                                IOException,
                                javassist.NotFoundException
        This program is run during the "process-classes" maven step.

        This program will add the JsonSetter annotation to any of the classes in PACKAGE_NAME package which have multiple ambiguous setters defined so that the model object can be deserialized from json correctly.

        Throws:
        javassist.CannotCompileException
        IOException
        javassist.NotFoundException