class RegexDeserializer extends Deserializer {

  @Override
  public DeserializedEvent deserialize(String raw) {
    Matcher m = this.pattern.matcher(raw);

    if (!m.matches()) {
      throw new DeserializationException("raw event does not match string");
    }

    int groups = m.groupCount();

    JsonObject obj = new JsonObject();
    for (int i = 0; i < groups && i < fields.size(); i++) {
      String str = m.group(i + 1);
      ReFieldConfig field = this.fields.get(i);

      switch (field.getType()) {
        case BOOLEAN:
          obj.addProperty(field.getName(), Boolean.parseBoolean(str));
          break;
        case NUMBER:
          obj.addProperty(field.getName(), NumberUtils.createNumber(str));
          break;
        case STRING:
          obj.addProperty(field.getName(), str);
          break;
        default:
          obj.addProperty(field.getName(), str);
          break;
      }
    }

    return new GenericJsonEvent(obj);
  }

  public  RegexDeserializer(final Pattern pattern, final List<ReFieldConfig> fields);

}