Refine search
@SuppressWarnings("unchecked") private <T> void setObject(Consumer<T> setter, JsonObject jsonObject, String name, Type type, JsonDeserializationContext context) { JsonElement object = jsonObject.get(name); if (object != null) { setter.accept(context.deserialize(object, type)); } }
public <T> T determineJsonElementForDistinguishingImplementers(JsonElement json, JsonDeserializationContext context, String field, String origin) { JsonObject jsonObject = json.getAsJsonObject(); JsonPrimitive prim = (JsonPrimitive) jsonObject.get(field); JsonPrimitive originField = (JsonPrimitive) jsonObject.get(origin); String typeName = prim.getAsString(); Class<?> klass = classForName(typeName, originField == null ? "gocd" : originField.getAsString()); return context.deserialize(jsonObject, klass); }
public class CityListDeserializer implements JsonDeserializer<CityList> { @Override public CityList deserialize(JsonElement element, Type type, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = element.getAsJsonObject(); List<City> cities = new ArrayList<City>(); for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) { // For individual City objects, we can use default deserialisation: City city = context.deserialize(entry.getValue(), City.class); cities.add(city); } return new CityList(cities); } }
JsonObject jsonObject = json.getAsJsonObject(); String type = jsonObject.get(TYPE_FIELD).getAsString(); ClassMetadata<? extends UIWidget, ?> elementMetadata = nuiManager.getWidgetMetadataLibrary().resolve(type, ModuleContext.getContext()); if (elementMetadata == null) { id = jsonObject.get(ID_FIELD).getAsString(); JsonArray list = jsonObject.getAsJsonArray(field.getSerializationName()); for (JsonElement item : list) { result.add(context.deserialize(item, contentType)); field.setValue(element, context.deserialize(jsonObject.get(field.getSerializationName()), field.getType())); if (jsonObject.has(CONTENTS_FIELD)) { for (JsonElement child : jsonObject.getAsJsonArray(CONTENTS_FIELD)) { UIWidget childElement = context.deserialize(child, UIWidget.class); if (childElement != null) { LayoutHint hint = null; if (child.isJsonObject()) { JsonObject childObject = child.getAsJsonObject(); if (layoutHintType != null && !layoutHintType.isInterface() && !Modifier.isAbstract(layoutHintType.getModifiers()) && childObject.has(LAYOUT_INFO_FIELD)) { hint = context.deserialize(childObject.get(LAYOUT_INFO_FIELD), layoutHintType);
@Override public Service deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext ctx) { JsonObject objServices = json.getAsJsonObject(); String theKey; domain = objServices.get("domain").getAsString(); JsonObject obj = objServices.get("services").getAsJsonObject(); services = new HashMap<String, ServiceElement>(); for(Entry<String, JsonElement> entry:obj.entrySet()){ ServiceElement theServiceElement = new ServiceElement(); theKey = entry.getKey(); JsonObject theRawDetail = obj.getAsJsonObject(theKey); theServiceElement.setDescription(theRawDetail.get("description").getAsString()); theServiceElement.setField(ctx.deserialize(theRawDetail.get("fields"), Field.class)); services.put(theKey, theServiceElement); } return new Service(domain, services); }
@Override public SecurityConfig deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { SecurityConfig result = new SecurityConfig(); JsonObject jsonObject = json.getAsJsonObject(); if (jsonObject.has(SERVER_PUBLIC_CERTIFICATE)) { result.serverPublicCertificate = context.deserialize(jsonObject.getAsJsonObject(SERVER_PUBLIC_CERTIFICATE), PublicIdentityCertificate.class); } if (jsonObject.has(SERVER_PRIVATE_CERTIFICATE)) { result.serverPrivateCertificate = context.deserialize(jsonObject.getAsJsonObject(SERVER_PRIVATE_CERTIFICATE), PrivateIdentityCertificate.class); } if (jsonObject.has(CLIENT_IDENTITIES)) { JsonArray clientArray = jsonObject.getAsJsonArray(CLIENT_IDENTITIES); for (JsonElement jsonEntry : clientArray) { ClientEntry entry = context.deserialize(jsonEntry, ClientEntry.class); result.addIdentity(entry.server, new ClientIdentity(entry.clientPublic, entry.clientPrivate)); } } return result; }
private <T> void readBlockPartMap(JsonObject jsonObject, String singleName, String partsName, Supplier<EnumMap<BlockPart, T>> supplier, Class<T> type, JsonDeserializationContext context) { if (jsonObject.has(singleName)) { T value = context.deserialize(jsonObject.get(singleName), type); for (BlockPart blockPart : BlockPart.values()) { supplier.get().put(blockPart, value); if (jsonObject.has(partsName) && jsonObject.get(partsName).isJsonObject()) { JsonObject partsObject = jsonObject.getAsJsonObject(partsName); if (partsObject.has("all")) { T value = context.deserialize(partsObject.get("all"), type); for (BlockPart blockPart : BlockPart.values()) { supplier.get().put(blockPart, value); T value = context.deserialize(partsObject.get("sides"), type); for (BlockPart blockPart : BlockPart.horizontalSides()) { supplier.get().put(blockPart, value); T value = context.deserialize(partsObject.get("topBottom"), type); supplier.get().put(BlockPart.TOP, value); supplier.get().put(BlockPart.BOTTOM, value); String partName = part.toString().toLowerCase(Locale.ENGLISH); if (partsObject.has(partName)) { T value = context.deserialize(partsObject.get(partName), type); supplier.get().put(part, value);
@Override public EntityData.GlobalStore deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { EntityData.GlobalStore.Builder world = EntityData.GlobalStore.newBuilder(); if (json.isJsonObject()) { JsonObject jsonObject = json.getAsJsonObject(); JsonArray prefabArray = jsonObject.getAsJsonArray("prefab"); if (prefabArray != null) { for (JsonElement prefabElem : prefabArray) { world.addPrefab((EntityData.Prefab) context.deserialize(prefabElem, EntityData.Prefab.class)); } } JsonArray entityArray = jsonObject.getAsJsonArray("entity"); if (entityArray != null) { for (JsonElement entityElem : entityArray) { world.addEntity((EntityData.Entity) context.deserialize(entityElem, EntityData.Entity.class)); } } JsonPrimitive nextId = jsonObject.getAsJsonPrimitive("next_entity_id"); if (nextId != null) { world.setNextEntityId(nextId.getAsInt()); } } return world.build(); } }
@Override public T deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { final JsonObject jsonObject = json.getAsJsonObject(); System.err.println(json.toString()); if (jsonObject.has("results")) { final JsonArray results = jsonObject.getAsJsonArray("results"); return context.deserialize(results, typeOfT); } else { return standardGson.fromJson(jsonObject, typeOfT); } } }
@Override public Filters deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { final JsonObject j = json.getAsJsonObject(); final JsonElement filters = j.get(KEY_FILTERS); if (null == filters) { throw new JsonParseException("Missing filters array!"); } final ArrayList<DashboardFilter> viewFilters = new ArrayList<>(); filters.getAsJsonArray().forEach((f) -> viewFilters.add(context.deserialize(f, DashboardFilter.class))); return new Filters(viewFilters); } }
@Override public ResourceSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); final List<String> hosts = context.deserialize(jsonObj.getAsJsonArray("hosts"), List.class); final List<String> racks = context.deserialize(jsonObj.getAsJsonArray("racks"), List.class); return new DefaultResourceSpecification(jsonObj.get("cores").getAsInt(), jsonObj.get("memorySize").getAsInt(), jsonObj.get("instances").getAsInt(), jsonObj.get("uplink").getAsInt(), jsonObj.get("downlink").getAsInt()); }
@Override public DashboardFilter deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); final String name = defensivelyGetString(jsonObject, KEY_NAME); jsonObject.addProperty(KEY_NAME, name); final String type = defensivelyGetString(jsonObject, KEY_TYPE); if (StringUtils.isBlank(type)) throw new JsonParseException("Missing filter type"); switch (type) { case TYPE_WHITELIST: return context.deserialize(jsonObject, WhitelistFilter.class); case TYPE_BLACKLIST: return context.deserialize(jsonObject, BlacklistFilter.class); default: throw new JsonParseException(format("Don't know how to deserialize filter type: \"%s\"", type)); } } }
@Override public BlockShapeData deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { BlockShapeData shape = new BlockShapeData(); JsonObject shapeObj = json.getAsJsonObject(); if (shapeObj.has(DISPLAY_NAME)) { shape.setDisplayName(shapeObj.getAsJsonPrimitive(DISPLAY_NAME).getAsString()); } for (BlockPart part : BlockPart.values()) { if (shapeObj.has(part.toString().toLowerCase(Locale.ENGLISH))) { JsonObject meshObj = shapeObj.getAsJsonObject(part.toString().toLowerCase(Locale.ENGLISH)); shape.setMeshPart(part, (BlockMeshPart) context.deserialize(meshObj, BlockMeshPart.class)); if (part.isSide() && meshObj.has(FULL_SIDE)) { shape.setBlockingSide(part.getSide(), meshObj.get(FULL_SIDE).getAsBoolean()); } } } if (shapeObj.has(COLLISION) && shapeObj.get(COLLISION).isJsonObject()) { JsonObject collisionInfo = shapeObj.get(COLLISION).getAsJsonObject(); processCollision(context, shape, collisionInfo); } else { shape.setCollisionShape(COLLISION_SHAPE_FACTORY.getNewUnitCube()); shape.setCollisionSymmetric(true); } return shape; }
private ColliderInfo processAABBShape(JsonDeserializationContext context, JsonObject colliderDef) { Vector3f offset = context.deserialize(colliderDef.get(POSITION), Vector3f.class); Vector3f extent = context.deserialize(colliderDef.get(EXTENTS), Vector3f.class); if (offset == null) { throw new JsonParseException("AABB Collider missing position"); } if (extent == null) { throw new JsonParseException("AABB Collider missing extents"); } extent.absolute(); return new ColliderInfo(offset, COLLISION_SHAPE_FACTORY.getNewBox(extent)); }
component.setColor( ChatColor.valueOf( object.get( "color" ).getAsString().toUpperCase( Locale.ROOT ) ) ); component.setBold( object.get( "bold" ).getAsBoolean() ); component.setItalic( object.get( "italic" ).getAsBoolean() ); component.setExtra( Arrays.<BaseComponent>asList( context.<BaseComponent[]>deserialize( object.get( "extra" ), BaseComponent[].class ) ) ); if ( event.get( "value" ).isJsonArray() ) res = context.deserialize( event.get( "value" ), BaseComponent[].class ); } else context.<BaseComponent>deserialize( event.get( "value" ), BaseComponent.class ) };
@Override public ShaderMetadata deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { ShaderMetadata result = new ShaderMetadata(); ShaderParameterMetadata[] params = context.deserialize(json.getAsJsonObject().get("params"), ShaderParameterMetadata[].class); for (ShaderParameterMetadata param : params) { result.getParameters().add(param); } return result; } }
@Override public ResourceSpecification deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); final List<String> hosts = context.deserialize(jsonObj.getAsJsonArray("hosts"), List.class); final List<String> racks = context.deserialize(jsonObj.getAsJsonArray("racks"), List.class); return new DefaultResourceSpecification(jsonObj.get("cores").getAsInt(), jsonObj.get("memorySize").getAsInt(), jsonObj.get("instances").getAsInt(), jsonObj.get("uplink").getAsInt(), jsonObj.get("downlink").getAsInt()); }
@Override public SetMultimap<String, V> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { SetMultimap<String, V> result = HashMultimap.create(); JsonObject obj = json.getAsJsonObject(); for (Map.Entry<String, JsonElement> entry : obj.entrySet()) { if (entry.getValue().isJsonArray()) { for (JsonElement item : entry.getValue().getAsJsonArray()) { result.put(entry.getKey(), context.<V>deserialize(item, valueType)); } } else { result.put(entry.getKey(), context.<V>deserialize(entry.getValue(), valueType)); } } return result; }
private ColliderInfo processSphereShape(JsonDeserializationContext context, JsonObject colliderDef) { Vector3f offset = context.deserialize(colliderDef.get(POSITION), Vector3f.class); float radius = colliderDef.get(RADIUS).getAsFloat(); if (offset == null) { throw new JsonParseException("Sphere Collider missing position"); } return new ColliderInfo(offset, COLLISION_SHAPE_FACTORY.getNewSphere(radius)); }
@Override public AgentRuntimeInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); AgentIdentifier identifier = context.deserialize(jsonObject.get("identifier"), AgentIdentifier.class); AgentRuntimeStatus runtimeStatus = context.deserialize(jsonObject.get("runtimeStatus"), AgentRuntimeStatus.class); AgentBuildingInfo buildingInfo = context.deserialize(jsonObject.get("buildingInfo"), AgentBuildingInfo.class); String location = jsonObject.has("location") ? jsonObject.get("location").getAsString() : null; Long usableSpace = jsonObject.has("usableSpace") ? jsonObject.get("usableSpace").getAsLong() : null; String operatingSystemName = jsonObject.has("operatingSystemName") ? jsonObject.get("operatingSystemName").getAsString() : null; String cookie = jsonObject.has("cookie") ? jsonObject.get("cookie").getAsString() : null; boolean supportsBuildCommandProtocol = jsonObject.has("supportsBuildCommandProtocol") && jsonObject.get("supportsBuildCommandProtocol").getAsBoolean(); String elasticPluginId = jsonObject.has("elasticPluginId") ? jsonObject.get("elasticPluginId").getAsString() : null; String elasticAgentId = jsonObject.has("elasticAgentId") ? jsonObject.get("elasticAgentId").getAsString() : null; AgentRuntimeInfo info; if (elasticPluginId == null || StringUtils.isBlank(elasticPluginId)) { info = new AgentRuntimeInfo(identifier, runtimeStatus, location, cookie, supportsBuildCommandProtocol); } else { info = new ElasticAgentRuntimeInfo(identifier, runtimeStatus, location, cookie, elasticAgentId, elasticPluginId); } info.setUsableSpace(usableSpace); info.setOperatingSystem(operatingSystemName); info.setSupportsBuildCommandProtocol(supportsBuildCommandProtocol); info.setBuildingInfo(buildingInfo); return info; } }