use of com.nextdoor.bender.deserializer.FieldNotFoundException in project bender by Nextdoor.
the class JsonRootNodeOperation method mutateEvent.
/**
* The {@link DeserializedEvent} payload must be a {@link JsonObject}.
*
* @param event Event with payload to mutate.
*/
protected void mutateEvent(DeserializedEvent event) throws OperationException {
Object payload = event.getPayload();
if (payload == null) {
return;
}
if (!(payload instanceof JsonObject)) {
throw new OperationException("Payload data is not a JsonObject");
}
Object o;
try {
o = event.getField(path);
} catch (FieldNotFoundException e) {
throw new OperationException(e);
}
if (!(o instanceof JsonObject)) {
throw new OperationException("specified node '" + path + "' is not an object");
}
event.setPayload(o);
}
use of com.nextdoor.bender.deserializer.FieldNotFoundException in project bender by Nextdoor.
the class TimeOperation method perform.
@Override
public InternalEvent perform(InternalEvent ievent) {
String field;
try {
field = ievent.getEventObj().getFieldAsString(timeField);
} catch (FieldNotFoundException e) {
throw new OperationException("time field " + timeField + " does not exist in " + ievent.getEventString());
}
ievent.setEventTime(getTimestamp(field, timeFieldType));
return ievent;
}
use of com.nextdoor.bender.deserializer.FieldNotFoundException in project bender by Nextdoor.
the class GenericJsonDeserializerTest method testGetMissingField.
@Test
public void testGetMissingField() throws UnsupportedEncodingException, IOException {
String input = TestUtils.getResourceString(this.getClass(), "basic.json");
String missingField = "$.not_a_member";
String expectedErrorMessage = missingField + " is not in payload.";
GenericJsonDeserializer deser = new GenericJsonDeserializer(Collections.emptyList());
deser.init();
DeserializedEvent event = deser.deserialize(input);
try {
event.getField(missingField);
fail();
} catch (FieldNotFoundException e) {
assertEquals(e.getMessage(), expectedErrorMessage);
}
}
use of com.nextdoor.bender.deserializer.FieldNotFoundException in project bender by Nextdoor.
the class RegexFilterOperation method test.
/**
* Returns true if the event matches the filter.
*
* @param ievent {@link DeserializedEvent} has payload to filter against.
*/
@Override
public boolean test(InternalEvent ievent) {
DeserializedEvent devent = ievent.getEventObj();
if (devent == null) {
return false;
}
boolean found;
try {
String field = devent.getFieldAsString(this.path);
found = this.pattern.matcher(field).matches();
} catch (FieldNotFoundException e) {
found = false;
}
/*
* When false is returned then the event is excluded from the stream.
*/
return this.exclude != found;
}
use of com.nextdoor.bender.deserializer.FieldNotFoundException in project bender by Nextdoor.
the class GenericJsonEventTest method testRemoveMissingField.
@Test(expected = FieldNotFoundException.class)
public void testRemoveMissingField() throws FieldNotFoundException {
GenericJsonEvent event = getEmptyEvent();
JsonObject payload = (JsonObject) event.getPayload();
try {
Object obj = event.removeField("$.foo");
} catch (FieldNotFoundException e) {
assertEquals(1, payload.size());
assertEquals("b", payload.get("a").getAsString());
throw e;
}
}
Aggregations