Java Code Examples for com.fasterxml.jackson.core.JsonParser#skipChildren()

The following examples show how to use com.fasterxml.jackson.core.JsonParser#skipChildren() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StudentBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Student parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Student instance = new Student();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "location":
          // field location (mapped with "location")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.location=jacksonParser.getText();
          }
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 2
Source File: JacksonJsonFieldBodyFilter.java    From logbook with MIT License 5 votes vote down vote up
public String filter(final String body) {
    try {
        final JsonParser parser = factory.createParser(body);
        
        final CharArrayWriter writer = new CharArrayWriter(body.length() * 2); // rough estimate of final size
        
        final JsonGenerator generator = factory.createGenerator(writer);
        try {
            while(true) {
                JsonToken nextToken = parser.nextToken();
                if(nextToken == null) {
                    break;
                }

                generator.copyCurrentEvent(parser);
                if(nextToken == JsonToken.FIELD_NAME && fields.contains(parser.getCurrentName())) {
                    nextToken = parser.nextToken();
                    generator.writeString(replacement);
                    if(!nextToken.isScalarValue()) {
                        parser.skipChildren(); // skip children
                    }
                }
            }                    
        } finally {
            parser.close();
            
            generator.close();
        }
        
        return writer.toString();
    } catch(final Exception e) {
        log.trace("Unable to filter body for fields {}, compacting result. `{}`", fields, e.getMessage()); 
        return fallbackCompactor.compact(body);
    }
}
 
Example 3
Source File: FriendBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Friend parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Friend instance = new Friend();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readInteger(jacksonParser.getText(), 0);
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 4
Source File: PapBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Pap parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Pap instance = new Pap();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "common":
          // field common (mapped with "common")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.common=jacksonParser.getText();
          }
        break;
        case "official":
          // field official (mapped with "official")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.official=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 5
Source File: PersonCityErr3BindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public PersonCityErr3 parseOnJackson(JsonParser jacksonParser) throws Exception {
  PersonCityErr3 instance = new PersonCityErr3();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "cityId":
          // field cityId (mapped with "cityId")
          instance.cityId=jacksonParser.getLongValue();
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=jacksonParser.getLongValue();
        break;
        case "personId":
          // field personId (mapped with "personId")
          instance.personId=jacksonParser.getLongValue();
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 6
Source File: Bean01BindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean01 parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Bean01 instance = new Bean01();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "id":
          // field id (mapped with "id")
          instance.setId(PrimitiveUtils.readLong(jacksonParser.getText(), 0L));
        break;
        case "text":
          // field text (mapped with "text")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setText(jacksonParser.getText());
          }
        break;
        case "value":
          // field value (mapped with "value")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.value=PrimitiveUtils.readDouble(jacksonParser.getText(), null);
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 7
Source File: AlbumBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Album parseOnJackson(JsonParser jacksonParser) throws Exception {
  Album instance = new Album();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "id":
          // field id (mapped with "id")
          instance.id=jacksonParser.getLongValue();
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 8
Source File: Bean8BindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean8 parseOnJackson(JsonParser jacksonParser) throws Exception {
  Bean8 instance = new Bean8();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "id":
          // field id (mapped with "id")
          instance.id=jacksonParser.getLongValue();
        break;
        case "ignore2":
          // field ignore2 (mapped with "ignore2")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.ignore2=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 9
Source File: MonetaryAmountDeserializer.java    From jackson-datatype-money with MIT License 5 votes vote down vote up
@Override
public M deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
    BigDecimal amount = null;
    CurrencyUnit currency = null;

    while (parser.nextToken() != JsonToken.END_OBJECT) {
        final String field = parser.getCurrentName();

        parser.nextToken();

        if (field.equals(names.getAmount())) {
            amount = context.readValue(parser, BigDecimal.class);
        } else if (field.equals(names.getCurrency())) {
            currency = context.readValue(parser, CurrencyUnit.class);
        } else if (field.equals(names.getFormatted())) {
            //noinspection UnnecessaryContinue
            continue;
        } else if (context.isEnabled(FAIL_ON_UNKNOWN_PROPERTIES)) {
            throw UnrecognizedPropertyException.from(parser, MonetaryAmount.class, field,
                    Arrays.asList(names.getAmount(), names.getCurrency(), names.getFormatted()));
        } else {
            parser.skipChildren();
        }
    }

    checkPresent(parser, amount, names.getAmount());
    checkPresent(parser, currency, names.getCurrency());

    return factory.create(amount, currency);
}
 
Example 10
Source File: PersonBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Person parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Person instance = new Person();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "age":
          // field age (mapped with "age")
          instance.age=PrimitiveUtils.readInteger(jacksonParser.getText(), 0);
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 11
Source File: SdkPojoDeserializer.java    From cloudformation-cli-java-plugin with Apache License 2.0 5 votes vote down vote up
private SdkPojo readPojo(final SdkPojo pojo, JsonParser p, DeserializationContext ctxt) throws IOException {
    if (!p.isExpectedStartObjectToken()) {
        throw new JsonMappingException(p, "Expected to be in START_OBJECT got " + p.currentToken());
    }

    Map<String, SdkField<?>> fieldMap = getFields(pojo);
    JsonToken next = p.nextToken();
    ObjectMapper codec = (ObjectMapper) p.getCodec();
    while (next != JsonToken.END_OBJECT) {
        /*
         * if (next != JsonToken.FIELD_NAME) { throw new JsonMappingException(p,
         * "Expecting to get FIELD_NAME token, got " + next); }
         */
        String fieldName = p.getCurrentName();
        SdkField<?> sdkField = fieldMap.get(fieldName);
        if (sdkField == null) {
            if (codec.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) {
                throw new JsonMappingException(p, "Unknown property encountered " + fieldName);
            }
            // we need to skip this
            next = p.nextToken();
            if (next == JsonToken.START_ARRAY || next == JsonToken.START_OBJECT) {
                p.skipChildren();
            }
            // all others, just proceed to next token
            next = p.nextToken();
            continue;
        }
        // progress to next thing to read
        p.nextToken();
        // Okay we need to parse the field and set it
        Object value = readObject(sdkField, p, ctxt);
        sdkField.set(pojo, value);
        next = p.nextToken();
    }
    return pojo instanceof SdkBuilder ? (SdkPojo) ((SdkBuilder) pojo).build() : pojo;
}
 
Example 12
Source File: DeviceAccessTokenBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public DeviceAccessToken parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  DeviceAccessToken instance = new DeviceAccessToken();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "creationTime":
          // field creationTime (mapped with "creationTime")
          instance.setCreationTime(PrimitiveUtils.readLong(jacksonParser.getText(), 0L));
        break;
        case "lastUsedTime":
          // field lastUsedTime (mapped with "lastUsedTime")
          instance.setLastUsedTime(PrimitiveUtils.readLong(jacksonParser.getText(), 0L));
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 13
Source File: PrefixConfigBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public PrefixConfig parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  PrefixConfig instance = new PrefixConfig();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "defaultCountry":
          // field defaultCountry (mapped with "defaultCountry")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.defaultCountry=jacksonParser.getText();
          }
        break;
        case "dialogTimeout":
          // field dialogTimeout (mapped with "dialogTimeout")
          instance.dialogTimeout=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "dualBillingPrefix":
          // field dualBillingPrefix (mapped with "dualBillingPrefix")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.dualBillingPrefix=jacksonParser.getText();
          }
        break;
        case "enabled":
          // field enabled (mapped with "enabled")
          instance.enabled=PrimitiveUtils.readBoolean(jacksonParser.getText(), (boolean)false);
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 14
Source File: ArgonSettingsBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public ArgonSettings parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  ArgonSettings instance = new ArgonSettings();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "version":
          // field version (mapped with "version")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.version=jacksonParser.getText();
          }
        break;
        case "application":
          // field application (mapped with "application")
          if (jacksonParser.currentToken()==JsonToken.START_OBJECT || jacksonParser.currentToken()==JsonToken.VALUE_STRING) {
            instance.application=applicationSettingsBindMap.parseOnJacksonAsString(jacksonParser);
          }
        break;
        case "logger":
          // field logger (mapped with "logger")
          if (jacksonParser.currentToken()==JsonToken.START_OBJECT || jacksonParser.currentToken()==JsonToken.VALUE_STRING) {
            instance.logger=loggerSettingsBindMap.parseOnJacksonAsString(jacksonParser);
          }
        break;
        case "openGL":
          // field openGL (mapped with "openGL")
          if (jacksonParser.currentToken()==JsonToken.START_OBJECT || jacksonParser.currentToken()==JsonToken.VALUE_STRING) {
            instance.openGL=openGLSettingsBindMap.parseOnJacksonAsString(jacksonParser);
          }
        break;
        case "viewFrustum":
          // field viewFrustum (mapped with "viewFrustum")
          if (jacksonParser.currentToken()==JsonToken.START_OBJECT || jacksonParser.currentToken()==JsonToken.VALUE_STRING) {
            instance.viewFrustum=viewFrustumSettingsBindMap.parseOnJacksonAsString(jacksonParser);
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 15
Source File: PrefixConfigBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public PrefixConfig parseOnJackson(JsonParser jacksonParser) throws Exception {
  PrefixConfig instance = new PrefixConfig();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "defaultCountry":
          // field defaultCountry (mapped with "defaultCountry")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.defaultCountry=jacksonParser.getText();
          }
        break;
        case "dialogTimeout":
          // field dialogTimeout (mapped with "dialogTimeout")
          instance.dialogTimeout=jacksonParser.getLongValue();
        break;
        case "dualBillingPrefix":
          // field dualBillingPrefix (mapped with "dualBillingPrefix")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.dualBillingPrefix=jacksonParser.getText();
          }
        break;
        case "enabled":
          // field enabled (mapped with "enabled")
          instance.enabled=jacksonParser.getBooleanValue();
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=jacksonParser.getLongValue();
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 16
Source File: Bean81RBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean81R parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Bean81R instance = new Bean81R();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "valueByteArray":
          // field valueByteArray (mapped with "valueByteArray")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.valueByteArray=Base64Utils.decode(jacksonParser.getValueAsString());
          }
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "valueMapStringInteger":
          // field valueMapStringInteger (mapped with "valueMapStringInteger")
          if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
            HashMap<String, Integer> collection=new HashMap<>();
            String key=null;
            Integer value=null;
            JsonToken current;
            String tempValue=null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
              current=jacksonParser.currentToken();
              for (int i=0; i<2 ;i++) {
                while (current != JsonToken.FIELD_NAME) {
                  current=jacksonParser.nextToken();
                }
                jacksonParser.nextValue();
                switch(jacksonParser.getCurrentName()) {
                case "key":
                  if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
                    key=jacksonParser.getText();
                  }
                break;
                case "value":
                  tempValue=jacksonParser.getValueAsString();
                  if (jacksonParser.currentToken()==JsonToken.VALUE_STRING && "null".equals(tempValue)) {
                    value=null;
                  } else {
                    if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
                      value=PrimitiveUtils.readInteger(jacksonParser.getText(), null);
                    }
                  }
                break;
                }
              }
              collection.put(key, value);
              key=null;
              value=null;
              jacksonParser.nextToken();
            }
            instance.valueMapStringInteger=collection;
          }
        break;
        case "valueInteger":
          // field valueInteger (mapped with "valueInteger")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.valueInteger=PrimitiveUtils.readInteger(jacksonParser.getText(), null);
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 17
Source File: NakadiReader.java    From fahrschein with Apache License 2.0 4 votes vote down vote up
private void readBatch(final JsonParser jsonParser) throws IOException {
    LOG.debug("Waiting for next batch of events for {}", eventNames);

    expectToken(jsonParser, JsonToken.START_OBJECT);
    metricsCollector.markMessageReceived();

    Cursor cursor = null;
    List<T> events = null;

    while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
        final String field = jsonParser.getCurrentName();
        switch (field) {
            case "cursor": {
                cursor = readCursor(jsonParser);
                break;
            }
            case "events": {
                events = eventReader.read(jsonParser);
                break;
            }
            case "info": {
                LOG.debug("Skipping stream info in event batch");
                jsonParser.nextToken();
                jsonParser.skipChildren();
                break;
            }
            default: {
                LOG.warn("Unexpected field [{}] in event batch", field);
                jsonParser.nextToken();
                jsonParser.skipChildren();
                break;
            }
        }
    }

    if (cursor == null) {
        throw new IOException("Could not read cursor");
    }

    final String eventName = getCurrentEventName(cursor);
    LOG.debug("Cursor for [{}] partition [{}] at offset [{}]", eventName, cursor.getPartition(), cursor.getOffset());

    if (events == null) {
        metricsCollector.markEventsReceived(0);
    } else {
        metricsCollector.markEventsReceived(events.size());

        final Batch<T> batch = new Batch<>(cursor, Collections.unmodifiableList(events));

        processBatch(batch);

        metricsCollector.markMessageSuccessfullyProcessed();
    }
}
 
Example 18
Source File: PrefixConfigBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public PrefixConfig parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  PrefixConfig instance = new PrefixConfig();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "defaultCountry":
          // field defaultCountry (mapped with "defaultCountry")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.defaultCountry=jacksonParser.getText();
          }
        break;
        case "dialogTimeout":
          // field dialogTimeout (mapped with "dialogTimeout")
          instance.dialogTimeout=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "dualBillingPrefix":
          // field dualBillingPrefix (mapped with "dualBillingPrefix")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.dualBillingPrefix=jacksonParser.getText();
          }
        break;
        case "enabled":
          // field enabled (mapped with "enabled")
          instance.enabled=PrimitiveUtils.readBoolean(jacksonParser.getText(), (boolean)false);
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 19
Source File: PersonBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Person parseOnJackson(JsonParser jacksonParser) throws Exception {
  Person instance = new Person();
  String fieldName;
  if (jacksonParser.currentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.currentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "birthCity":
          // field birthCity (mapped with "birthCity")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.birthCity=jacksonParser.getText();
          }
        break;
        case "birthDay":
          // field birthDay (mapped with "birthDay")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.birthDay=DateUtils.read(jacksonParser.getText());
          }
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=jacksonParser.getLongValue();
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        case "surname":
          // field surname (mapped with "surname")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.surname=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 20
Source File: Bean87A_2BindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean87A_2 parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Bean87A_2 instance = new Bean87A_2();
  String fieldName;
  if (jacksonParser.getCurrentToken() == null) {
    jacksonParser.nextToken();
  }
  if (jacksonParser.getCurrentToken() != JsonToken.START_OBJECT) {
    jacksonParser.skipChildren();
    return instance;
  }
  while (jacksonParser.nextToken() != JsonToken.END_OBJECT) {
    fieldName = jacksonParser.getCurrentName();
    jacksonParser.nextToken();

    // Parse fields:
    switch (fieldName) {
        case "attributeURL":
          // field attributeURL (mapped with "attributeURL")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.attributeURL=TypeAdapterUtils.toJava(UrlByteArrayTypeAdapter.class, Base64Utils.decode(jacksonParser.getValueAsString()));
          }
        break;
        case "elementURL":
          // field elementURL (mapped with "elementURL")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.elementURL=TypeAdapterUtils.toJava(UrlByteArrayTypeAdapter.class, Base64Utils.decode(jacksonParser.getValueAsString()));
          }
        break;
        case "dataURL":
          // field dataURL (mapped with "dataURL")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.dataURL=TypeAdapterUtils.toJava(UrlByteArrayTypeAdapter.class, Base64Utils.decode(jacksonParser.getValueAsString()));
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}