List of usage examples for com.google.gson JsonDeserializationContext deserialize
public <T> T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
From source file:org.wso2.carbon.siddhi.editor.core.util.designview.deserializers.types.QueryInputConfigDeSerializer.java
License:Open Source License
@Override public Object deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) { JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonObject.get(TYPE); String queryInputType = jsonPrimitive.getAsString(); if (queryInputType.equalsIgnoreCase(QueryInputType.WINDOW.toString()) || queryInputType.equalsIgnoreCase(QueryInputType.FILTER.toString()) || queryInputType.equalsIgnoreCase(QueryInputType.PROJECTION.toString()) || queryInputType.equalsIgnoreCase(QueryInputType.FUNCTION.toString())) { return jsonDeserializationContext.deserialize(jsonObject, WindowFilterProjectionConfig.class); } else if (queryInputType.equalsIgnoreCase(QueryInputType.JOIN.toString())) { return jsonDeserializationContext.deserialize(jsonObject, JoinConfig.class); } else if (queryInputType.equalsIgnoreCase(QueryInputType.PATTERN.toString()) || queryInputType.equalsIgnoreCase(QueryInputType.SEQUENCE.toString())) { return jsonDeserializationContext.deserialize(jsonObject, PatternSequenceConfig.class); }/*from ww w .java 2 s .c o m*/ throw new JsonParseException("Unable to de-serialize the QueryInputConfig JSON since its type is unknown"); }
From source file:org.wso2.carbon.siddhi.editor.core.util.designview.deserializers.types.QueryOutputConfigDeSerializer.java
License:Open Source License
@Override public Object deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) { JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonObject.get(TYPE); if (jsonPrimitive == null) { throw new JsonParseException("Unable to find type of the QueryOutputConfig"); }// ww w .j av a 2 s .c om String queryOutputType = jsonPrimitive.getAsString(); if (jsonObject.get(TARGET) == null) { return null; } String target = jsonObject.get(TARGET).getAsString(); if (queryOutputType.equalsIgnoreCase(QueryOutputType.INSERT.toString())) { return new QueryOutputConfig(queryOutputType, jsonDeserializationContext.deserialize(jsonObject.get(OUTPUT), InsertOutputConfig.class), target); } else if (queryOutputType.equalsIgnoreCase(QueryOutputType.UPDATE.toString())) { return new QueryOutputConfig(queryOutputType, jsonDeserializationContext .deserialize(jsonObject.get(OUTPUT), UpdateInsertIntoOutputConfig.class), target); } else if (queryOutputType.equalsIgnoreCase(QueryOutputType.UPDATE_OR_INSERT_INTO.toString())) { return new QueryOutputConfig(queryOutputType, jsonDeserializationContext .deserialize(jsonObject.get(OUTPUT), UpdateInsertIntoOutputConfig.class), target); } else if (queryOutputType.equalsIgnoreCase(QueryOutputType.DELETE.toString())) { return new QueryOutputConfig(queryOutputType, jsonDeserializationContext.deserialize(jsonObject.get(OUTPUT), DeleteOutputConfig.class), target); } throw new JsonParseException("Unable to de-serialize the QueryOutputConfig JSON since its type is unknown"); }
From source file:org.wso2.carbon.siddhi.editor.core.util.designview.deserializers.types.StreamHandlerConfigDeserializer.java
License:Open Source License
@Override public Object deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) { JsonObject jsonObject = jsonElement.getAsJsonObject(); JsonPrimitive jsonPrimitive = (JsonPrimitive) jsonObject.get(TYPE); String streamHandlerType = jsonPrimitive.getAsString(); if (streamHandlerType.equalsIgnoreCase(StreamHandlerType.FILTER.toString())) { return jsonDeserializationContext.deserialize(jsonObject, FilterConfig.class); } else if (streamHandlerType.equalsIgnoreCase(StreamHandlerType.FUNCTION.toString()) || streamHandlerType.equalsIgnoreCase(StreamHandlerType.WINDOW.toString())) { return jsonDeserializationContext.deserialize(jsonObject, FunctionWindowConfig.class); }/*from w w w . ja v a 2 s . c o m*/ throw new JsonParseException( "Unable to de-serialize the StreamHandlerConfig JSON since its type is unknown"); }
From source file:org.xacml4j.v30.marshal.json.CategoryAdapter.java
License:Open Source License
@Override public Category deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { try {/*from w ww . j a v a 2s . c o m*/ JsonObject o = json.getAsJsonObject(); String categoryId = GsonUtil.getAsString(o, JsonProperties.CATEGORY_ID_PROPERTY, null); Preconditions.checkState(categoryId != null); CategoryId category = SHORT_NAMES.get(categoryId); category = (category == null) ? Categories.parse(categoryId) : category; String id = GsonUtil.getAsString(o, JsonProperties.ID_PROPERTY, null); Collection<Attribute> attr = context.deserialize(o.getAsJsonArray(JsonProperties.ATTRIBUTE_PROPERTY), new TypeToken<Collection<Attribute>>() { }.getType()); Node content = DOMUtil.stringToNode(GsonUtil.getAsString(o, JsonProperties.CONTENT_PROPERTY, null)); return Category.builder(category).id(id) .entity(Entity.builder().attributes(attr).content(content).build()).build(); } catch (XacmlSyntaxException e) { throw new JsonParseException(e); } }
From source file:org.xacml4j.v30.marshal.json.ObligationOrAdviceAdapter.java
License:Open Source License
@Override public BaseDecisionRuleResponse deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject o = json.getAsJsonObject(); String id = checkNotNull(GsonUtil.getAsString(o, ID_PROPERTY, null)); Collection<AttributeAssignment> attributeAssignments = context .deserialize(o.get(ATTRIBUTE_ASSIGNMENTS_PROPERTY), ATTRIBUTE_ASSIGNMENTS_TYPE); if (typeOfT == Obligation.class) { Obligation.Builder builder = Obligation.builder(id); return attributeAssignments != null ? builder.attributes(attributeAssignments).build() : builder.build();/*from w w w . j a v a 2 s . c o m*/ } else if (typeOfT == Advice.class) { Advice.Builder builder = Advice.builder(id); return attributeAssignments != null ? builder.attributes(attributeAssignments).build() : builder.build(); } else { throw new IllegalArgumentException(String.format("Invalid type: %s", typeOfT)); } }
From source file:org.xacml4j.v30.marshal.json.RequestContextAdapter.java
License:Open Source License
@Override public RequestContext deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject o = json.getAsJsonObject(); boolean returnPolicyIdList = GsonUtil.getAsBoolean(o, RETURN_POLICY_ID_LIST_PROPERTY, false); boolean combinedDecision = GsonUtil.getAsBoolean(o, COMBINED_DECISION_PROPERTY, false); JsonArray array = o.getAsJsonArray(JsonProperties.CATEGORY_ARRAY_NAME); Preconditions.checkState(array != null); Collection<Category> attributes = context.deserialize(array, new TypeToken<Collection<Category>>() { }.getType());/*from ww w. ja va 2 s.c o m*/ Collection<RequestReference> reqRefs = ImmutableList.of(); JsonObject multiRequests = o.getAsJsonObject(MULTI_REQUESTS_PROPERTY); if (multiRequests != null) { reqRefs = context.deserialize(multiRequests.getAsJsonArray(REQUEST_REFERENCE_PROPERTY), new TypeToken<Collection<RequestReference>>() { }.getType()); } return RequestContext.builder().returnPolicyIdList(returnPolicyIdList).combineDecision(combinedDecision) .attributes(attributes).reference(reqRefs).build(); }
From source file:org.xacml4j.v30.marshal.json.RequestReferenceAdapter.java
License:Open Source License
@Override public RequestReference deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject o = json.getAsJsonObject(); Collection<CategoryReference> refs = context.deserialize(o.getAsJsonArray(REFERENCE_ID_PROPERTY), new TypeToken<Collection<CategoryReference>>() { }.getType());//from w ww .j av a 2 s.co m return RequestReference.builder().reference(refs).build(); }
From source file:org.xacml4j.v30.marshal.json.ResponseContextAdapter.java
License:Open Source License
@Override public ResponseContext deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject o = json.getAsJsonObject(); Collection<Result> r = context.deserialize(o.get(RESULT_PROPERTY), RESULTS_TYPE); return ResponseContext.builder().results(r).build(); }
From source file:org.xacml4j.v30.marshal.json.ResultAdapter.java
License:Open Source License
@Override public Result deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject o = json.getAsJsonObject(); final String decisionValue = GsonUtil.getAsString(o, DECISION_PROPERTY, null); Decision decision = DECISION_VALUE_MAP.inverse().get(decisionValue); if (decision == null) { throw new JsonParseException(String.format("Invalid 'Decision' value: \"%s\"", decisionValue)); }//w w w .j a v a 2s.c om Status status = context.deserialize(o.get(STATUS_PROPERTY), Status.class); Result.Builder builder = Result.builder(decision, status); Collection<Obligation> obligations = context.deserialize(o.get(OBLIGATIONS_PROPERTY), OBLIGATIONS_TYPE); if (obligations != null) { checkArgument(!obligations.isEmpty(), "At least one obligation should be specified."); builder.obligation(obligations); } Collection<Advice> advice = context.deserialize(o.get(ASSOCIATED_ADVICE_PROPERTY), ADVICE_TYPE); if (advice != null) { checkArgument(!advice.isEmpty(), "At least one advice should be specified."); builder.advice(advice); } Collection<Category> attributes = context.deserialize(o.get(ATTRIBUTES_PROPERTY), ATTRIBUTES_TYPE); if (attributes != null) { builder.includeInResultAttr(attributes); } deserializePolicyIdentifiers(o, context, builder); return builder.build(); }
From source file:org.xacml4j.v30.marshal.json.ResultAdapter.java
License:Open Source License
private void deserializePolicyIdentifiers(JsonObject o, JsonDeserializationContext context, Result.Builder builder) { JsonObject jsonPolicyIdentifiers = o.getAsJsonObject(POLICY_IDENTIFIER_PROPERTY); if (jsonPolicyIdentifiers != null) { Collection<PolicyIDReference> policyIdReferences = context.deserialize( jsonPolicyIdentifiers.get(POLICY_ID_REFERENCE_PROPERTY), POLICY_ID_REFERENCES_TYPE); if (policyIdReferences != null) { builder.evaluatedPolicies(policyIdReferences); }/*from ww w . j a v a 2 s . c o m*/ Collection<PolicySetIDReference> policySetIdReferences = context.deserialize( jsonPolicyIdentifiers.get(POLICY_SET_ID_REFERENCE_PROPERTY), POLICY_SET_ID_REFERENCES_TYPE); if (policySetIdReferences != null) { builder.evaluatedPolicies(policySetIdReferences); } } }