@Override public void setField(String fieldName, Object value) throws FieldNotFoundException { if (this.payload == null) { throw new FieldNotFoundException("payload is null"); } if (!fieldName.startsWith("$.")) { fieldName = "$." + fieldName; } JsonPathProvider.setField(this.payload, value, fieldName); }
@Override public Object removeField(String fieldName) throws FieldNotFoundException { throw new FieldNotFoundException(); }
@Override public void setField(String fieldName, Object value) throws FieldNotFoundException { if (this.payload == null) { throw new FieldNotFoundException("payload is null"); } if (!fieldName.startsWith("$.")) { fieldName = "$." + fieldName; } JsonPathProvider.setField(this.payload, value, fieldName); }
@Override public Object removeField(String fieldName) throws FieldNotFoundException { throw new FieldNotFoundException("field not found"); }
@Override public Object getField(String field) throws FieldNotFoundException { if (this.payload == null) { throw new FieldNotFoundException(field + " is not in payload because payload is null"); } JsonObject json = this.payload.getAsJsonObject(); Object obj; try { obj = JsonPathProvider.read(json, field); } catch(InvalidPathException e) { throw new FieldNotFoundException("Field cannot be found because " + field + " is an invalid path"); } if (obj == null || obj instanceof JsonNull) { throw new FieldNotFoundException(field + " is not in payload."); } if (obj instanceof JsonPrimitive) { if (((JsonPrimitive) obj).isString()) { return ((JsonPrimitive) obj).getAsString(); } } return obj; }
@Override public Object getField(String field) throws FieldNotFoundException { if (this.payload == null) { throw new FieldNotFoundException(field + " is not in payload because payload is null"); } JsonObject json = this.payload.getAsJsonObject(); Object obj; try { obj = JsonPathProvider.read(json, field); } catch(InvalidPathException e) { throw new FieldNotFoundException("Field cannot be found because " + field + " is an invalid path"); } if (obj == null || obj instanceof JsonNull) { throw new FieldNotFoundException(field + " is not in payload."); } if (obj instanceof JsonPrimitive) { if (((JsonPrimitive) obj).isString()) { return ((JsonPrimitive) obj).getAsString(); } } return obj; }
@Override public Object getField(String fieldName) throws FieldNotFoundException { Object o = payload.get(fieldName); if (o == null) { throw new FieldNotFoundException(); } return o; }
@Override public Object removeField(String fieldName) throws FieldNotFoundException { if (this.payload == null) { throw new FieldNotFoundException(fieldName + " is not in payload because payload is null"); } Object o = getField(fieldName); JsonPathProvider.delete(this.payload, fieldName); return o; }
@Override public Object removeField(String fieldName) throws FieldNotFoundException { if (this.payload == null) { throw new FieldNotFoundException(fieldName + " is not in payload because payload is null"); } Object o = getField(fieldName); JsonPathProvider.delete(this.payload, fieldName); return o; }
protected static Pair<String, Object> getFieldAndSource(DeserializedEvent devent, List<String> sourceFieldsNames, boolean asString) throws FieldNotFoundException { Object sourceValue = null; String foundSourceFieldName = null; for (String sourceFieldName : sourceFieldsNames) { try { if (asString) { sourceValue = devent.getFieldAsString(sourceFieldName); } else { sourceValue = devent.getField(sourceFieldName); } foundSourceFieldName = sourceFieldName; break; } catch (FieldNotFoundException e) { continue; } } if (sourceValue == null) { throw new FieldNotFoundException(); } return new ImmutablePair<String, Object>(foundSourceFieldName, sourceValue); } }
protected static Pair<String, Object> getFieldAndSource(DeserializedEvent devent, List<String> sourceFieldsNames, boolean asString) throws FieldNotFoundException { Object sourceValue = null; String foundSourceFieldName = null; for (String sourceFieldName : sourceFieldsNames) { try { if (asString) { sourceValue = devent.getFieldAsString(sourceFieldName); } else { sourceValue = devent.getField(sourceFieldName); } foundSourceFieldName = sourceFieldName; break; } catch (FieldNotFoundException e) { continue; } } if (sourceValue == null) { throw new FieldNotFoundException(); } return new ImmutablePair<String, Object>(foundSourceFieldName, sourceValue); } }
throw new FieldNotFoundException(); throw new FieldNotFoundException("matched field is not a number");
throw new FieldNotFoundException(); throw new FieldNotFoundException("matched field is not a number");