本文整理汇总了Java中com.google.gson.GsonBuilder.registerTypeHierarchyAdapter方法的典型用法代码示例。如果您正苦于以下问题:Java GsonBuilder.registerTypeHierarchyAdapter方法的具体用法?Java GsonBuilder.registerTypeHierarchyAdapter怎么用?Java GsonBuilder.registerTypeHierarchyAdapter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gson.GsonBuilder
的用法示例。
在下文中一共展示了GsonBuilder.registerTypeHierarchyAdapter方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EventServlet
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public EventServlet(LeshanServer server, int securePort) {
server.getRegistrationService().addListener(this.registrationListener);
server.getObservationService().addListener(this.observationListener);
// add an interceptor to each endpoint to trace all CoAP messages
coapMessageTracer = new CoapMessageTracer(server.getRegistrationService());
for (Endpoint endpoint : server.getCoapServer().getEndpoints()) {
endpoint.addInterceptor(coapMessageTracer);
}
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeHierarchyAdapter(Registration.class, new RegistrationSerializer(securePort));
gsonBuilder.registerTypeHierarchyAdapter(LwM2mNode.class, new LwM2mNodeSerializer());
gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
this.gson = gsonBuilder.create();
}
示例2: withTypeAdapter
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* Creates a GsonBuilder instance With all of the type adapters for the current classpath.
*/
public static GsonBuilder withTypeAdapter() {
GsonBuilder builder = new GsonBuilder();
try {
for (Class<?> c : typeAdapters()) {
builder.registerTypeHierarchyAdapter(
c.getAnnotation(AnnotatedTypeAdapter.class).forType(),
c.newInstance());
}
} catch (IOException | InstantiationException | IllegalAccessException e) {
throw new RuntimeException("Could not initialize JSON serializers", e);
}
return builder;
}
示例3: gatherParsers
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
@Override
public void gatherParsers(GsonBuilder builder) {
builder.registerTypeHierarchyAdapter(TrickType.class, new TypeAdapter<TrickType>() {
@Override
public TrickType read(JsonReader in) throws IOException {
TrickType type = TrickType.byId.get(in.nextString());
if (type == null) {
return TrickType.STRING;
}
return type;
}
@Override
public void write(JsonWriter out, TrickType value) throws IOException {
out.value(value.getId());
}
});
}
示例4: ClientServlet
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public ClientServlet(LwM2mServer server, int securePort) {
this.server = server;
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeHierarchyAdapter(Registration.class, new RegistrationSerializer(securePort));
gsonBuilder.registerTypeHierarchyAdapter(LwM2mResponse.class, new ResponseSerializer());
gsonBuilder.registerTypeHierarchyAdapter(LwM2mNode.class, new LwM2mNodeSerializer());
gsonBuilder.registerTypeHierarchyAdapter(LwM2mNode.class, new LwM2mNodeDeserializer());
gsonBuilder.setDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
this.gson = gsonBuilder.create();
}
示例5: ObjectSpecServlet
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public ObjectSpecServlet(LwM2mModelProvider pModelProvider) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeHierarchyAdapter(ObjectModel.class, new ObjectModelSerializer());
gsonBuilder.registerTypeHierarchyAdapter(ResourceModel.class, new ResourceModelSerializer());
this.gson = gsonBuilder.create();
// use the provider from the server and return a model by client
modelProvider = pModelProvider;
}
示例6: PlayerProfileCache
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public PlayerProfileCache(MinecraftServer server, File cacheFile)
{
this.mcServer = server;
this.usercacheFile = cacheFile;
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.registerTypeHierarchyAdapter(PlayerProfileCache.ProfileEntry.class, new PlayerProfileCache.Serializer());
this.gson = gsonbuilder.create();
this.load();
}
示例7: UserList
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public UserList(File saveFile)
{
this.saveFile = saveFile;
GsonBuilder gsonbuilder = (new GsonBuilder()).setPrettyPrinting();
gsonbuilder.registerTypeHierarchyAdapter(UserListEntry.class, new UserList.Serializer());
this.gson = gsonbuilder.create();
}
示例8: getGson
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* Initializes the current Gson object if null and returns it. The Gson
* object has custom adapters to manage datatypes according to Facebook
* formats.
*
* @return the current instance of Gson.
*/
public static Gson getGson() {
if (gson == null) {
// Creates the Gson object which will manage the information
// received
GsonBuilder builder = new GsonBuilder();
// Serializes enums as lower-case.
builder.registerTypeHierarchyAdapter(Enum.class, new EnumLowercaseSerializer());
builder.registerTypeAdapter(Entity.class,new EntityValueDeserializer());
gson = builder.create();
}
return gson;
}
示例9: getHomebrewGson
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* Returns a GSON instance with our converters applied.
*
* @return a GSON instance with our converters applied
*/
private static Gson getHomebrewGson() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.excludeFieldsWithoutExposeAnnotation();
gsonBuilder.registerTypeHierarchyAdapter(LocalDateTime.class, new LocalDateTimeSerializer());
return gsonBuilder.create();
}
示例10: AbstractGsonReader
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
/**
* Constructs an {@link AbstractGsonReader} with a custom
* {@link GsonBuilder} to support custom attributes.
*
* @param gsonBuilder
*/
public AbstractGsonReader(final GsonBuilder gsonBuilder) {
gsonBuilder.registerTypeAdapter(DataType.class, new DataType.JsonAdapter());
gsonBuilder.registerTypeHierarchyAdapter(Compression.class, CompressionAdapter.getJsonAdapter());
this.gson = gsonBuilder.create();
}
示例11: PlayerProfileCache
import com.google.gson.GsonBuilder; //导入方法依赖的package包/类
public PlayerProfileCache(GameProfileRepository profileRepoIn, File usercacheFileIn)
{
this.profileRepo = profileRepoIn;
this.usercacheFile = usercacheFileIn;
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.registerTypeHierarchyAdapter(PlayerProfileCache.ProfileEntry.class, new PlayerProfileCache.Serializer());
this.gson = gsonbuilder.create();
this.load();
}