下面列出了com.fasterxml.jackson.databind.introspect.Annotated#getRawType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
}
@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;
}
@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);
}
}
@Override
public Object findDeserializer(Annotated am) {
if (am.hasAnnotation(ManyToOne.class)) {
return new ManyToOneDeserializer(am.getRawType());
} else {
return super.findDeserializer(am);
}
}
private Class<?> rawDeserializationType(Annotated a) {
if (a instanceof AnnotatedMethod) {
AnnotatedMethod am = (AnnotatedMethod) a;
if (am.getParameterCount() == 1) {
return am.getRawParameterType(0);
}
}
return a.getRawType();
}
@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;
}