Java Code Examples for com.fasterxml.jackson.core.JsonToken#END_OBJECT

The following examples show how to use com.fasterxml.jackson.core.JsonToken#END_OBJECT . 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: JsonImportReader.java    From apiman with Apache License 2.0 6 votes vote down vote up
public void readApiVersions() throws Exception {
    current = nextToken();
    if (current == JsonToken.END_ARRAY) {
        return;
    }
    while (nextToken() != JsonToken.END_ARRAY) {
        // Traverse each api definition
        while(nextToken() != JsonToken.END_OBJECT) {
            if (jp.getCurrentName().equals(ApiVersionBean.class.getSimpleName())) {
                current = nextToken();
                ApiVersionBean apiBean = jp.readValueAs(ApiVersionBean.class);
                dispatcher.apiVersion(apiBean);
            } else {
                OrgElementsEnum fieldName = OrgElementsEnum.valueOf(jp.getCurrentName());
                current = nextToken();
                switch (fieldName) {
                case Policies:
                    processEntities(PolicyBean.class, dispatcher::apiPolicy);
                    break;
                default:
                    throw new RuntimeException("Unhandled entity " + fieldName + " with token " + current);
                }
            }
        }
    }
}
 
Example 2
Source File: ClientCsdlAnnotations.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
@Override
protected ClientCsdlAnnotations doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {

  final ClientCsdlAnnotations annotations = new ClientCsdlAnnotations();

  for (; jp.getCurrentToken() != null && jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.FIELD_NAME) {
      if ("Target".equals(jp.getCurrentName())) {
        annotations.setTarget(jp.nextTextValue());
      } else if ("Qualifier".equals(jp.getCurrentName())) {
        annotations.setQualifier(jp.nextTextValue());
      } else if ("Annotation".equals(jp.getCurrentName())) {
        jp.nextToken();
        annotations.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class));
      }
    }
  }

  return annotations;
}
 
Example 3
Source File: Bean01BindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean01 parseOnJackson(JsonParser jacksonParser) throws Exception {
  Bean01 instance = new Bean01();
  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 "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setName(jacksonParser.getText());
          }
        break;
        case "type":
          // field type (mapped with "type")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setType(jacksonParser.getText());
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 4
Source File: PersonBindMap.java    From kripton with Apache License 2.0 5 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 "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 5
Source File: PersonBindMap.java    From kripton with Apache License 2.0 5 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 "age":
          // field age (mapped with "age")
          instance.age=jacksonParser.getIntValue();
        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;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 6
Source File: Bean81GBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean81G parseOnJackson(JsonParser jacksonParser) throws Exception {
  Bean81G instance = new Bean81G();
  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 "valueBigInteger":
          // field valueBigInteger (mapped with "valueBigInteger")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.valueBigInteger=BigIntegerUtils.read(jacksonParser.getText());
          }
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=jacksonParser.getLongValue();
        break;
        case "valueBigDecimal":
          // field valueBigDecimal (mapped with "valueBigDecimal")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.valueBigDecimal=BigDecimalUtils.read(jacksonParser.getText());
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 7
Source File: StudentBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Student parseOnJackson(JsonParser jacksonParser) throws Exception {
  Student instance = new Student();
  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 "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 8
Source File: ClientCsdlFunction.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
@Override
protected ClientCsdlFunction doDeserialize(final JsonParser jp, final DeserializationContext ctxt)
        throws IOException {

  final ClientCsdlFunction functionImpl = new ClientCsdlFunction();

  for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.FIELD_NAME) {
      if ("Name".equals(jp.getCurrentName())) {
        functionImpl.setName(jp.nextTextValue());
      } else if ("IsBound".equals(jp.getCurrentName())) {
        functionImpl.setBound(BooleanUtils.toBoolean(jp.nextTextValue()));
      } else if ("IsComposable".equals(jp.getCurrentName())) {
        functionImpl.setComposable(BooleanUtils.toBoolean(jp.nextTextValue()));
      } else if ("EntitySetPath".equals(jp.getCurrentName())) {
        functionImpl.setEntitySetPath(jp.nextTextValue());
      } else if ("Parameter".equals(jp.getCurrentName())) {
        jp.nextToken();
        functionImpl.getParameters().add(jp.readValueAs(ClientCsdlParameter.class));
      } else if ("ReturnType".equals(jp.getCurrentName())) {
        functionImpl.setReturnType(parseReturnType(jp, "Function"));
      } else if ("Annotation".equals(jp.getCurrentName())) {
        jp.nextToken();
        functionImpl.getAnnotations().add(jp.readValueAs(ClientCsdlAnnotation.class));
      }
    }
  }

  return functionImpl;
}
 
Example 9
Source File: Bean81HBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean81H parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Bean81H instance = new Bean81H();
  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 "valueBigInteger":
          // field valueBigInteger (mapped with "valueBigInteger")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.valueBigInteger=BigIntegerUtils.read(jacksonParser.getText());
          }
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "valueBigDecimal":
          // field valueBigDecimal (mapped with "valueBigDecimal")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.valueBigDecimal=BigDecimalUtils.read(jacksonParser.getText());
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 10
Source File: Bean81IBindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean81I parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Bean81I instance = new Bean81I();
  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 "valueBigDecimal":
          // field valueBigDecimal (mapped with "valueBigDecimal")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.valueBigDecimal=BigDecimalUtils.read(jacksonParser.getText());
          }
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "valueBigInteger":
          // field valueBigInteger (mapped with "valueBigInteger")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.valueBigInteger=BigIntegerUtils.read(jacksonParser.getText());
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 11
Source File: Bean02BindMap.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean02 parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Bean02 instance = new Bean02();
  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 "date":
          // field date (mapped with "date")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setDate(DateUtils.read(jacksonParser.getText()));
          }
        break;
        case "type":
          // field type (mapped with "type")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setType(jacksonParser.getText());
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 12
Source File: Bean87A_6BindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Bean87A_6 parseOnJackson(JsonParser jacksonParser) throws Exception {
  Bean87A_6 instance = new Bean87A_6();
  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 "attributeString":
          // field attributeString (mapped with "attributeString")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.attributeString=TypeAdapterUtils.toJava(StringUrlTypeAdapter.class, UrlUtils.read(jacksonParser.getText()));
          }
        break;
        case "elementString":
          // field elementString (mapped with "elementString")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.elementString=TypeAdapterUtils.toJava(StringUrlTypeAdapter.class, UrlUtils.read(jacksonParser.getText()));
          }
        break;
        case "dataString":
          // field dataString (mapped with "dataString")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.dataString=TypeAdapterUtils.toJava(StringUrlTypeAdapter.class, UrlUtils.read(jacksonParser.getText()));
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 13
Source File: PhoneNumberBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public PhoneNumber parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  PhoneNumber instance = new PhoneNumber();
  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 "actionType":
          // field actionType (mapped with "actionType")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            String tempEnum=jacksonParser.getText();
            instance.actionType=StringUtils.hasText(tempEnum)?ActionType.valueOf(tempEnum):null;
          }
        break;
        case "contactId":
          // field contactId (mapped with "contactId")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.contactId=jacksonParser.getText();
          }
        break;
        case "contactName":
          // field contactName (mapped with "contactName")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.contactName=jacksonParser.getText();
          }
        break;
        case "countryCode":
          // field countryCode (mapped with "countryCode")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.countryCode=jacksonParser.getText();
          }
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "number":
          // field number (mapped with "number")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.number=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 14
Source File: CountryBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Country parseOnJackson(JsonParser jacksonParser) throws Exception {
  Country instance = new Country();
  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 "area":
          // field area (mapped with "area")
          instance.area=jacksonParser.getLongValue();
        break;
        case "callingCode":
          // field callingCode (mapped with "callingCode")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.callingCode=jacksonParser.getText();
          }
        break;
        case "code":
          // field code (mapped with "code")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.code=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 "region":
          // field region (mapped with "region")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.region=jacksonParser.getText();
          }
        break;
        case "translatedName":
          // field translatedName (mapped with "translatedName")
          if (jacksonParser.currentToken()==JsonToken.START_ARRAY) {
            HashMap<Translation, String> collection=new HashMap<>();
            Translation key=null;
            String value=null;
            while (jacksonParser.nextToken() != JsonToken.END_ARRAY) {
              jacksonParser.nextValue();
               {
                String tempEnum=jacksonParser.getText();
                key=StringUtils.hasText(tempEnum)?Translation.valueOf(tempEnum):null;
              }
              jacksonParser.nextValue();
              if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
                value=jacksonParser.getText();
              }
              collection.put(key, value);
              key=null;
              value=null;
              jacksonParser.nextToken();
            }
            instance.translatedName=collection;
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 15
Source File: ChannelBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Channel parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Channel instance = new Channel();
  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 "imageSize":
          // field imageSize (mapped with "imageSize")
          instance.setImageSize(PrimitiveUtils.readLong(jacksonParser.getText(), 0L));
        break;
        case "imageType":
          // field imageType (mapped with "imageType")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setImageType(jacksonParser.getText());
          }
        break;
        case "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setName(jacksonParser.getText());
          }
        break;
        case "uid":
          // field uid (mapped with "uid")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.setUid(jacksonParser.getText());
          }
        break;
        case "updateTime":
          // field updateTime (mapped with "updateTime")
          instance.setUpdateTime(PrimitiveUtils.readLong(jacksonParser.getText(), 0L));
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 16
Source File: PropertyBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public Property parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  Property instance = new Property();
  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 "name":
          // field name (mapped with "name")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.name=jacksonParser.getText();
          }
        break;
        case "value":
          // field value (mapped with "value")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.value=jacksonParser.getText();
          }
        break;
        case "content":
          // field content (mapped with "content")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.content=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}
 
Example 17
Source File: GelfMessageJsonEncoderTest.java    From gelfclient with Apache License 2.0 4 votes vote down vote up
@Test
public void testEncode() throws Exception {
    byte[] bytes = readBytes();

    JsonFactory json = new JsonFactory();
    JsonParser parser = json.createParser(bytes);

    String version = null;
    Number timestamp = null;
    String host = null;
    String short_message = null;
    String full_message = null;
    Number level = null;
    Number _foo = null;
    Number _bar = null;
    String _baz = null;

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

        if (key == null) {
            continue;
        }

        parser.nextToken();

        switch (key) {
            case "version":
                version = parser.getText();
                break;
            case "timestamp":
                timestamp = parser.getNumberValue();
                break;
            case "host":
                host = parser.getText();
                break;
            case "short_message":
                short_message = parser.getText();
                break;
            case "full_message":
                full_message = parser.getText();
                break;
            case "level":
                level = parser.getNumberValue();
                break;
            case "_foo":
                _foo = parser.getNumberValue();
                break;
            case "_bar":
                _bar = parser.getNumberValue();
                break;
            case "_baz":
                _baz = parser.getText();
                break;
            default:
                throw new Exception("Found unexpected field in JSON payload: " + key);
        }
    }

    assertEquals(message.getVersion().toString(), version);
    assertEquals(message.getTimestamp(), timestamp);
    assertEquals(message.getHost(), host);
    assertEquals(message.getMessage(), short_message);
    assertEquals(message.getFullMessage(), full_message);
    assertEquals(message.getLevel().getNumericLevel(), level);
    assertEquals(1.0, _foo);
    assertEquals(128, _bar);
    assertEquals("a value", _baz);
}
 
Example 18
Source File: AegisthusSerializer.java    From aegisthus with Apache License 2.0 4 votes vote down vote up
public Map<String, Object> deserialize(String data) throws IOException {
	try {
		Map<String, Object> map = new LinkedHashMap<String, Object>();
		JsonParser jp = jsonFactory.createJsonParser(data);
		jp.nextToken(); // Object
		jp.nextToken(); // key
		map.put(KEY, new DataByteArray(jp.getCurrentName().getBytes()));
		jp.nextToken(); // object
		while (jp.nextToken() != JsonToken.END_OBJECT) {
			String field = jp.getCurrentName();
			if (DELETEDAT.equals(field.toUpperCase())) {
				jp.nextToken();
				map.put(DELETEDAT, jp.getLongValue());
			} else {
				jp.nextToken();
				while (jp.nextToken() != JsonToken.END_ARRAY) {
					List<Object> cols = new ArrayList<Object>();
					jp.nextToken();
					String name = jp.getText();
					cols.add(name);
					jp.nextToken();
					cols.add(new DataByteArray(jp.getText().getBytes()));
					jp.nextToken();
					cols.add(jp.getLongValue());
					if (jp.nextToken() != JsonToken.END_ARRAY) {
						String status = jp.getText();
						cols.add(status);
						if ("e".equals(status)) {
							jp.nextToken();
							cols.add(jp.getLongValue());
							jp.nextToken();
							cols.add(jp.getLongValue());
						} else if ("c".equals(status)) {
							jp.nextToken();
							cols.add(jp.getLongValue());
						}
						jp.nextToken();
					}
					map.put(name, cols);
				}
			}
		}

		return map;
	} catch (IOException e) {
		LOG.error(data);
		throw e;
	}
}
 
Example 19
Source File: HoconNodeCursor.java    From jackson-dataformat-hocon with Apache License 2.0 4 votes vote down vote up
@Override
public JsonToken endToken() { return JsonToken.END_OBJECT; }
 
Example 20
Source File: PhoneNumberBindMap.java    From kripton with Apache License 2.0 4 votes vote down vote up
/**
 * parse with jackson
 */
@Override
public PhoneNumber parseOnJacksonAsString(JsonParser jacksonParser) throws Exception {
  PhoneNumber instance = new PhoneNumber();
  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 "actionType":
          // field actionType (mapped with "actionType")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            String tempEnum=jacksonParser.getText();
            instance.actionType=StringUtils.hasText(tempEnum)?ActionType.valueOf(tempEnum):null;
          }
        break;
        case "contactId":
          // field contactId (mapped with "contactId")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.contactId=jacksonParser.getText();
          }
        break;
        case "contactName":
          // field contactName (mapped with "contactName")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.contactName=jacksonParser.getText();
          }
        break;
        case "countryCode":
          // field countryCode (mapped with "countryCode")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.countryCode=jacksonParser.getText();
          }
        break;
        case "id":
          // field id (mapped with "id")
          instance.id=PrimitiveUtils.readLong(jacksonParser.getText(), 0L);
        break;
        case "number":
          // field number (mapped with "number")
          if (jacksonParser.currentToken()!=JsonToken.VALUE_NULL) {
            instance.number=jacksonParser.getText();
          }
        break;
        default:
          jacksonParser.skipChildren();
        break;}
  }
  return instance;
}