use of com.fasterxml.jackson.databind.ObjectReader in project uPortal by Jasig.
the class JacksonColumnMapper method fromNonNullValue.
@Override
public final Object fromNonNullValue(String s) {
try {
final JsonWrapper jsonWrapper = objectReader.readValue(s);
final ObjectReader typeReader = typedObjectReaders.getUnchecked(jsonWrapper.getType());
return typeReader.readValue(jsonWrapper.getValue());
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Could not read from JSON: " + s, e);
} catch (IOException e) {
throw new IllegalArgumentException("Could not read from JSON: " + s, e);
}
}
use of com.fasterxml.jackson.databind.ObjectReader in project dhis2-core by dhis2.
the class DefaultCsvEventService method readEvents.
@Override
public Events readEvents(InputStream inputStream, boolean skipFirst) throws IOException {
Events events = new Events();
ObjectReader reader = CSV_MAPPER.readerFor(CsvEventDataValue.class).with(CSV_SCHEMA.withSkipFirstDataRow(skipFirst));
MappingIterator<CsvEventDataValue> iterator = reader.readValues(inputStream);
Event event = new Event();
event.setEvent("not_valid");
while (iterator.hasNext()) {
CsvEventDataValue dataValue = iterator.next();
if (!event.getEvent().equals(dataValue.getEvent())) {
event = new Event();
event.setEvent(dataValue.getEvent());
event.setStatus(StringUtils.isEmpty(dataValue.getStatus()) ? EventStatus.ACTIVE : Enum.valueOf(EventStatus.class, dataValue.getStatus()));
event.setProgram(dataValue.getProgram());
event.setProgramStage(dataValue.getProgramStage());
event.setEnrollment(dataValue.getEnrollment());
event.setOrgUnit(dataValue.getOrgUnit());
event.setEventDate(dataValue.getEventDate());
event.setDueDate(dataValue.getDueDate());
if (dataValue.getLongitude() != null && dataValue.getLatitude() != null) {
event.setCoordinate(new Coordinate(dataValue.getLongitude(), dataValue.getLatitude()));
}
events.getEvents().add(event);
}
DataValue value = new DataValue(dataValue.getDataElement(), dataValue.getValue());
value.setStoredBy(dataValue.getStoredBy());
value.setProvidedElsewhere(dataValue.getProvidedElsewhere());
event.getDataValues().add(value);
}
return events;
}
use of com.fasterxml.jackson.databind.ObjectReader in project jvm-serializers by eishay.
the class JacksonAvroDatabind method register.
public static void register(TestGroups groups) {
ObjectMapper mapper = new ObjectMapper(new AvroFactory());
mapper.enable(SerializationFeature.WRITE_ENUMS_USING_INDEX);
JavaType type = mapper.constructType(MediaContent.class);
AvroSchema schema = new AvroSchema(Avro.Media.sMediaContent);
ObjectReader reader = mapper.readerFor(type).with(schema);
ObjectWriter writer = mapper.writerFor(type).with(schema);
groups.media.add(JavaBuiltIn.mediaTransformer, new StdJacksonDataBind<MediaContent>("avro/jackson/databind", type, mapper, reader, writer), new SerFeatures(SerFormat.JSON, SerGraph.FLAT_TREE, SerClass.ZERO_KNOWLEDGE, ""));
}
use of com.fasterxml.jackson.databind.ObjectReader in project hadoop by apache.
the class JsonUtilClient method toXAttrNames.
static List<String> toXAttrNames(final Map<?, ?> json) throws IOException {
if (json == null) {
return null;
}
final String namesInJson = (String) json.get("XAttrNames");
ObjectReader reader = new ObjectMapper().readerFor(List.class);
final List<Object> xattrs = reader.readValue(namesInJson);
final List<String> names = Lists.newArrayListWithCapacity(json.keySet().size());
for (Object xattr : xattrs) {
names.add((String) xattr);
}
return names;
}
use of com.fasterxml.jackson.databind.ObjectReader in project camel by apache.
the class SObjectTreeResponseTest method shouldDeserializeJsonFromSalesforceExample.
@Test
public void shouldDeserializeJsonFromSalesforceExample() throws Exception {
final String json = //
"{\n" + //
" \"hasErrors\" : false,\n" + //
" \"results\" : [{\n" + //
" \"referenceId\" : \"ref1\",\n" + //
" \"id\" : \"001D000000K0fXOIAZ\"\n" + //
" },{\n" + //
" \"referenceId\" : \"ref4\",\n" + //
" \"id\" : \"001D000000K0fXPIAZ\"\n" + //
" },{\n" + //
" \"referenceId\" : \"ref2\",\n" + //
" \"id\" : \"003D000000QV9n2IAD\"\n" + //
" },{\n" + //
" \"referenceId\" : \"ref3\",\n" + //
" \"id\" : \"003D000000QV9n3IAD\"\n" + //
" }]\n" + "}";
final ObjectMapper mapper = new ObjectMapper();
final ObjectReader reader = mapper.readerFor(SObjectTreeResponse.class);
final SObjectTreeResponse response = reader.readValue(json);
assertNotNull("Response should be parsed", response);
assertFalse("`hasErrors` flag should be false", response.hasErrors());
assertEquals("Should read 4 references", 4, response.getResults().size());
assertThat("4 references should be read as expected", response.getResults(), hasItems(//
new ReferenceId("ref1", "001D000000K0fXOIAZ", Collections.emptyList()), //
new ReferenceId("ref4", "001D000000K0fXPIAZ", Collections.emptyList()), //
new ReferenceId("ref2", "003D000000QV9n2IAD", Collections.emptyList()), new ReferenceId("ref3", "003D000000QV9n3IAD", Collections.emptyList())));
}
Aggregations