List of usage examples for com.google.gson JsonPrimitive getAsString
@Override
public String getAsString()
From source file:org.wso2.carbon.identity.cloud.sample.JWTProcessor.java
License:Open Source License
public Map process(String jwtToken) { jwtDetails = new HashMap<String, String>(); JsonToken token = deserialize(jwtToken); // JsonObject header = token.getHeader(); JsonObject claims = token.getPayloadAsJsonObject(); Set<Map.Entry<String, JsonElement>> claimSet = claims.entrySet(); for (Map.Entry e : claimSet) { if (e.getValue() instanceof JsonPrimitive) { JsonPrimitive primitive = (JsonPrimitive) e.getValue(); jwtDetails.put(e.getKey().toString(), primitive.getAsString()); }//from w w w . j a v a2s.co m } System.out.println("Claims : " + jwtDetails); return jwtDetails; }
From source file:org.wso2.carbon.registry.extensions.handlers.utils.RESTServiceUtils.java
License:Open Source License
/** * Returns a Json element as a string//from www .ja va 2 s .c o m * * @param object json Object * @param key element key * @return Element value */ private static String getChildElementText(JsonObject object, String key) { JsonElement element = object.get(key); if (element != null && element.isJsonArray()) { if (((JsonArray) element).size() == 1) { return object.get(key).getAsString(); } else { StringBuffer sb = new StringBuffer(); JsonArray elements = (JsonArray) object.get(key); for (int i = 0; i < elements.size(); i++) { JsonPrimitive ob = (JsonPrimitive) elements.get(i); sb.append(ob.getAsString()); if (i < elements.size() - 1) { sb.append(","); } } return sb.toString(); } } else if (element != null && (element.isJsonObject() || element.isJsonPrimitive())) { return object.get(key).getAsString(); } return null; }
From source file:org.wso2.carbon.siddhi.editor.core.util.designview.deserializers.types.AggregateByTimePeriodDeSerializer.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 attributesSelectionType = jsonPrimitive.getAsString(); if (attributesSelectionType.equalsIgnoreCase(AggregationByTimeType.RANGE.toString())) { return jsonDeserializationContext.deserialize(jsonObject, AggregateByTimeRange.class); } else if (attributesSelectionType.equalsIgnoreCase(AggregationByTimeType.INTERVAL.toString())) { return jsonDeserializationContext.deserialize(jsonObject, AggregateByTimeInterval.class); }/*from w w w. ja v a 2 s .c o m*/ throw new JsonParseException( "Unable to de-serialize the AggregateByTimePeriod JSON since its type is unknown"); }
From source file:org.wso2.carbon.siddhi.editor.core.util.designview.deserializers.types.AttributesSelectionConfigDeSerializer.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 attributesSelectionType = jsonPrimitive.getAsString(); if (attributesSelectionType.equalsIgnoreCase(AttributeSelection.TYPE_USER_DEFINED)) { return jsonDeserializationContext.deserialize(jsonObject, UserDefinedSelectionConfig.class); } else if (attributesSelectionType.equalsIgnoreCase(AttributeSelection.TYPE_ALL)) { return jsonDeserializationContext.deserialize(jsonObject, AllSelectionConfig.class); }//from ww w .j a v a2 s .co m throw new JsonParseException( "Unable to de-serialize the AttributesSelectionConfig JSON since its type is unknown"); }
From source file:org.wso2.carbon.siddhi.editor.core.util.designview.deserializers.types.MapperPayloadOrAttributeDeserializer.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 mapperAttributeType = jsonPrimitive.getAsString(); if (mapperAttributeType.equalsIgnoreCase(MapperPayloadOrAttributeType.LIST.toString())) { return jsonDeserializationContext.deserialize(jsonObject, MapperListPayloadOrAttribute.class); } else if (mapperAttributeType.equalsIgnoreCase(MapperPayloadOrAttributeType.MAP.toString())) { return jsonDeserializationContext.deserialize(jsonObject, MapperMapPayloadOrAttribute.class); }/* w w w.ja v a2 s . c om*/ throw new JsonParseException( "Unable to de-serialize the Mapper Attribute/Payload JSON since its type is unknown"); }
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); }/* w w w . j av a 2s . co 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"); }/*from w w w. java 2 s .co m*/ 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 a2s .c o m*/ throw new JsonParseException( "Unable to de-serialize the StreamHandlerConfig JSON since its type is unknown"); }
From source file:org.wso2.developerstudio.datamapper.diagram.schemagen.util.SchemaBuilder.java
License:Open Source License
private static TypeEnum RealTypeOf(JsonElement element) { if (element == null || element.isJsonNull()) { return TypeEnum.NULL; } else if (element.isJsonArray()) { return TypeEnum.ARRAY; } else if (element.isJsonObject()) { return TypeEnum.OBJECT; } else if (element.isJsonPrimitive()) { JsonPrimitive p = element.getAsJsonPrimitive(); if (p.isNumber()) { return TypeEnum.NUMBER; } else if (p.isBoolean()) { return TypeEnum.BOOLEAN; } else if (p.isString()) { String value = p.getAsString(); if (StringUtils.isNotEmpty(value)) { return TypeEnum.STRING; } else { return TypeEnum.NULL; }/*from w ww . j av a 2s.c o m*/ } } return TypeEnum.UNDEFINED; }
From source file:org.xacml4j.v30.marshal.json.GsonUtil.java
License:Open Source License
public static String getAsString(JsonObject o, String memberName, String defaultValue) { JsonPrimitive v = o.getAsJsonPrimitive(memberName); return (v != null) ? v.getAsString() : defaultValue; }