Java Code Examples for com.fasterxml.jackson.databind.introspect.Annotated#getRawType()

The following examples show how to use com.fasterxml.jackson.databind.introspect.Annotated#getRawType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FriendlyIdAnnotationIntrospector.java    From friendly-id with Apache License 2.0 6 votes vote down vote up
@Override
public Object findSerializer(Annotated annotatedMethod) {
	IdFormat annotation = _findAnnotation(annotatedMethod, IdFormat.class);
	if (annotatedMethod.getRawType() == UUID.class) {
		if (annotation != null) {
			switch (annotation.value()) {
				case RAW:
					return UUIDSerializer.class;
				case URL62:
					return FriendlyIdSerializer.class;
			}
		}
		return FriendlyIdSerializer.class;
	} else {
		return null;
	}
}
 
Example 2
Source File: RosettaAnnotationIntrospector.java    From Rosetta with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public JsonSerializer<?> findSerializer(Annotated a) {
  StoredAsJson storedAsJson = a.getAnnotation(StoredAsJson.class);
  RosettaSerialize rosettaSerialize = a.getAnnotation(RosettaSerialize.class);
  if (storedAsJson != null && rosettaSerialize != null) {
    throw new IllegalArgumentException("Cannot have @StoredAsJson as well as @RosettaSerialize annotations on the same entry");
  }
  if (storedAsJson != null) {
    Class<?> type = a.getRawType();
    return storedAsJson.binary() ? new StoredAsJsonBinarySerializer(type) : new StoredAsJsonSerializer(type);
  }

  if (rosettaSerialize != null) {
    Class<? extends JsonSerializer> klass = rosettaSerialize.using();
    if (klass != JsonSerializer.None.class) {
      return ClassUtil.createInstance(
          klass,
          objectMapper.getSerializationConfig().canOverrideAccessModifiers());
    }
  }
  return null;
}
 
Example 3
Source File: HibernateAnnotationIntrospector.java    From onedev with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Object findSerializer(Annotated am) {
	if (am.hasAnnotation(ManyToOne.class)) {
		return new ManyToOneSerializer((Class<AbstractEntity>) am.getRawType());
	} else {
		return super.findDeserializer(am);
	}
}
 
Example 4
Source File: HibernateAnnotationIntrospector.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Object findDeserializer(Annotated am) {
	if (am.hasAnnotation(ManyToOne.class)) {
		return new ManyToOneDeserializer(am.getRawType());
	} else {
		return super.findDeserializer(am);
	}
}
 
Example 5
Source File: FriendlyIdAnnotationIntrospector.java    From friendly-id with Apache License 2.0 5 votes vote down vote up
private Class<?> rawDeserializationType(Annotated a) {
	if (a instanceof AnnotatedMethod) {
		AnnotatedMethod am = (AnnotatedMethod) a;
		if (am.getParameterCount() == 1) {
			return am.getRawParameterType(0);
		}
	}
	return a.getRawType();
}
 
Example 6
Source File: RosettaAnnotationIntrospector.java    From Rosetta with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public JsonDeserializer<?> findDeserializer(Annotated a) {
  StoredAsJson storedAsJson = a.getAnnotation(StoredAsJson.class);
  RosettaDeserialize rosettaDeserialize = a.getAnnotation(RosettaDeserialize.class);
  if (storedAsJson != null && rosettaDeserialize != null) {
    throw new IllegalArgumentException("Cannot have @StoredAsJson as well as @RosettaDeserialize annotations on the same entry");
  }
  if (storedAsJson != null) {
    if (a instanceof AnnotatedMethod) {
      a = getAnnotatedTypeFromAnnotatedMethod((AnnotatedMethod) a);
    }

    String empty = StoredAsJson.NULL.equals(storedAsJson.empty()) ? "null" : storedAsJson.empty();
    return new StoredAsJsonDeserializer(a.getRawType(), getType(a), empty, objectMapper);
  }

  if (rosettaDeserialize != null) {
    Class<? extends JsonDeserializer> klass = rosettaDeserialize.using();
    if (klass != JsonDeserializer.None.class) {
      return ClassUtil.createInstance(
          klass,
          objectMapper.getDeserializationConfig().canOverrideAccessModifiers());
    }
  }

  return null;
}