use of com.google.gson.JsonSyntaxException in project lite-apps by chimbori.
the class TagsCollector method updateTagsJson.
public static void updateTagsJson() throws IOException {
Gson gson = GsonInstance.getPrettyPrinter();
// Read the list of all known tags from the tags.json file. In case we discover any new tags,
// we will add them to this file, taking care not to overwrite those that already exist.
LibraryTagsList tagsGson = LibraryTagsList.fromGson(gson, new FileReader(FilePaths.LITE_APPS_TAGS_JSON));
Map<String, LibraryTag> globalTags = new HashMap<>();
File[] liteAppDirs = FilePaths.LITE_APPS_SRC_DIR.listFiles();
for (File liteAppDirectory : liteAppDirs) {
if (!liteAppDirectory.isDirectory()) {
// Probably a temporary file, like .DS_Store.
continue;
}
File manifestJsonFile = new File(liteAppDirectory, FilePaths.MANIFEST_JSON_FILE_NAME);
if (!manifestJsonFile.exists()) {
throw new MissingManifestException(liteAppDirectory.getName());
}
Manifest manifest;
try {
manifest = gson.fromJson(new FileReader(manifestJsonFile), Manifest.class);
} catch (JsonSyntaxException e) {
System.err.println("Failed to parse JSON: " + liteAppDirectory.getName());
throw e;
}
// For all tags applied to this manifest, check if they exist in the global tags list.
if (manifest.tags != null) {
for (String tagName : manifest.tags) {
LibraryTag tag = globalTags.get(tagName);
if (tag == null) {
// If this is the first time we are seeing this tag, create a new JSONArray to hold its contents.
LibraryTag newTag = new LibraryTag(tagName);
globalTags.put(tagName, newTag);
tagsGson.addTag(newTag);
}
}
}
}
// Write the tags to JSON
FileUtils.writeFile(FilePaths.LITE_APPS_TAGS_JSON, tagsGson.toJson(gson));
}
use of com.google.gson.JsonSyntaxException in project coastal-hazards by USGS-CIDA.
the class MetadataResource method getMetadataSummaryByAttribtueUsingItemID.
@GET
@Path("/summarize/itemid/{itemid}/attribute/{attr}")
@Produces(MediaType.APPLICATION_JSON)
public Response getMetadataSummaryByAttribtueUsingItemID(@PathParam("itemid") String itemId, @PathParam("attr") String attr) throws URISyntaxException {
Response response;
try (ItemManager itemManager = new ItemManager()) {
Item item = itemManager.load(itemId);
String jsonSummary = MetadataUtil.getSummaryFromWPS(getMetadataUrl(item), attr);
Summary summary = GsonUtil.getDefault().fromJson(jsonSummary, Summary.class);
response = Response.ok(GsonUtil.getDefault().toJson(summary, Summary.class), MediaType.APPLICATION_JSON_TYPE).build();
} catch (IOException | ParserConfigurationException | SAXException | JsonSyntaxException ex) {
Map<String, String> err = new HashMap<>();
err.put("message", ex.getMessage());
response = Response.serverError().entity(GsonUtil.getDefault().toJson(err, HashMap.class)).build();
}
return response;
}
use of com.google.gson.JsonSyntaxException in project edx-app-android by edx.
the class ISO8601DateTypeAdapter method read.
@Override
@NonNull
public Date read(final JsonReader in) throws IOException {
final String date = in.nextString();
final ParsePosition parsePosition = new ParsePosition(0);
try {
return ISO8601Utils.parse(date, parsePosition);
} catch (ParseException e) {
throw new JsonSyntaxException(date, e);
}
}
use of com.google.gson.JsonSyntaxException in project edx-app-android by edx.
the class LoginAPI method register.
@NonNull
private void register(Bundle parameters) throws Exception {
final Map<String, String> parameterMap = new HashMap<>();
for (String key : parameters.keySet()) {
parameterMap.put(key, parameters.getString(key));
}
Response<ResponseBody> response = loginService.register(parameterMap).execute();
if (!response.isSuccessful()) {
final int errorCode = response.code();
final String errorBody = response.errorBody().string();
if ((errorCode == HttpStatus.BAD_REQUEST || errorCode == HttpStatus.CONFLICT) && !android.text.TextUtils.isEmpty(errorBody)) {
try {
final FormFieldMessageBody body = gson.fromJson(errorBody, FormFieldMessageBody.class);
if (body != null && body.size() > 0) {
throw new RegistrationException(body);
}
} catch (JsonSyntaxException ex) {
// Looks like the response does not contain form validation errors.
}
}
throw new HttpStatusException(response);
}
}
use of com.google.gson.JsonSyntaxException in project java-sdk by watson-developer-cloud.
the class CredentialUtils method getVCAPServices.
/**
* Gets the <b>VCAP_SERVICES</b> environment variable and return it as a {@link JsonObject}.
*
* @return the VCAP_SERVICES as a {@link JsonObject}.
*/
private static JsonObject getVCAPServices() {
final String envServices = services != null ? services : System.getenv(VCAP_SERVICES);
if (envServices == null) {
return null;
}
JsonObject vcapServices = null;
try {
final JsonParser parser = new JsonParser();
vcapServices = (JsonObject) parser.parse(envServices);
} catch (final JsonSyntaxException e) {
log.log(Level.INFO, "Error parsing VCAP_SERVICES", e);
}
return vcapServices;
}
Aggregations