List of usage examples for com.google.gson GsonBuilder registerTypeAdapterFactory
public GsonBuilder registerTypeAdapterFactory(TypeAdapterFactory factory)
From source file:org.kairosdb.core.http.rest.json.QueryParser.java
License:Apache License
@Inject public QueryParser(AggregatorFactory aggregatorFactory, GroupByFactory groupByFactory, QueryPluginFactory pluginFactory) { m_aggregatorFactory = aggregatorFactory; m_groupByFactory = groupByFactory;//from ww w. j ava 2s . c o m m_pluginFactory = pluginFactory; m_descriptorMap = new HashMap<Class, Map<String, PropertyDescriptor>>(); GsonBuilder builder = new GsonBuilder(); builder.registerTypeAdapterFactory(new LowercaseEnumTypeAdapterFactory()); builder.registerTypeAdapter(TimeUnit.class, new TimeUnitDeserializer()); builder.registerTypeAdapter(DateTimeZone.class, new DateTimeZoneDeserializer()); builder.registerTypeAdapter(Metric.class, new MetricDeserializer()); builder.registerTypeAdapter(SetMultimap.class, new SetMultimapDeserializer()); builder.registerTypeAdapter(RelativeTime.class, new RelativeTimeSerializer()); builder.registerTypeAdapter(SetMultimap.class, new SetMultimapSerializer()); builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); m_gson = builder.create(); }
From source file:org.lastaflute.core.json.engine.GsonJsonEngine.java
License:Apache License
protected void registerStringAdapter(GsonBuilder builder) { builder.registerTypeAdapterFactory(createStringTypeAdapterFactory()); }
From source file:org.lastaflute.core.json.engine.GsonJsonEngine.java
License:Apache License
protected void registerNumberAdapter(GsonBuilder builder) { // to show property path in exception message createNumberFactoryList().forEach(factory -> builder.registerTypeAdapterFactory(factory)); }
From source file:org.lastaflute.core.json.engine.GsonJsonEngine.java
License:Apache License
protected void registerJava8TimeAdapter(GsonBuilder builder) { // until supported by Gson builder.registerTypeAdapterFactory(createDateTimeTypeAdapterFactory()); }
From source file:org.lastaflute.core.json.engine.GsonJsonEngine.java
License:Apache License
protected void registerBooleanAdapter(GsonBuilder builder) { // to adjust boolean expression flexibly builder.registerTypeAdapterFactory(createBooleanTypeAdapterFactory()); }
From source file:org.lastaflute.core.json.engine.GsonJsonEngine.java
License:Apache License
protected void registerCollectionAdapter(GsonBuilder builder) { // for option of list-null-to-empty builder.registerTypeAdapterFactory(createCollectionTypeAdapterFactory()); }
From source file:org.lastaflute.core.json.engine.GsonJsonEngine.java
License:Apache License
protected void registerDBFluteAdapter(GsonBuilder builder) { builder.registerTypeAdapterFactory(createClassificationTypeAdapterFactory()); }
From source file:org.lastaflute.core.json.engine.GsonJsonEngine.java
License:Apache License
protected void setupYourCollectionSettings(GsonBuilder builder) { final List<JsonYourCollectionResource> yourCollections = option.getYourCollections(); for (JsonYourCollectionResource resource : yourCollections) { builder.registerTypeAdapterFactory(createYourCollectionTypeAdapterFactory(resource)); }/* ww w.j av a2s .com*/ }
From source file:org.objectpocket.ObjectPocketImpl.java
License:Apache License
private Gson configureGson() { if (gson == null) { GsonBuilder gsonBuilder = new GsonBuilder(); // null serialization if (serializeNulls) { gsonBuilder.serializeNulls(); }// ww w . j a v a2 s . c o m // This is where the referencing entry magic happens gsonBuilder.registerTypeAdapterFactory(new CustomTypeAdapterFactory(this)); // add custom type adapters for (Type type : typeAdapterMap.keySet()) { for (Object typeAdapter : typeAdapterMap.get(type)) { gsonBuilder.registerTypeAdapter(type, typeAdapter); } } // pretty printing if (prettyPrinting) { gsonBuilder.setPrettyPrinting(); } gson = gsonBuilder.create(); } return gson; }
From source file:org.raspinloop.config.GsonProperties.java
License:Apache License
@SuppressWarnings("unchecked") private <T> GsonBuilder registerImpl(Collection<HardwareProperties> objects, GsonBuilder builder, Class<T> type) {/*from w ww . ja v a 2 s . c o m*/ RuntimeTypeAdapterFactory<T> typeFactory = RuntimeTypeAdapterFactory.of(type, "java_type"); for (HardwareProperties obj : objects) { if (type.isInstance(obj)) { typeFactory.registerSubtype((Class<? extends T>) obj.getClass(), obj.getClass().getName()); } } return builder.registerTypeAdapterFactory(typeFactory); }