本文整理汇总了Java中com.google.gson.typeadapters.RuntimeTypeAdapterFactory类的典型用法代码示例。如果您正苦于以下问题:Java RuntimeTypeAdapterFactory类的具体用法?Java RuntimeTypeAdapterFactory怎么用?Java RuntimeTypeAdapterFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RuntimeTypeAdapterFactory类属于com.google.gson.typeadapters包,在下文中一共展示了RuntimeTypeAdapterFactory类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getGson
import com.google.gson.typeadapters.RuntimeTypeAdapterFactory; //导入依赖的package包/类
/**
* Generates a gson that has all of the common features loaded in.
* @return a gson object
*/
private static Gson getGson() {
if (sGson == null) {
GsonBuilder builder = new GsonBuilder();
RuntimeTypeAdapterFactory<BaseClass> adapter = RuntimeTypeAdapterFactory
.of(BaseClass.class)
.registerSubtype(Amazon.class)
.registerSubtype(Barbarian.class)
.registerSubtype(Centaur.class)
.registerSubtype(Elementalist.class)
.registerSubtype(Hunter.class)
.registerSubtype(Lyrist.class)
.registerSubtype(Magician.class)
.registerSubtype(Noble.class)
.registerSubtype(Nymph.class)
.registerSubtype(Priest.class)
.registerSubtype(Sorcerer.class)
.registerSubtype(Spearman.class)
.registerSubtype(Thief.class);
builder.registerTypeAdapter(PlayerCharacter.class, new CharacterSerializer());
builder.registerTypeAdapterFactory(adapter);
builder.setPrettyPrinting();
sGson = builder.create();
}
return sGson;
}
开发者ID:CIS-Extra,项目名称:mazes_and_minotaurs,代码行数:30,代码来源:SaveAndLoadPerformer.java
示例2: fromFile
import com.google.gson.typeadapters.RuntimeTypeAdapterFactory; //导入依赖的package包/类
/**
* Reads a stash tab from file
*
* @param fileName The file containing stash info
* @return Requested stash tab
* @throws Exception
*/
public static StashTab fromFile(String fileName) throws Exception {
RuntimeTypeAdapterFactory<Item> itemAdapter = RuntimeTypeAdapterFactory.of(Item.class, new ItemTypePredicate())
.registerSubtype(Currency.class)
.registerSubtype(Equipment.class)
.registerSubtype(Gem.class)
.registerSubtype(Map.class);
Gson gson = new GsonBuilder()
.enableComplexMapKeySerialization()
.registerTypeAdapterFactory(itemAdapter)
.registerTypeAdapter(Property.class, new PropertyDeserializer())
.registerTypeAdapter(Property.class, new RequirementDeserializer())
.registerTypeAdapter(Sockets.class, new SocketDeserializer())
.registerTypeAdapter(ExplicitMod.class, new ExplicitModDeserializer())
.registerTypeAdapter(ImplicitMod.class, new ImplicitModDeserializer()).create();
return gson.fromJson(new JsonReader(new FileReader(fileName)), StashTab.class);
}
开发者ID:Speljohan,项目名称:lib-poe,代码行数:27,代码来源:StashLoader.java
示例3: getGson
import com.google.gson.typeadapters.RuntimeTypeAdapterFactory; //导入依赖的package包/类
private static Gson getGson() {
if (sGson == null) {
GsonBuilder builder = new GsonBuilder();
RuntimeTypeAdapterFactory adapter = RuntimeTypeAdapterFactory
.of(Equipment.class)
.registerSubtype(Equipment.class)
.registerSubtype(Weapon.class)
.registerSubtype(Armor.class)
.registerSubtype(Mythics.class);
builder.registerTypeAdapterFactory(adapter);
builder.setPrettyPrinting();
sGson = builder.create();
}
return sGson;
}
开发者ID:CIS-Extra,项目名称:mazes_and_minotaurs,代码行数:16,代码来源:CharacterSerializer.java
示例4: createGsonBuilder
import com.google.gson.typeadapters.RuntimeTypeAdapterFactory; //导入依赖的package包/类
@Override
@NonNull
protected GsonBuilder createGsonBuilder(@NonNull GsonBuilder gsonBuilder) {
return super.createGsonBuilder(gsonBuilder)
.registerTypeAdapterFactory(RuntimeTypeAdapterFactory.of(ActEvent.class)
.registerSubtype(AfterUpdateEvent.class)
.registerSubtype(OneShotEvent.class)
.registerSubtype(StepEvent.class)
.registerSubtype(TimeEvent.class));
}
开发者ID:seroperson,项目名称:itstimetoact,代码行数:11,代码来源:SampleGsonTimeToAct.java
示例5: setup
import com.google.gson.typeadapters.RuntimeTypeAdapterFactory; //导入依赖的package包/类
@Before
public void setup() {
timeToAct = new GsonTimeToAct(RuntimeEnvironment.application) {
@Override
@NonNull
protected GsonBuilder createGsonBuilder(@NonNull GsonBuilder gsonBuilder) {
return super.createGsonBuilder(gsonBuilder)
.registerTypeAdapterFactory(RuntimeTypeAdapterFactory.of(ActEvent.class)
.registerSubtype(TestEvent.class)
.registerSubtype(SecondTestEvent.class));
}
};
}
开发者ID:seroperson,项目名称:itstimetoact,代码行数:15,代码来源:GsonTest.java
示例6: JupyterUtil
import com.google.gson.typeadapters.RuntimeTypeAdapterFactory; //导入依赖的package包/类
public JupyterUtil() {
this.cellTypeFactory = RuntimeTypeAdapterFactory.of(Cell.class, "cell_type")
.registerSubtype(MarkdownCell.class, "markdown").registerSubtype(CodeCell.class, "code")
.registerSubtype(RawCell.class, "raw").registerSubtype(HeadingCell.class, "heading");
this.outputTypeFactory = RuntimeTypeAdapterFactory.of(Output.class, "output_type")
.registerSubtype(ExecuteResult.class, "execute_result")
.registerSubtype(DisplayData.class, "display_data").registerSubtype(Stream.class, "stream")
.registerSubtype(Error.class, "error");
this.markdownProcessor = new PegdownParser();
}
开发者ID:apache,项目名称:zeppelin,代码行数:11,代码来源:JupyterUtil.java
示例7: getPlacePointAdapterFactory
import com.google.gson.typeadapters.RuntimeTypeAdapterFactory; //导入依赖的package包/类
public static RuntimeTypeAdapterFactory<PlacePoint> getPlacePointAdapterFactory() {
// NOTES: TransitStop is derived from PlacePoint.
// API returns list of PlacePoint for GET static/stops where each can be PlacePoint or TransitStop
// For each item in the list, field "subClassType" is used to discriminate between these types.
// RuntimeTypeAdapterFactory<PlacePoint> provides mechanism for polymorphic deserialization.
RuntimeTypeAdapterFactory<PlacePoint> retVal = RuntimeTypeAdapterFactory.of(
PlacePoint.class,
"subClassType");
retVal.registerSubtype(TransitStop.class, "TransitStop");
return retVal;
}
开发者ID:urbanthings,项目名称:android-urbanthings-sdk,代码行数:12,代码来源:UrbanThingsGson.java
示例8: getJourneyLegAdapterFactory
import com.google.gson.typeadapters.RuntimeTypeAdapterFactory; //导入依赖的package包/类
public static RuntimeTypeAdapterFactory<JourneyLeg> getJourneyLegAdapterFactory() {
// NOTES: TransitJourneyLeg is derived from JourneyLeg.
// Journey contains ArrayList<JourneyLeg> where each leg might be JourneyLeg or TransitJourneyLeg
// For each item in the list, (default) field "type" is used to discriminate between these types.
// RuntimeTypeAdapterFactory<JourneyLeg> provides mechanism for polymorphic deserialization.
RuntimeTypeAdapterFactory<JourneyLeg> retVal = RuntimeTypeAdapterFactory.of(
JourneyLeg.class);
retVal.registerSubtype(TransitJourneyLeg.class, "TransitJourneyLeg");
return retVal;
}
开发者ID:urbanthings,项目名称:android-urbanthings-sdk,代码行数:11,代码来源:UrbanThingsGson.java
示例9: SampleDomainGsonFactory
import com.google.gson.typeadapters.RuntimeTypeAdapterFactory; //导入依赖的package包/类
public SampleDomainGsonFactory() {
final RuntimeTypeAdapterFactory<AggregateRoot> aggregateRootAdapter =
RuntimeTypeAdapterFactory.of(AggregateRoot.class)
.registerSubtype(InventoryItemAggregateRoot.class, InventoryItemAggregateRoot.class.getSimpleName());
final RuntimeTypeAdapterFactory<Command> commandAdapter =
RuntimeTypeAdapterFactory.of(Command.class)
.registerSubtype(CreateInventoryItem.class, CreateInventoryItem.class.getSimpleName())
.registerSubtype(IncreaseInventory.class, IncreaseInventory.class.getSimpleName())
.registerSubtype(DecreaseInventory.class, DecreaseInventory.class.getSimpleName());
final RuntimeTypeAdapterFactory<Event> eventAdapter =
RuntimeTypeAdapterFactory.of(Event.class)
.registerSubtype(InventoryItemCreated.class, InventoryItemCreated.class.getSimpleName())
.registerSubtype(InventoryIncreased.class, InventoryIncreased.class.getSimpleName())
.registerSubtype(InventoryDecreased.class, InventoryDecreased.class.getSimpleName());
this.gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT)
.registerTypeAdapterFactory(aggregateRootAdapter)
.registerTypeAdapterFactory(commandAdapter)
.registerTypeAdapterFactory(eventAdapter)
//.setPrettyPrinting()
.create();
}
开发者ID:rodolfodpk,项目名称:myeslib,代码行数:28,代码来源:SampleDomainGsonFactory.java
注:本文中的com.google.gson.typeadapters.RuntimeTypeAdapterFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论