@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)); }
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); }
@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); }
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(); }
public ReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor, FieldNamingStrategy fieldNamingPolicy, Excluder excluder, JsonAdapterAnnotationTypeAdapterFactory jsonAdapterFactory) { this.constructorConstructor = constructorConstructor; this.fieldNamingPolicy = fieldNamingPolicy; this.excluder = excluder; this.jsonAdapterFactory = jsonAdapterFactory; }
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); }
public LaReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor, FieldNamingStrategy fieldNamingPolicy, Excluder excluder, JsonAdapterAnnotationTypeAdapterFactory jsonAdapterFactory) { this.constructorConstructor = constructorConstructor; this.fieldNamingPolicy = fieldNamingPolicy; this.excluder = excluder; this.jsonAdapterFactory = jsonAdapterFactory; }
@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()); }
public ReflectiveTypeAdapterFactory(ConstructorConstructor constructorConstructor, FieldNamingStrategy fieldNamingPolicy, Excluder excluder) { this.constructorConstructor = constructorConstructor; this.fieldNamingPolicy = fieldNamingPolicy; this.excluder = excluder; }
static String getFieldName(FieldNamingStrategy fieldNamingPolicy, Field f) { SerializedName serializedName = f.getAnnotation(SerializedName.class); return serializedName == null ? fieldNamingPolicy.translateName(f) : serializedName.value(); }
private FieldNamingStrategyDelegate(Map<Field, FieldNamingStrategy> customNamings, FieldNamingStrategy delegate) { this.customNamings = customNamings; this.delegate = delegate; }
public GsonFieldNamingStrategy(FieldNamingStrategy fallback) { this.fallback = fallback; }
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); }
private GsonBuilder initBuilder(FieldNamingStrategy fieldNamingStrategy, Set<Type> abstractTypes, Configurer configurer, GlobalEnvironment environment) { GsonBuilder gsonBuilder = new GsonBuilder() .setFieldNamingStrategy(fieldNamingStrategy) .registerTypeAdapterFactory(new GsonJava8TypeAdapterFactory()); return configurer.configure(gsonBuilder, abstractTypes, basePackages, this.typeInfoGenerator, environment); }
public Builder withFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy) { this.fieldNamingStrategy = fieldNamingStrategy; return this; }
public FieldNamingStrategy getFieldNamingStrategy() { return fieldNamingStrategy; }
public void setFieldNamingStrategy(FieldNamingStrategy fieldNamingStrategy) { this.fieldNamingStrategy = fieldNamingStrategy; }
public ReflectiveTypeAdapterFactory(ConstructorConstructor paramConstructorConstructor, FieldNamingStrategy paramFieldNamingStrategy, Excluder paramExcluder) { this.constructorConstructor = paramConstructorConstructor; this.fieldNamingPolicy = paramFieldNamingStrategy; this.excluder = paramExcluder; }
public ReflectiveTypeAdapterFactory(ConstructorConstructor constructorconstructor, FieldNamingStrategy fieldnamingstrategy, Excluder excluder) { a = constructorconstructor; b = fieldnamingstrategy; c = excluder; }
public HyperDataAdapterFactory(ConstructorConstructor constructorConstructor, FieldNamingStrategy fieldNamingPolicy, Excluder excluder) { super(constructorConstructor, fieldNamingPolicy, excluder); this.constructorConstructor = constructorConstructor; this.fieldNamingPolicy = fieldNamingPolicy; this.excluder = excluder; }
/** * Constructor. * * @param fieldNamingStrategy the field naming strategy to be used when deserializing object */ public MotechJsonReader(FieldNamingStrategy fieldNamingStrategy) { this.fieldNamingStrategy = fieldNamingStrategy; }