use of com.fasterxml.jackson.databind.JsonMappingException in project druid by druid-io.
the class QueryGranularityTest method testSerializeDuration.
@Test
public void testSerializeDuration() throws Exception {
ObjectMapper mapper = new DefaultObjectMapper();
String json = "{ \"type\": \"duration\", \"duration\": \"3600000\" }";
Granularity gran = mapper.readValue(json, Granularity.class);
Assert.assertEquals(new DurationGranularity(3600000, null), gran);
json = "{ \"type\": \"duration\", \"duration\": \"5\", \"origin\": \"2012-09-01T00:00:00.002Z\" }";
gran = mapper.readValue(json, Granularity.class);
Assert.assertEquals(new DurationGranularity(5, 2), gran);
DurationGranularity expected = new DurationGranularity(5, 2);
Assert.assertEquals(expected, mapper.readValue(mapper.writeValueAsString(expected), Granularity.class));
String illegalJson = "{ \"type\": \"duration\", \"duration\": \"0\" }";
try {
mapper.readValue(illegalJson, Granularity.class);
Assert.fail();
} catch (JsonMappingException e) {
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project moco by dreamhead.
the class CollectionReader method read.
public <T> ImmutableList<T> read(final InputStream is, final Class<T> elementClass) {
try {
CollectionType type = factory.constructCollectionType(List.class, elementClass);
List<T> sessionSettings = mapper.readValue(is, type);
return copyOf(sessionSettings);
} catch (UnrecognizedPropertyException e) {
logger.info("Unrecognized field: {}", e.getMessage());
throw new RuntimeException(format("Unrecognized field [ %s ], please check!", e.getPropertyName()));
} catch (JsonMappingException e) {
logger.info("{} {}", e.getMessage(), e.getPathReference());
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
closeQuietly(is);
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project hadoop by apache.
the class RemoteSASKeyGenerationResponse method makeRemoteRequest.
/**
* Helper method to make a remote request.
* @param uri - Uri to use for the remote request
* @return RemoteSASKeyGenerationResponse
*/
private RemoteSASKeyGenerationResponse makeRemoteRequest(URI uri) throws SASKeyGenerationException {
try {
String responseBody = remoteCallHelper.makeRemoteGetRequest(new HttpGet(uri));
ObjectMapper objectMapper = new ObjectMapper();
return objectMapper.readValue(responseBody, RemoteSASKeyGenerationResponse.class);
} catch (WasbRemoteCallException remoteCallEx) {
throw new SASKeyGenerationException("Encountered RemoteCallException" + " while retrieving SAS key from remote service", remoteCallEx);
} catch (JsonParseException jsonParserEx) {
throw new SASKeyGenerationException("Encountered JsonParseException " + "while parsing the response from remote" + " service into RemoteSASKeyGenerationResponse object", jsonParserEx);
} catch (JsonMappingException jsonMappingEx) {
throw new SASKeyGenerationException("Encountered JsonMappingException" + " while mapping the response from remote service into " + "RemoteSASKeyGenerationResponse object", jsonMappingEx);
} catch (IOException ioEx) {
throw new SASKeyGenerationException("Encountered IOException while " + "accessing remote service to retrieve SAS Key", ioEx);
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project OpenAM by OpenRock.
the class SubjectTypesResource method jsonify.
/**
* Transforms a subclass of {@link EntitlementSubject} in to a JsonSchema representation.
* This schema is then combined with the Subject's name (taken as the resourceId) and all this is
* compiled together into a new {@link JsonValue} object until "title" and "config" fields respectively.
*
* @param subjectClass The class whose schema to produce.
* @param resourceId The ID of the resource to return
* @return A JsonValue containing the schema of the EntitlementSubject
*/
private JsonValue jsonify(Class<? extends EntitlementSubject> subjectClass, String resourceId, boolean logical) {
try {
final JsonSchema schema = mapper.generateJsonSchema(subjectClass);
//this will remove the 'subjectName' attribute from those subjects which incorporate it unnecessarily
final JsonNode node = schema.getSchemaNode().get("properties");
if (node instanceof ObjectNode) {
final ObjectNode alter = (ObjectNode) node;
alter.remove("subjectName");
}
return JsonValue.json(JsonValue.object(JsonValue.field(JSON_OBJ_TITLE, resourceId), JsonValue.field(JSON_OBJ_LOGICAL, logical), JsonValue.field(JSON_OBJ_CONFIG, schema)));
} catch (JsonMappingException e) {
if (debug.errorEnabled()) {
debug.error("SubjectTypesResource :: JSONIFY - Error applying " + "jsonification to the Subject class representation.", e);
}
return null;
}
}
use of com.fasterxml.jackson.databind.JsonMappingException in project OpenAM by OpenRock.
the class JsonPolicyParser method parsePrivilege.
private Privilege parsePrivilege(String providedName, JsonValue jsonValue) throws EntitlementException {
try {
// Note: this is a bit ugly as we re-serialise the JsonValue back into a JSON String to then parse it
// again using Jackson. Unfortunately, that appears to be the easiest way as JsonValue does not support
// data binding.
JsonPolicy policy = MAPPER.readValue(jsonValue.toString(), JsonPolicy.class);
Privilege privilege = policy.asPrivilege();
if (isBlank(privilege.getName())) {
privilege.setName(providedName);
}
if (isBlank(privilege.getName())) {
throw new EntitlementException(EntitlementException.MISSING_PRIVILEGE_NAME);
}
// Validate the condition if present
if (privilege.getCondition() != null) {
privilege.getCondition().validate();
}
return privilege;
} catch (UnrecognizedPropertyException ex) {
throw new EntitlementException(EntitlementException.INVALID_VALUE, new Object[] { ex.getUnrecognizedPropertyName() });
} catch (JsonMappingException ex) {
throw new EntitlementException(EntitlementException.INVALID_JSON, ex, ex.getMessage());
} catch (IOException e) {
throw new EntitlementException(EntitlementException.UNABLE_TO_CREATE_POLICY, e);
}
}
Aggregations