All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.norberg.automatter.jackson.AutoMatterAnnotationIntrospector Maven / Gradle / Ivy

package io.norberg.automatter.jackson;

import com.fasterxml.jackson.databind.introspect.Annotated;
import com.fasterxml.jackson.databind.introspect.AnnotatedConstructor;
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.introspect.AnnotatedParameter;
import com.fasterxml.jackson.databind.introspect.NopAnnotationIntrospector;

import io.norberg.automatter.AutoMatter;

class AutoMatterAnnotationIntrospector extends NopAnnotationIntrospector {

  @Override
  public String findImplicitPropertyName(final AnnotatedMember member) {
    final AutoMatter.Field field = member.getAnnotation(AutoMatter.Field.class);
    if (field == null) {
      return null;
    }
    if (member instanceof AnnotatedParameter) {
      return field.value();
    }
    if (member instanceof AnnotatedMethod) {
      return member.getName();
    }
    return null;
  }

  @Override
  public boolean hasCreatorAnnotation(final Annotated a) {
    if (!(a instanceof AnnotatedConstructor)) {
      return false;
    }
    final AnnotatedConstructor ctor = (AnnotatedConstructor) a;
    if (ctor.getParameterCount() == 0) {
      return true;
    }
    final AutoMatter.Field field = ctor.getParameter(0).getAnnotation(AutoMatter.Field.class);
    return field != null;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy