本文整理匯總了Java中com.google.gson.FieldNamingStrategy類的典型用法代碼示例。如果您正苦於以下問題:Java FieldNamingStrategy類的具體用法?Java FieldNamingStrategy怎麽用?Java FieldNamingStrategy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FieldNamingStrategy類屬於com.google.gson包,在下文中一共展示了FieldNamingStrategy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: print
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
@Override
protected void print(ExportHelper helper, EventLookupRpcRequest request, List<EventInterface> events, int eventCookieFlags, EventMeetingSortBy sort, boolean asc) throws IOException {
helper.setup("application/json", reference(), false);
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
@Override
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
return new JsonPrimitive(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(src));
}
})
.setFieldNamingStrategy(new FieldNamingStrategy() {
Pattern iPattern = Pattern.compile("i([A-Z])(.*)");
@Override
public String translateName(Field f) {
Matcher matcher = iPattern.matcher(f.getName());
if (matcher.matches())
return matcher.group(1).toLowerCase() + matcher.group(2);
else
return f.getName();
}
})
.setPrettyPrinting().create();
helper.getWriter().write(gson.toJson(events));
}
示例2: createEntity
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
protected HttpEntity createEntity(Object pojo) {
Gson gson = new GsonBuilder().serializeNulls()
.setFieldNamingStrategy(new FieldNamingStrategy() {
@Override
public String translateName(Field field) {
String name = field.getName();
if (name.startsWith("m_")) {
name = name.substring(2);
}
return name;
}
}).create();
return new StringEntity(gson.toJson(pojo), ContentType.APPLICATION_JSON);
}
示例3: create
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
@NotNull
static SlackPayloadSerializer create() {
Map<Field, FieldNamingStrategy> customNamings = new HashMap<>();
customNamings.put(declaredField(SlackPayload.Attachment.Field.class, "isShort"), f -> "short");
Gson gson = new GsonBuilder()
.setFieldNamingStrategy(new FieldNamingStrategyDelegate(customNamings, FieldNamingPolicy.IDENTITY))
.disableHtmlEscaping()
.setPrettyPrinting()
.create();
return new SlackPayloadSerializer(gson);
}
示例4: clone
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
private GsonValueMapperFactory clone(GsonValueMapperFactory valueMapperFactory) {
TypeInfoGenerator infoGen = getFieldValue(valueMapperFactory, "typeInfoGenerator");
GsonValueMapperFactory.Configurer configurer = getFieldValue(valueMapperFactory, "configurer");
FieldNamingStrategy fieldNamingStrategy = getFieldValue(valueMapperFactory, "fieldNamingStrategy");
return GsonValueMapperFactory.builder()
.withBasePackages(basePackages)
.withTypeInfoGenerator(infoGen)
.withFieldNamingStrategy(fieldNamingStrategy)
.withConfigurer(configurer)
.build();
}
示例5: ReflectiveTypeAdapterFactory
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
public ReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor,
FieldNamingStrategy fieldNamingPolicy, Excluder excluder,
JsonAdapterAnnotationTypeAdapterFactory jsonAdapterFactory) {
this.constructorConstructor = constructorConstructor;
this.fieldNamingPolicy = fieldNamingPolicy;
this.excluder = excluder;
this.jsonAdapterFactory = jsonAdapterFactory;
}
示例6: createReflectiveTypeAdapterFactory
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
protected LaReflectiveTypeAdapterFactory createReflectiveTypeAdapterFactory(Gson newGson, Object factory) {
final ConstructorConstructor constructorConstructor = getConstructorConstructor(factory);
final JsonAdapterAnnotationTypeAdapterFactory jsonAdapterFactory = getJsonAdapterFactory(factory);
final FieldNamingStrategy fieldNamingStrategy = newGson.fieldNamingStrategy();
final Excluder excluder = newGson.excluder();
return new LaReflectiveTypeAdapterFactory(constructorConstructor, fieldNamingStrategy, excluder, jsonAdapterFactory);
}
示例7: LaReflectiveTypeAdapterFactory
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
public LaReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor, FieldNamingStrategy fieldNamingPolicy,
Excluder excluder, JsonAdapterAnnotationTypeAdapterFactory jsonAdapterFactory) {
this.constructorConstructor = constructorConstructor;
this.fieldNamingPolicy = fieldNamingPolicy;
this.excluder = excluder;
this.jsonAdapterFactory = jsonAdapterFactory;
}
示例8: doCreate
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
@Override
protected void doCreate(ConstructorConstructor constructorConstructor, FieldNamingStrategy fieldNamingPolicy, Excluder excluder) {
registerTypeAdapterFactory(new HyperDataAdapterFactory(constructorConstructor, fieldNamingPolicy, excluder));
registerTypeAdapter(HyperMap.class, new GsonHyperDataDeserializer());
registerTypeAdapter(HyperMap.class, new GsonHyperDataSerializer());
registerTypeAdapter(HyperHashMap.class, new GsonHyperDataDeserializer());
registerTypeAdapter(HyperHashMap.class, new GsonHyperDataSerializer());
}
示例9: ReflectiveTypeAdapterFactory
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
public ReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor, FieldNamingStrategy fieldNamingPolicy, Excluder excluder) {
this.constructorConstructor = constructorConstructor;
this.fieldNamingPolicy = fieldNamingPolicy;
this.excluder = excluder;
}
示例10: ReflectiveTypeAdapterFactory
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
public ReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor,
FieldNamingStrategy fieldNamingPolicy, Excluder excluder) {
this.constructorConstructor = constructorConstructor;
this.fieldNamingPolicy = fieldNamingPolicy;
this.excluder = excluder;
}
示例11: getFieldName
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
static String getFieldName(FieldNamingStrategy fieldNamingPolicy, Field f) {
SerializedName serializedName = f.getAnnotation(SerializedName.class);
return serializedName == null ? fieldNamingPolicy.translateName(f) : serializedName.value();
}
示例12: ReflectiveTypeAdapterFactory
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
public ReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor,
FieldNamingStrategy fieldNamingPolicy, Excluder excluder) {
this.constructorConstructor = constructorConstructor;
this.fieldNamingPolicy = fieldNamingPolicy;
this.excluder = excluder;
}
示例13: FieldNamingStrategyDelegate
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
private FieldNamingStrategyDelegate(Map<Field, FieldNamingStrategy> customNamings, FieldNamingStrategy delegate) {
this.customNamings = customNamings;
this.delegate = delegate;
}
示例14: GsonFieldNamingStrategy
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
public GsonFieldNamingStrategy(FieldNamingStrategy fallback) {
this.fallback = fallback;
}
示例15: GsonValueMapperFactory
import com.google.gson.FieldNamingStrategy; //導入依賴的package包/類
private GsonValueMapperFactory(String[] basePackages, TypeInfoGenerator typeInfoGenerator, FieldNamingStrategy fieldNamingStrategy, Configurer configurer) {
this.basePackages = basePackages;
this.fieldNamingStrategy = Objects.requireNonNull(fieldNamingStrategy);
this.typeInfoGenerator = Objects.requireNonNull(typeInfoGenerator);
this.configurer = Objects.requireNonNull(configurer);
}