本文整理汇总了Java中com.google.gson.JsonDeserializationContext类的典型用法代码示例。如果您正苦于以下问题:Java JsonDeserializationContext类的具体用法?Java JsonDeserializationContext怎么用?Java JsonDeserializationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonDeserializationContext类属于com.google.gson包,在下文中一共展示了JsonDeserializationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
@Nullable
public Feature deserialize(@Nonnull JsonElement json, @Nonnull Type typeOfT, @Nonnull JsonDeserializationContext context)
throws JsonParseException {
try {
JsonObject jsonObject = json.getAsJsonObject();
// default path
String name = jsonObject.get("name").getAsString();
if (!name.contains(".")) {
name = DEFAULT_PATH + "." + name;
}
Class clazz = Class.forName(name);
Feature feature = context.deserialize(json, clazz);
injector.injectMembers(feature);
return feature;
} catch (Exception e) {
log.log(Level.WARNING, "Could not deserialize feature:\n" + json.toString(), e);
}
return null;
}
示例2: deserialize
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
public SetAttributes deserialize(JsonObject object, JsonDeserializationContext deserializationContext, LootCondition[] conditionsIn)
{
JsonArray jsonarray = JsonUtils.getJsonArray(object, "modifiers");
SetAttributes.Modifier[] asetattributes$modifier = new SetAttributes.Modifier[jsonarray.size()];
int i = 0;
for (JsonElement jsonelement : jsonarray)
{
asetattributes$modifier[i++] = SetAttributes.Modifier.deserialize(JsonUtils.getJsonObject(jsonelement, "modifier"), deserializationContext);
}
if (asetattributes$modifier.length == 0)
{
throw new JsonSyntaxException("Invalid attribute modifiers array; cannot be empty");
}
else
{
return new SetAttributes(conditionsIn, asetattributes$modifier);
}
}
示例3: deserialize
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
public VariantList deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_) throws JsonParseException
{
List<Variant> list = Lists.<Variant>newArrayList();
if (p_deserialize_1_.isJsonArray())
{
JsonArray jsonarray = p_deserialize_1_.getAsJsonArray();
if (jsonarray.size() == 0)
{
throw new JsonParseException("Empty variant array");
}
for (JsonElement jsonelement : jsonarray)
{
list.add((Variant)p_deserialize_3_.deserialize(jsonelement, Variant.class));
}
}
else
{
list.add((Variant)p_deserialize_3_.deserialize(p_deserialize_1_, Variant.class));
}
return new VariantList(list);
}
示例4: parseMapVariants
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
protected Map<String, VariantList> parseMapVariants(JsonDeserializationContext deserializationContext, JsonObject object)
{
Map<String, VariantList> map = Maps.<String, VariantList>newHashMap();
if (object.has("variants"))
{
JsonObject jsonobject = JsonUtils.getJsonObject(object, "variants");
for (Entry<String, JsonElement> entry : jsonobject.entrySet())
{
map.put(entry.getKey(), (VariantList)deserializationContext.deserialize((JsonElement)entry.getValue(), VariantList.class));
}
}
return map;
}
示例5: deserialize
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public VKApiComment deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject root = json.getAsJsonObject();
VKApiComment dto = new VKApiComment();
dto.id = optInt(root, "id");
dto.from_id = optInt(root, "from_id");
if(dto.from_id == 0){
dto.from_id = optInt(root, "owner_id");
}
dto.date = optLong(root, "date");
dto.text = optString(root, "text");
dto.reply_to_user = optInt(root, "reply_to_user");
dto.reply_to_comment = optInt(root, "reply_to_comment");
if(root.has("attachments")){
dto.attachments = context.deserialize(root.get("attachments"), VkApiAttachments.class);
}
if(root.has("likes")){
JsonObject likesRoot = root.getAsJsonObject("likes");
dto.likes = optInt(likesRoot, "count");
dto.user_likes = optIntAsBoolean(likesRoot, "user_likes");
dto.can_like = optIntAsBoolean(likesRoot, "can_like");
}
dto.can_edit = optIntAsBoolean(root, "can_edit");
return dto;
}
示例6: deserialize
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public VideoList deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
VideoList videoList = new VideoList();
JsonObject jsonObject = json.getAsJsonObject().getAsJsonObject("data");
videoList.setAfter(jsonObject.getAsJsonPrimitive("after").getAsString());
Iterator<JsonElement> videoListJsonIterator = jsonObject.getAsJsonArray("children").iterator();
while (videoListJsonIterator.hasNext()) {
JsonElement videoItemJson = videoListJsonIterator.next();
try {
Video video = context.deserialize(videoItemJson, Video.class);
if (video != null) {
videoList.addVideo(video);
}
} catch (Throwable t) {
Log.e(TAG, "Failed to deserialize a video item : " + videoItemJson, t);
}
}
return videoList;
}
示例7: deserialize
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public Video deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
Video video = null;
JsonObject jsonObject = json.getAsJsonObject().getAsJsonObject("data");
String domain = jsonObject.getAsJsonPrimitive("domain").getAsString();
if (isYoutubeDomain(domain)) {
String url = jsonObject.getAsJsonPrimitive("url").getAsString();
String youtubeId = getYoutubeId(url);
if (youtubeId != null && youtubeId.length() > 0) {
video = new Video(
jsonObject.getAsJsonPrimitive("id").getAsString(),
youtubeId,
jsonObject.getAsJsonPrimitive("created").getAsLong(),
jsonObject.getAsJsonPrimitive("title").getAsString(),
url
);
}
}
return video;
}
示例8: deserialize
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public UserArray deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject root = json.getAsJsonObject();
UserArray dto = new UserArray();
dto.count = optInt(root, "count");
if(root.has("items")){
JsonArray array = root.getAsJsonArray("items");
dto.ids = new int[array.size()];
for(int i = 0; i < array.size(); i++){
dto.ids[i] = array.get(i).getAsJsonObject().get("from_id").getAsInt();
}
} else {
dto.ids = new int[0];
}
return dto;
}
示例9: deserialize
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public URL deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext context) throws JsonParseException {
Preconditions.checkNotNull(jsonElement);
Preconditions.checkNotNull(type);
Preconditions.checkNotNull(context);
if (jsonElement.getAsString() == null) {
throw new JsonParseException("URL must be a string");
}
try {
return new URL(jsonElement.getAsString());
} catch (final MalformedURLException e) {
throw new JsonParseException(e);
}
}
示例10: deserialize
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public FeatureCollectionDto deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
FeatureCollectionDto dto = new FeatureCollectionDto();
List<FeatureDto> features = new ArrayList<>();
dto.setFeatures(features);
JsonObject asJsonObject = json.getAsJsonObject();
JsonArray jsonArray = asJsonObject.get("features").getAsJsonArray();
if (jsonArray == null) {
return dto;
}
for (int i = 0; i < jsonArray.size(); i++) {
JsonObject featureElement = jsonArray.get(i).getAsJsonObject();
FeatureDto geometryDto = context.deserialize(featureElement, FeatureDto.class);
features.add(geometryDto);
}
dto.setBbox(BoundingBoxParser.parseBbox(asJsonObject, context));
return dto;
}
示例11: parseVariants
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
protected ModelBlockDefinition.Variants parseVariants(JsonDeserializationContext p_178335_1_, Entry<String, JsonElement> p_178335_2_)
{
String s = (String)p_178335_2_.getKey();
List<ModelBlockDefinition.Variant> list = Lists.<ModelBlockDefinition.Variant>newArrayList();
JsonElement jsonelement = (JsonElement)p_178335_2_.getValue();
if (jsonelement.isJsonArray())
{
for (JsonElement jsonelement1 : jsonelement.getAsJsonArray())
{
list.add((ModelBlockDefinition.Variant)p_178335_1_.deserialize(jsonelement1, ModelBlockDefinition.Variant.class));
}
}
else
{
list.add((ModelBlockDefinition.Variant)p_178335_1_.deserialize(jsonelement, ModelBlockDefinition.Variant.class));
}
return new ModelBlockDefinition.Variants(s, list);
}
示例12: deserialize
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public AbstractApplication deserialize(final JsonElement p_jsonElement, final Type p_type,
final JsonDeserializationContext p_jsonDeserializationContext) {
JsonObject jsonObj = p_jsonElement.getAsJsonObject();
String className = jsonObj.get("m_class").getAsString();
boolean enabled = jsonObj.get("m_enabled").getAsBoolean();
// don't create instance if disabled
if (!enabled) {
return null;
}
if (!m_appClass.getSuperclass().equals(AbstractApplication.class)) {
// check if there is an "interface"/abstract class between DXRAMComponent and the instance to
// create
if (!m_appClass.getSuperclass().getSuperclass().equals(AbstractApplication.class)) {
LOGGER.fatal("Could class '%s' is not a subclass of AbstractApplication, check your config file", className);
return null;
}
}
return p_jsonDeserializationContext.deserialize(p_jsonElement, m_appClass);
}
示例13: deserialize
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public EntityWrapper deserialize(JsonElement jsonElement, Type typef, JsonDeserializationContext context) throws JsonParseException {
if (jsonElement == null || jsonElement instanceof JsonNull) {
return null;
}
JsonObject root = jsonElement.getAsJsonObject();
boolean isNull = root.get(KEY_IS_NULL).getAsBoolean();
Entity entity = null;
if (!isNull) {
int dbotype = root.get(KEY_TYPE).getAsInt();
entity = context.deserialize(root.get(KEY_ENTITY), AttachmentsTypes.classForType(dbotype));
}
return new EntityWrapper(entity);
}
示例14: deserialize
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public AttachmentsEntity deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException {
JsonArray array = jsonElement.getAsJsonArray();
if(array.size() == 0){
return new AttachmentsEntity(Collections.emptyList());
}
List<Entity> entities = new ArrayList<>(array.size());
for(int i = 0; i < array.size(); i++){
JsonObject o = array.get(i).getAsJsonObject();
int dbotype = o.get(KEY_ENTITY_TYPE).getAsInt();
entities.add(context.deserialize(o.get(KEY_ENTITY), AttachmentsTypes.classForType(dbotype)));
}
return new AttachmentsEntity(entities);
}
示例15: deserialize
import com.google.gson.JsonDeserializationContext; //导入依赖的package包/类
@Override
public FieldMap deserialize(JsonElement json,
Type typeOfT,
JsonDeserializationContext context) throws JsonParseException {
JsonObject rootObject = json.getAsJsonObject();
Set<Map.Entry<String, JsonElement>> entrySet = rootObject.entrySet();
FieldMap fieldMap = new FieldMap();
for (Map.Entry<String, JsonElement> entry : entrySet) {
JsonObject propertyObject = entry.getValue().getAsJsonObject();
String propertyName = entry.getKey();
parsePropertyObject(propertyObject, propertyName, fieldMap, context);
}
return fieldMap;
}