use of com.google.gson.JsonParseException in project maple-ir by LLVM-but-worse.
the class FieldInsnNodeSerializer method deserialize.
@Override
public FieldInsnNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
int opcode;
String owner = null, name = null, desc = null;
JsonObject object = (JsonObject) json;
opcode = object.get("opcode").getAsInt();
owner = object.get("owner").getAsString();
name = object.get("name").getAsString();
desc = object.get("desc").getAsString();
if (owner == null || name == null || desc == null)
throw new JsonParseException("Could not parse FieldInsnNode");
return new FieldInsnNode(opcode, owner, name, desc);
}
use of com.google.gson.JsonParseException in project cosmic by MissionCriticalCloud.
the class RoutingConfigAdapter method deserialize.
@Override
public RoutingConfig deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext context) throws JsonParseException {
final JsonObject jsonObject = jsonElement.getAsJsonObject();
if (!jsonObject.has("type")) {
throw new JsonParseException("Deserializing as a RoutingConfig, but no type present in the json object");
}
final String routingConfigType = jsonObject.get("type").getAsString();
if (SINGLE_DEFAULT_ROUTE_IMPLICIT_ROUTING_CONFIG.equals(routingConfigType)) {
return context.deserialize(jsonElement, SingleDefaultRouteImplicitRoutingConfig.class);
} else if (ROUTING_TABLE_ROUTING_CONFIG.equals(routingConfigType)) {
return context.deserialize(jsonElement, RoutingTableRoutingConfig.class);
}
throw new JsonParseException("Failed to deserialize type \"" + routingConfigType + "\"");
}
use of com.google.gson.JsonParseException in project cosmic by MissionCriticalCloud.
the class NatRuleAdapter method deserialize.
@Override
public NatRule deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext context) throws JsonParseException {
final JsonObject jsonObject = jsonElement.getAsJsonObject();
if (!jsonObject.has("type")) {
throw new JsonParseException("Deserializing as a NatRule, but no type present in the json object");
}
final String natRuleType = jsonObject.get("type").getAsString();
if ("SourceNatRule".equals(natRuleType)) {
return context.deserialize(jsonElement, SourceNatRule.class);
} else if ("DestinationNatRule".equals(natRuleType)) {
return context.deserialize(jsonElement, DestinationNatRule.class);
}
throw new JsonParseException("Failed to deserialize type \"" + natRuleType + "\"");
}
use of com.google.gson.JsonParseException in project hub-alert by blackducksoftware.
the class DistributionJobDetailsModelJsonAdapterTest method deserializeThrowsJsonParseExceptionTest.
@Test
public void deserializeThrowsJsonParseExceptionTest() {
String testFieldValue = "a value";
DistributionJobDetailsModel baseModel = new Test_DistributionJobDetailsModel(testFieldValue);
JsonElement jsonElement = gson.toJsonTree(baseModel);
DistributionJobDetailsModelJsonAdapter deserializer = new DistributionJobDetailsModelJsonAdapter();
try {
deserializer.deserialize(jsonElement, DistributionJobDetailsModel.class, jsonDeserializationContext);
fail("Expected exception: " + JsonParseException.class);
} catch (JsonParseException e) {
// Success
}
}
use of com.google.gson.JsonParseException in project java-crud-api by kolchagov.
the class TestApi method getMockHttpServletRequest.
private MockHttpServletRequest getMockHttpServletRequest() throws UnsupportedEncodingException {
final MockHttpServletRequest req = new MockHttpServletRequest();
req.setServerName("localhost");
req.setMethod(method);
final UriComponents build = UriComponentsBuilder.fromUriString(this.baseUrl).build();
req.setPathInfo(build.getPath());
req.setQueryString(build.getQuery());
setParamsFromBuild(req, build);
if (data != null) {
try {
if (data.endsWith("__is_null"))
throw new JsonParseException("");
// invalid json test expects json content
if (!"{\"}".equals(data)) {
parser.parse(data);
}
req.setContentType("application/json");
} catch (JsonParseException ignored) {
req.setContentType("application/x-www-form-urlencoded");
final String url = "/?" + URLDecoder.decode(data, "utf8");
setParamsFromBuild(req, UriComponentsBuilder.fromUriString(url).build());
}
req.setContent(data.getBytes("utf8"));
}
return req;
}
Aggregations