下面列出了怎么用com.google.gson.annotations.Expose的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Internal implementation, normal users should not use it.
*/
public void toMap(HashMap<String, String> map, String prefix) {
this.setParamSimple(map, prefix + "Name", this.Name);
this.setParamSimple(map, prefix + "Description", this.Description);
this.setParamSimple(map, prefix + "Cluster", this.Cluster);
this.setParamSimple(map, prefix + "Model", this.Model);
this.setParamSimple(map, prefix + "RuntimeVersion", this.RuntimeVersion);
this.setParamSimple(map, prefix + "CreateTime", this.CreateTime);
this.setParamSimple(map, prefix + "State", this.State);
this.setParamSimple(map, prefix + "ServingUrl", this.ServingUrl);
this.setParamSimple(map, prefix + "Message", this.Message);
this.setParamSimple(map, prefix + "AppId", this.AppId);
this.setParamSimple(map, prefix + "ServType", this.ServType);
this.setParamSimple(map, prefix + "Expose", this.Expose);
this.setParamSimple(map, prefix + "Replicas", this.Replicas);
this.setParamSimple(map, prefix + "Id", this.Id);
this.setParamSimple(map, prefix + "Uin", this.Uin);
this.setParamSimple(map, prefix + "DelTime", this.DelTime);
}
protected static GsonBuilder createSharedGsonBuilder() {
GsonBuilder builder = new GsonBuilder();
builder.setExclusionStrategies(new ExclusionStrategy() {
@Override
public boolean shouldSkipField(FieldAttributes f) {
Expose expose = f.getAnnotation(Expose.class);
return expose != null && !expose.serialize();
}
@Override
public boolean shouldSkipClass(Class<?> clazz) {
return false;
}
});
setDefaultProperties(builder);
return builder;
}
/**
* Internal implementation, normal users should not use it.
*/
public void toMap(HashMap<String, String> map, String prefix) {
this.setParamSimple(map, prefix + "Name", this.Name);
this.setParamSimple(map, prefix + "Model", this.Model);
this.setParamSimple(map, prefix + "Description", this.Description);
this.setParamSimple(map, prefix + "Cluster", this.Cluster);
this.setParamSimple(map, prefix + "RuntimeVersion", this.RuntimeVersion);
this.setParamSimple(map, prefix + "Replicas", this.Replicas);
this.setParamSimple(map, prefix + "Expose", this.Expose);
this.setParamSimple(map, prefix + "ServType", this.ServType);
this.setParamArraySimple(map, prefix + "RuntimeConf.", this.RuntimeConf);
}
@Override
public FieldSpec.Builder fieldBuilt(ObjectPluginContext objectPluginContext, TypeDeclaration declaration, FieldSpec.Builder incoming, EventType eventType) {
return incoming
.addAnnotation(
AnnotationSpec.builder(SerializedName.class)
.addMember("value", "$S", objectPluginContext.creationResult().getJavaName(EventType.IMPLEMENTATION)).build())
.addAnnotation(AnnotationSpec.builder(Expose.class).build());
}
public boolean excludeField(Field field, boolean serialize) {
if ((this.modifiers & field.getModifiers()) != 0) {
return true;
}
if (this.version != IGNORE_VERSIONS && !isValidVersion((Since) field.getAnnotation(Since.class), (Until) field.getAnnotation(Until.class))) {
return true;
}
if (field.isSynthetic()) {
return true;
}
if (this.requireExpose) {
Expose annotation = (Expose) field.getAnnotation(Expose.class);
if (annotation == null || (serialize ? !annotation.serialize() : !annotation.deserialize())) {
return true;
}
}
if (!this.serializeInnerClasses && isInnerClass(field.getType())) {
return true;
}
if (isAnonymousOrLocal(field.getType())) {
return true;
}
List<ExclusionStrategy> list = serialize ? this.serializationStrategies : this.deserializationStrategies;
if (!list.isEmpty()) {
FieldAttributes fieldAttributes = new FieldAttributes(field);
for (ExclusionStrategy exclusionStrategy : list) {
if (exclusionStrategy.shouldSkipField(fieldAttributes)) {
return true;
}
}
}
return false;
}
/**
* Internal implementation, normal users should not use it.
*/
public void toMap(HashMap<String, String> map, String prefix) {
this.setParamObj(map, prefix + "Expose.", this.Expose);
this.setParamSimple(map, prefix + "RequestId", this.RequestId);
}
@Override
protected JsonIgnore getJsonIgnore(Annotation[] annotations) {
JsonIgnore jsoniterObj = super.getJsonIgnore(annotations);
if (jsoniterObj != null) {
return jsoniterObj;
}
if (builder().excludeFieldsWithoutExposeAnnotation) {
final Expose gsonObj = getAnnotation(
annotations, Expose.class);
if (gsonObj != null) {
return new JsonIgnore() {
@Override
public boolean ignoreDecoding() {
return !gsonObj.deserialize();
}
@Override
public boolean ignoreEncoding() {
return !gsonObj.serialize();
}
@Override
public Class<? extends Annotation> annotationType() {
return JsonIgnore.class;
}
};
}
return new JsonIgnore() {
@Override
public boolean ignoreDecoding() {
return true;
}
@Override
public boolean ignoreEncoding() {
return true;
}
@Override
public Class<? extends Annotation> annotationType() {
return JsonIgnore.class;
}
};
}
return null;
}
@Override
public boolean shouldSkipField(FieldAttributes fieldAttributes) {
final Expose expose = fieldAttributes.getAnnotation(Expose.class);
return expose != null && !expose.serialize();
}
public boolean excludeField(Field field, boolean serialize) {
if ((modifiers & field.getModifiers()) != 0) {
return true;
}
if (version != Excluder.IGNORE_VERSIONS
&& !isValidVersion(field.getAnnotation(Since.class), field.getAnnotation(Until.class))) {
return true;
}
if (field.isSynthetic()) {
return true;
}
if (requireExpose) {
Expose annotation = field.getAnnotation(Expose.class);
if (annotation == null || (serialize ? !annotation.serialize() : !annotation.deserialize())) {
return true;
}
}
if (!serializeInnerClasses && isInnerClass(field.getType())) {
return true;
}
if (isAnonymousOrLocal(field.getType())) {
return true;
}
List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
if (!list.isEmpty()) {
FieldAttributes fieldAttributes = new FieldAttributes(field);
for (ExclusionStrategy exclusionStrategy : list) {
if (exclusionStrategy.shouldSkipField(fieldAttributes)) {
return true;
}
}
}
return false;
}
public boolean excludeField(Field field, boolean serialize) {
if ((modifiers & field.getModifiers()) != 0) {
return true;
}
if (version != Excluder.IGNORE_VERSIONS
&& !isValidVersion(field.getAnnotation(Since.class), field.getAnnotation(Until.class))) {
return true;
}
if (field.isSynthetic()) {
return true;
}
if (requireExpose) {
Expose annotation = field.getAnnotation(Expose.class);
if (annotation == null || (serialize ? !annotation.serialize() : !annotation.deserialize())) {
return true;
}
}
if (!serializeInnerClasses && isInnerClass(field.getType())) {
return true;
}
if (isAnonymousOrLocal(field.getType())) {
return true;
}
List<ExclusionStrategy> list = serialize ? serializationStrategies : deserializationStrategies;
if (!list.isEmpty()) {
FieldAttributes fieldAttributes = new FieldAttributes(field);
for (ExclusionStrategy exclusionStrategy : list) {
if (exclusionStrategy.shouldSkipField(fieldAttributes)) {
return true;
}
}
}
return false;
}
/**
* Get 暴露方式
* @return Expose 暴露方式
*/
public ExposeInfo getExpose() {
return this.Expose;
}
/**
* Set 暴露方式
* @param Expose 暴露方式
*/
public void setExpose(ExposeInfo Expose) {
this.Expose = Expose;
}
/**
* Get 模型暴露方式
* @return Expose 模型暴露方式
*/
public String getExpose() {
return this.Expose;
}
/**
* Set 模型暴露方式
* @param Expose 模型暴露方式
*/
public void setExpose(String Expose) {
this.Expose = Expose;
}
/**
* Get 暴露外网或内网,默认暴露外网,`集群模式` 选填
* @return Expose 暴露外网或内网,默认暴露外网,`集群模式` 选填
*/
public String getExpose() {
return this.Expose;
}
/**
* Set 暴露外网或内网,默认暴露外网,`集群模式` 选填
* @param Expose 暴露外网或内网,默认暴露外网,`集群模式` 选填
*/
public void setExpose(String Expose) {
this.Expose = Expose;
}