List of usage examples for com.google.gson JsonParseException JsonParseException
public JsonParseException(String msg, Throwable cause)
From source file:com.googlesource.gerrit.plugins.hooks.rtc.workitems.RtcWorkItemDeserializer.java
License:Apache License
private RtcEntity extractResource(JsonObject root, final String memberName, final Class<RtcEntity> clazz) { String url = extractRdfResourceUrl(root, memberName); try {// ww w . j a va2s . c om return factory.get(url, clazz); } catch (IOException e) { throw new JsonParseException("Unable to parse resource from url " + url + " using class " + clazz, e); } }
From source file:com.microsoft.aad.adal.TokenCacheItemSerializationAdapater.java
License:Open Source License
@Override public TokenCacheItem deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { final JsonObject srcJsonObj = json.getAsJsonObject(); throwIfParameterMissing(srcJsonObj, OAuth2.AUTHORITY); throwIfParameterMissing(srcJsonObj, OAuth2.ID_TOKEN); throwIfParameterMissing(srcJsonObj, OAuth2.ADAL_CLIENT_FAMILY_ID); throwIfParameterMissing(srcJsonObj, OAuth2.REFRESH_TOKEN); final String rawIdToken = srcJsonObj.get(OAuth2.ID_TOKEN).getAsString(); final TokenCacheItem tokenCacheItem = new TokenCacheItem(); final IdToken idToken; try {/* w w w .ja v a 2 s . c om*/ idToken = new IdToken(rawIdToken); } catch (AuthenticationException e) { throw new JsonParseException(TAG + ": Could not deserialize into a tokenCacheItem object", e); } final UserInfo userInfo = new UserInfo(idToken); tokenCacheItem.setUserInfo(userInfo); tokenCacheItem.setTenantId(idToken.getTenantId()); tokenCacheItem.setAuthority(srcJsonObj.get(OAuth2.AUTHORITY).getAsString()); tokenCacheItem.setIsMultiResourceRefreshToken(true); tokenCacheItem.setRawIdToken(rawIdToken); tokenCacheItem.setFamilyClientId(srcJsonObj.get(OAuth2.ADAL_CLIENT_FAMILY_ID).getAsString()); tokenCacheItem.setRefreshToken(srcJsonObj.get(OAuth2.REFRESH_TOKEN).getAsString()); return tokenCacheItem; }
From source file:es.us.isa.aml.parsers.agreements.json.InterfaceAdapterExpression.java
License:Open Source License
private Expression deserializeInternal(JsonElement json, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); String type = jsonObject.get("_type").getAsString(); JsonElement element = jsonObject.get("properties"); Gson gson = new Gson(); try {/* w ww . j a v a 2 s. c o m*/ switch (type) { case "DuringExpression": DuringExpression exp = context.deserialize(element, Class.forName("es.us.isa.aml.model.expression." + type)); exp.setState( deserializeInternal(jsonObject.get("properties").getAsJsonObject().get("state"), context)); exp.setNum(deserializeInternal(jsonObject.get("properties").getAsJsonObject().get("num"), context)); return exp; case "FrecuencyExpression": FrecuencyExpression exp2 = context.deserialize(element, Class.forName("es.us.isa.aml.model.expression." + type)); exp2.setState( deserializeInternal(jsonObject.get("properties").getAsJsonObject().get("state"), context)); exp2.setNtimes( deserializeInternal(jsonObject.get("properties").getAsJsonObject().get("ntimes"), context)); return exp2; case "Atomic": return new Atomic(jsonObject.get("properties").getAsJsonObject().get("value").getAsNumber()); case "Var": return new Var(jsonObject.get("properties").getAsJsonObject().get("id").getAsString()); case "ArithmeticExpression": Expression ae1 = deserializeInternal(jsonObject.get("properties").getAsJsonObject().get("exp1"), context); Expression ae2 = deserializeInternal(jsonObject.get("properties").getAsJsonObject().get("exp2"), context); ArithmeticOperator ao = gson.fromJson( jsonObject.get("properties").getAsJsonObject().get("operator"), ArithmeticOperator.class); ArithmeticExpression expA = new ArithmeticExpression(ae1, ae2, ao); return expA; case "AssignmentExpression": AssignmentExpression expAss = context.deserialize(element, Class.forName("es.us.isa.aml.model.expression." + type)); expAss.setExpression1( deserializeInternal(jsonObject.get("properties").getAsJsonObject().get("exp1"), context)); expAss.setExpression2( deserializeInternal(jsonObject.get("properties").getAsJsonObject().get("exp2"), context)); return expAss; case "LogicalExpression": Expression le1 = deserializeInternal(jsonObject.get("properties").getAsJsonObject().get("exp1"), context); Expression le2 = deserializeInternal(jsonObject.get("properties").getAsJsonObject().get("exp2"), context); LogicalOperator lo = gson.fromJson(jsonObject.get("properties").getAsJsonObject().get("operator"), LogicalOperator.class); LogicalExpression expL = new LogicalExpression(le1, le2, lo); return expL; case "RelationalExpression": Expression re1 = deserializeInternal(jsonObject.get("properties").getAsJsonObject().get("exp1"), context); Expression re2 = deserializeInternal(jsonObject.get("properties").getAsJsonObject().get("exp2"), context); RelationalOperator ro = gson.fromJson( jsonObject.get("properties").getAsJsonObject().get("operator"), RelationalOperator.class); RelationalExpression expR = new RelationalExpression(re1, re2, ro); return expR; case "ParenthesisExpression": ParenthesisExpression expP = context.deserialize(element, Class.forName("es.us.isa.aml.model.expression." + type)); expP.setExpression( deserializeInternal(jsonObject.get("properties").getAsJsonObject().get("exp"), context)); return expP; default: return context.deserialize(element, Class.forName("es.us.isa.aml.model.expression." + type)); } } catch (ClassNotFoundException cnfe) { LOGGER.log(Level.SEVERE, cnfe.getMessage()); throw new JsonParseException("Unknown element type: " + type, cnfe); } }
From source file:fr.itinerennes.api.client.gson.DateTypeAdapter.java
License:Open Source License
@Override public Date deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { final String value = json.getAsString(); try {/*from w ww .j av a 2 s .c om*/ return dateFormatter.parse(value); } catch (final ParseException e) { final String msg = String.format("Can't parse date value %s", value); throw new JsonParseException(msg, e); } }
From source file:fr.itinerennes.api.client.gson.TimeTypeAdapter.java
License:Open Source License
@Override public Time deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { final String value = json.getAsString(); try {//from www.j a v a 2 s .co m return Time.from(value); } catch (ParseException e) { final String msg = String.format("Can't parse time value %s", value); throw new JsonParseException(msg, e); } }
From source file:io.datakernel.cube.api.ReportingQueryResponseDeserializer.java
License:Apache License
private List<Map<String, Object>> deserializeRecords(JsonArray jsonRecords) { List<Map<String, Object>> records = new ArrayList<>(); for (JsonElement jsonRecordElement : jsonRecords) { JsonObject jsonRecord = jsonRecordElement.getAsJsonObject(); Map<String, Object> record = new LinkedHashMap<>(); for (Map.Entry<String, JsonElement> jsonRecordEntry : jsonRecord.entrySet()) { String property = jsonRecordEntry.getKey(); JsonElement propertyValue = jsonRecordEntry.getValue(); KeyType keyType = structure.getKeyType(property); if (keyType != null) { try { record.put(property, keyType.fromString(propertyValue.getAsString())); } catch (ParseException e) { throw new JsonParseException("Could not parse value of property '" + property + "'", e); }/*from w ww . jav a 2 s . c o m*/ } else if (structure.containsField(property) || reportingConfiguration.containsComputedMeasure(property)) record.put(property, propertyValue.getAsNumber()); else if (reportingConfiguration.containsAttribute(property)) record.put(property, propertyValue.getAsString()); else throw new JsonParseException("Unknown property '" + property + "' in record"); } records.add(record); } return records; }
From source file:io.hawkcd.agent.utilities.deserializers.TaskDefinitionAdapter.java
License:Apache License
@Override public TaskDefinition deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonObject jsonObject = json.getAsJsonObject(); String type = jsonObject.get("type").getAsString(); try {//from www . jav a 2 s. c om if (type.equals("EXEC")) { return context.deserialize(jsonObject, ExecTask.class); } else if (type.equals("UPLOAD_ARTIFACT")) { return context.deserialize(jsonObject, UploadArtifactTask.class); } else if (type.equals("FETCH_MATERIAL")) { return context.deserialize(jsonObject, FetchMaterialTask.class); } else if (type.equals("FETCH_ARTIFACT")) { return context.deserialize(jsonObject, FetchArtifactTask.class); } return context.deserialize(jsonObject, Class.forName("com.googlecode.whiteboard.model." + type)); } catch (ClassNotFoundException cnfe) { throw new JsonParseException("Unknown element type: " + type, cnfe); } }
From source file:io.motown.operatorapi.json.gson.deserializer.AddressTypeAdapterDeserializer.java
License:Apache License
@Override public Address deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) { JsonObject obj;/* ww w .j a v a2s . c o m*/ try { obj = jsonElement.getAsJsonObject(); if (obj == null) { return null; } } catch (ClassCastException | IllegalStateException e) { throw new JsonParseException("Address must be a JSON object", e); } String addressLine1 = obj.getAsJsonPrimitive("addressLine1").getAsString(); String city = obj.getAsJsonPrimitive("city").getAsString(); String country = obj.getAsJsonPrimitive("country").getAsString(); JsonPrimitive addressLine2Obj = obj.getAsJsonPrimitive("addressLine2"), postalCodeObj = obj.getAsJsonPrimitive("postalCode"), regionObj = obj.getAsJsonPrimitive("region"); String addressLine2 = addressLine2Obj != null ? addressLine2Obj.getAsString() : ""; String postalCode = postalCodeObj != null ? postalCodeObj.getAsString() : ""; String region = regionObj != null ? regionObj.getAsString() : ""; return new Address(addressLine1, addressLine2, postalCode, city, region, country); }
From source file:io.motown.operatorapi.json.gson.deserializer.CoordinatesTypeAdapterDeserializer.java
License:Apache License
@Override public Coordinates deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) { JsonObject obj;/*www.ja v a 2 s .c o m*/ try { obj = jsonElement.getAsJsonObject(); if (obj == null) { return null; } } catch (ClassCastException | IllegalStateException e) { throw new JsonParseException("Coordinates must be a JSON object", e); } double latitude = obj.getAsJsonPrimitive("latitude").getAsDouble(); double longitude = obj.getAsJsonPrimitive("longitude").getAsDouble(); return new Coordinates(latitude, longitude); }
From source file:io.motown.operatorapi.json.gson.deserializer.OpeningTimeTypeAdapterDeserializer.java
License:Apache License
@Override public OpeningTime deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) { JsonObject obj;//from w ww. j av a 2s .com try { obj = jsonElement.getAsJsonObject(); if (obj == null) { return null; } } catch (ClassCastException | IllegalStateException e) { throw new JsonParseException("OpeningTime must be a valid JSON object", e); } Day day = Day.fromValue(obj.getAsJsonPrimitive("day").getAsString()); String timeStartStr = obj.getAsJsonPrimitive("timeStart").getAsString(); String timeStopStr = obj.getAsJsonPrimitive("timeStop").getAsString(); TimeOfDay timeStart; TimeOfDay timeStop; Matcher start = TIME_OF_DAY.matcher(timeStartStr); Matcher stop = TIME_OF_DAY.matcher(timeStopStr); if (start.matches() && stop.matches()) { timeStart = new TimeOfDay(Integer.parseInt(start.group(HOUR_GROUP)), Integer.parseInt(start.group(MINUTES_GROUP))); timeStop = new TimeOfDay(Integer.parseInt(stop.group(HOUR_GROUP)), Integer.parseInt(stop.group(MINUTES_GROUP))); } else { throw new JsonParseException("timeStart and timeStop must be a valid 24-hour time (00:00 - 23:59)"); } return new OpeningTime(day, timeStart, timeStop); }