Refine search
@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); } }
@Test public void shouldInstantiateATaskForTypeFetch() throws Exception { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("type", "fetch"); jsonObject.addProperty(TypeAdapter.ARTIFACT_ORIGIN, "gocd"); taskTypeAdapter.deserialize(jsonObject, type, jsonDeserializationContext); Mockito.verify(jsonDeserializationContext).deserialize(jsonObject, CRFetchArtifactTask.class); }
@Override public EntityData.Prefab deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { EntityData.Prefab.Builder prefab = EntityData.Prefab.newBuilder(); JsonObject jsonObject = json.getAsJsonObject(); for (Map.Entry<String, JsonElement> entry : jsonObject.entrySet()) { String name = entry.getKey().toLowerCase(Locale.ENGLISH); switch (name) { case "name": if (entry.getValue().isJsonPrimitive()) { prefab.setName(entry.getValue().getAsString()); default: if (entry.getValue().isJsonObject()) { EntityData.Component.Builder component = context.deserialize(entry.getValue(), EntityData.Component.Builder.class); component.setType(entry.getKey()); prefab.addComponent(component);
@Override public UIWidget deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if (json.isJsonPrimitive() && json.getAsJsonPrimitive().isString()) { return new UILabel(json.getAsString()); JsonObject jsonObject = json.getAsJsonObject(); String type = jsonObject.get(TYPE_FIELD).getAsString(); ClassMetadata<? extends UIWidget, ?> elementMetadata = nuiManager.getWidgetMetadataLibrary().resolve(type, ModuleContext.getContext()); if (elementMetadata == null) { if (jsonObject.has(ID_FIELD)) { 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 (layoutHintType != null && !layoutHintType.isInterface() && !Modifier.isAbstract(layoutHintType.getModifiers()) && childObject.has(LAYOUT_INFO_FIELD)) { hint = context.deserialize(childObject.get(LAYOUT_INFO_FIELD), layoutHintType);
@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; } }
if (root.has("id")) { builder.id(root.get("id").getAsString()); JsonElement value = root.get(VALUE_PROPERTY); if (value == null) { throw new JsonParseException(String.format("%s not found for %s in JSON", VALUE_PROPERTY, type)); if (value.isJsonObject()) { final String valueTypeName = value.getAsJsonObject().get(Holder.TYPE_PROPERTY).getAsString(); try { Class<?> valueType = Class.forName(valueTypeName); builder.value(context.deserialize(value, valueType)); } catch (ClassNotFoundException e) { throw new JsonParseException(String.format("Couldn't construct value class %s for %s", valueTypeName, type), e); } else if (value.isJsonPrimitive()) { throw new JsonParseException( String.format("Couldn't deserialize %s : %s. Not a primitive or object", VALUE_PROPERTY, value));
@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 CommitMetadata fromJson(JsonElement json, JsonDeserializationContext context) { JsonObject jsonObject = (JsonObject) json; String author = jsonObject.get(AUTHOR).getAsString(); Map<String, String> properties = CommitPropertiesConverter.fromJson(jsonObject.get(PROPERTIES)); LocalDateTime commitDate = context.deserialize(jsonObject.get(COMMIT_DATE), LocalDateTime.class); Instant commitDateInstant = context.deserialize(jsonObject.get(COMMIT_DATE_INSTANT), Instant.class); CommitId id = context.deserialize(jsonObject.get(COMMIT_ID), CommitId.class); return new CommitMetadata(author, properties, commitDate, commitDateInstant, id); }
@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; }
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); }
private BehaviorNode getCompositeNode(JsonElement json, JsonDeserializationContext context) { String type; JsonObject obj = json.getAsJsonObject(); Map.Entry<String, JsonElement> entry = obj.entrySet().iterator().next(); type = entry.getKey(); JsonElement jsonElement = entry.getValue(); BehaviorNode node = createNode(type); if (actions.containsKey(type)) { Action action = context.deserialize(jsonElement, actions.get(type)); addAction((ActionNode) node, action); } else if (decorators.containsKey(type)) { Action action = context.deserialize(jsonElement, decorators.get(type)); addAction((ActionNode) node, action); JsonElement childJson = jsonElement.getAsJsonObject().get("child"); BehaviorNode child = context.deserialize(childJson, BehaviorNode.class); node.insertChild(0, child); } else if (jsonElement.isJsonArray()) { List<BehaviorNode> children = context.deserialize(jsonElement, new TypeToken<List<BehaviorNode>>() { }.getType()); for (int i = 0; i < children.size(); i++) { BehaviorNode child = children.get(i); node.insertChild(i, child); } } return node; }
protected void deserialize(JsonObject object, BaseComponent component, JsonDeserializationContext context) if ( object.has( "color" ) ) component.setColor( ChatColor.valueOf( object.get( "color" ).getAsString().toUpperCase( Locale.ROOT ) ) ); if ( object.has( "bold" ) ) component.setBold( object.get( "bold" ).getAsBoolean() ); if ( object.has( "italic" ) ) component.setItalic( object.get( "italic" ).getAsBoolean() ); if ( object.has( "underlined" ) ) if ( object.has( "extra" ) ) 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 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; }
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); } }
@Override public BaseComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if ( json.isJsonPrimitive() ) { return new TextComponent( json.getAsString() ); } JsonObject object = json.getAsJsonObject(); if ( object.has( "translate" ) ) { return context.deserialize( json, TranslatableComponent.class ); } if ( object.has( "keybind" ) ) { return context.deserialize( json, KeybindComponent.class ); } if ( object.has( "score" ) ) { return context.deserialize( json, ScoreComponent.class ); } if ( object.has( "selector" ) ) { return context.deserialize( json, SelectorComponent.class ); } return context.deserialize( json, TextComponent.class ); } }
@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)); } } }
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); if (partsObject.has("sides")) { T value = context.deserialize(partsObject.get("sides"), type); for (BlockPart blockPart : BlockPart.horizontalSides()) { supplier.get().put(blockPart, value); if (partsObject.has("topBottom")) { 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 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 BehaviorNode getPrimitiveNode(JsonElement json, JsonDeserializationContext context) { String type = json.getAsString(); BehaviorNode node = createNode(type); if (actions.containsKey(type)) { Action action = context.deserialize(new JsonObject(), actions.get(type)); addAction((ActionNode) node, action); } else if (decorators.containsKey(type)) { Action action = context.deserialize(new JsonObject(), decorators.get(type)); addAction((ActionNode) node, action); } return node; }
@Override public ProgramOptions deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObj = json.getAsJsonObject(); ProgramId programId = context.deserialize(jsonObj.get("programId"), ProgramId.class); Arguments arguments = context.deserialize(jsonObj.get("arguments"), Arguments.class); Arguments userArguments = context.deserialize(jsonObj.get("userArguments"), Arguments.class); boolean debug = jsonObj.get("debug").getAsBoolean(); return new SimpleProgramOptions(programId, arguments, userArguments, debug); }