use of org.codehaus.jackson.type.JavaType in project motech by motech.
the class MdsRestBundleIT method testRestExposedFields.
@Test
public void testRestExposedFields() throws Exception {
getLogger().info("Testing REST exposed fields");
final JavaType mapType = OBJECT_MAPPER.getTypeFactory().constructMapType(Map.class, String.class, Object.class);
// CREATE
HttpPost post = new HttpPost(FILTERED_ENTITY_URL);
post.setEntity(new StringEntity(recordJsonString("some-string", 42), ContentType.APPLICATION_JSON));
String body = getHttpClient().execute(post, new BasicResponseHandler());
Map record = OBJECT_MAPPER.readValue(body, mapType);
assertEquals(FILTERED_REST_FIELDS.size(), record.size());
assertEquals(FILTERED_REST_FIELDS, record.keySet());
assertEquals(42, record.get("intField"));
// UPDATE
HttpPut put = new HttpPut(FILTERED_ENTITY_URL);
put.setEntity(new StringEntity(recordJsonString(record.get("strField") + "Updated", (int) record.get("intField") + 13, (long) (int) record.get("id"))));
body = getHttpClient().execute(put, new BasicResponseHandler());
record = OBJECT_MAPPER.readValue(body, mapType);
assertEquals(FILTERED_REST_FIELDS.size(), record.size());
assertEquals(FILTERED_REST_FIELDS, record.keySet());
assertEquals(42 + 13, record.get("intField"));
// READ
body = getHttpClient().get(FILTERED_ENTITY_URL, new BasicResponseHandler());
RestResponse response = OBJECT_MAPPER.readValue(body, RestResponse.class);
assertEquals(1, response.getData().size());
record = response.getData().get(0);
assertEquals(FILTERED_REST_FIELDS.size(), record.size());
assertEquals(FILTERED_REST_FIELDS, record.keySet());
assertEquals(42 + 13, record.get("intField"));
// Make sure the string field is ignored
List result = getDataServiceForFilteredEntity().retrieveAll();
assertNotNull(result);
assertFalse(result.isEmpty());
for (Object obj : result) {
assertNotNull(obj);
assertNull(PropertyUtil.getProperty(obj, "strField"));
}
}
use of org.codehaus.jackson.type.JavaType in project motech by motech.
the class TaskDeserializer method deserialize.
@Override
public Task deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
jsonNode = jsonParser.readValueAsTree();
task = new Task();
ObjectCodec codec = jsonParser.getCodec();
if (codec instanceof ObjectMapper) {
mapper = (ObjectMapper) codec;
} else {
mapper = new ObjectMapper();
}
TypeFactory typeFactory = mapper.getTypeFactory();
JavaType stringType = typeFactory.constructType(String.class);
JavaType longType = typeFactory.constructType(Long.class);
JavaType intType = typeFactory.constructType(Integer.class);
JavaType dateTime = typeFactory.constructType(DateTime.class);
JavaType booleanType = typeFactory.constructType(boolean.class);
JavaType timeType = typeFactory.constructType(Time.class);
setProperty("id", longType);
setProperty("owner", stringType);
setProperty("creator", stringType);
setProperty("creationDate", dateTime);
setProperty("modificationDate", dateTime);
setProperty("modifiedBy", stringType);
setProperty("description", stringType);
setProperty("name", stringType);
setProperty("enabled", stringType);
setProperty("hasRegisteredChannel", stringType);
setProperty("taskConfig", typeFactory.constructType(TaskConfig.class));
setProperty("trigger", typeFactory.constructType(TaskTriggerInformation.class));
setProperty("numberOfRetries", intType);
setProperty("retryIntervalInMilliseconds", intType);
setProperty("retryTaskOnFailure", stringType);
setProperty("useTimeWindow", booleanType);
setProperty("startTime", timeType);
setProperty("endTime", timeType);
setProperty("validationErrors", typeFactory.constructCollectionType(Set.class, TaskError.class));
setProperty("actions", typeFactory.constructCollectionType(List.class, TaskActionInformation.class));
setProperty("days", typeFactory.constructCollectionType(List.class, String.class));
return task;
}
use of org.codehaus.jackson.type.JavaType in project typescript-generator by vojtechhabarta.
the class Jackson1Parser method getBeanHelper.
private BeanHelper getBeanHelper(Class<?> beanClass) {
if (beanClass == null) {
return null;
}
try {
final SerializationConfig serializationConfig = objectMapper.getSerializationConfig();
final JavaType simpleType = objectMapper.constructType(beanClass);
final JsonSerializer<?> jsonSerializer = BeanSerializerFactory.instance.createSerializer(serializationConfig, simpleType, null);
if (jsonSerializer == null) {
return null;
}
if (jsonSerializer instanceof BeanSerializer) {
return new BeanHelper((BeanSerializer) jsonSerializer);
} else {
final String jsonSerializerName = jsonSerializer.getClass().getName();
throw new RuntimeException(String.format("Unknown serializer '%s' for class '%s'", jsonSerializerName, beanClass));
}
} catch (JsonMappingException e) {
throw new RuntimeException(e);
}
}
Aggregations