本文整理汇总了Java中com.bluelinelabs.logansquare.annotation.JsonField类的典型用法代码示例。如果您正苦于以下问题:Java JsonField类的具体用法?Java JsonField怎么用?Java JsonField使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonField类属于com.bluelinelabs.logansquare.annotation包,在下文中一共展示了JsonField类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isJsonFieldFieldAnnotationValid
import com.bluelinelabs.logansquare.annotation.JsonField; //导入依赖的package包/类
private boolean isJsonFieldFieldAnnotationValid(Element element, Elements elements) {
TypeElement enclosingElement = (TypeElement) element.getEnclosingElement();
Annotation objectAnnotation = enclosingElement.getAnnotation(JsonObject.class);
if (objectAnnotation == null) {
error(enclosingElement, "%s: @%s fields can only be in classes annotated with @%s.", enclosingElement.getQualifiedName(), JsonField.class.getSimpleName(), JsonObject.class.getSimpleName());
return false;
}
if (element.getModifiers().contains(PRIVATE) && (TextUtils.isEmpty(JsonFieldHolder.getGetter(element, elements)) || TextUtils.isEmpty(JsonFieldHolder.getSetter(element, elements)))) {
error(element, "@%s annotation can only be used on private fields if both getter and setter are present.", JsonField.class.getSimpleName());
return false;
}
return true;
}
示例2: findAndParseObjects
import com.bluelinelabs.logansquare.annotation.JsonField; //导入依赖的package包/类
@Override
public void findAndParseObjects(RoundEnvironment env, Map<String, JsonObjectHolder> jsonObjectMap, Elements elements, Types types) {
for (Element element : env.getElementsAnnotatedWith(JsonField.class)) {
try {
processJsonFieldAnnotation(element, jsonObjectMap, elements, types);
} catch (Exception e) {
StringWriter stackTrace = new StringWriter();
e.printStackTrace(new PrintWriter(stackTrace));
error(element, "Unable to generate injector for %s. Stack trace incoming:\n%s", JsonField.class, stackTrace.toString());
}
}
}
示例3: processJsonFieldAnnotation
import com.bluelinelabs.logansquare.annotation.JsonField; //导入依赖的package包/类
private void processJsonFieldAnnotation(Element element, Map<String, JsonObjectHolder> jsonObjectMap, Elements elements, Types types) {
if (!isJsonFieldFieldAnnotationValid(element, elements)) {
return;
}
TypeElement enclosingElement = (TypeElement)element.getEnclosingElement();
JsonObjectHolder objectHolder = jsonObjectMap.get(TypeUtils.getInjectedFQCN(enclosingElement, elements));
JsonFieldHolder fieldHolder = objectHolder.fieldMap.get(element.getSimpleName().toString());
if (fieldHolder == null) {
fieldHolder = new JsonFieldHolder();
objectHolder.fieldMap.put(element.getSimpleName().toString(), fieldHolder);
}
JsonField annotation = element.getAnnotation(JsonField.class);
TypeMirror typeConverterType;
try {
typeConverterType = mProcessingEnv.getElementUtils().getTypeElement(annotation.typeConverter().getCanonicalName()).asType();
} catch (MirroredTypeException mte) {
typeConverterType = mte.getTypeMirror();
}
String[] fieldName = annotation.name();
JsonIgnore ignoreAnnotation = element.getAnnotation(JsonIgnore.class);
boolean shouldParse = ignoreAnnotation == null || ignoreAnnotation.ignorePolicy() == IgnorePolicy.SERIALIZE_ONLY;
boolean shouldSerialize = ignoreAnnotation == null || ignoreAnnotation.ignorePolicy() == IgnorePolicy.PARSE_ONLY;
String error = fieldHolder.fill(element, elements, types, fieldName, typeConverterType, objectHolder, shouldParse, shouldSerialize);
if (!TextUtils.isEmpty(error)) {
error(element, error);
}
ensureTypeConverterClassValid(typeConverterType, elements, types);
}
示例4: getAnnotation
import com.bluelinelabs.logansquare.annotation.JsonField; //导入依赖的package包/类
@Override
public Class getAnnotation() {
return JsonField.class;
}