List of usage examples for com.fasterxml.jackson.core JsonToken FIELD_NAME
JsonToken FIELD_NAME
To view the source code for com.fasterxml.jackson.core JsonToken FIELD_NAME.
Click Source Link
From source file:com.msopentech.odatajclient.engine.data.metadata.edm.v4.NavigationPropertyDeserializer.java
@Override protected NavigationProperty doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final NavigationProperty property = new NavigationProperty(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { property.setName(jp.nextTextValue()); } else if ("Type".equals(jp.getCurrentName())) { property.setType(jp.nextTextValue()); } else if ("Nullable".equals(jp.getCurrentName())) { property.setNullable(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("Partner".equals(jp.getCurrentName())) { property.setPartner(jp.nextTextValue()); } else if ("ContainsTarget".equals(jp.getCurrentName())) { property.setContainsTarget(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("ReferentialConstraint".equals(jp.getCurrentName())) { jp.nextToken();/*from w w w .ja v a 2 s .c o m*/ property.getReferentialConstraints() .add(jp.getCodec().readValue(jp, ReferentialConstraint.class)); } else if ("OnDelete".equals(jp.getCurrentName())) { jp.nextToken(); property.setOnDelete(jp.getCodec().readValue(jp, OnDelete.class)); } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); property.setAnnotation(jp.getCodec().readValue(jp, Annotation.class)); } } } return property; }
From source file:com.msopentech.odatajclient.engine.data.metadata.edm.v4.TypeDefinitionDeserializer.java
@Override protected TypeDefinition doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final TypeDefinition typeDefinition = new TypeDefinition(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { typeDefinition.setName(jp.nextTextValue()); } else if ("UnderlyingType".equals(jp.getCurrentName())) { typeDefinition.setUnderlyingType(jp.nextTextValue()); } else if ("MaxLength".equals(jp.getCurrentName())) { typeDefinition.setMaxLength(jp.nextTextValue()); } else if ("Unicode".equals(jp.getCurrentName())) { typeDefinition.setUnicode(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("Precision".equals(jp.getCurrentName())) { typeDefinition.setPrecision(BigInteger.valueOf(jp.nextLongValue(0L))); } else if ("Scale".equals(jp.getCurrentName())) { typeDefinition.setScale(BigInteger.valueOf(jp.nextLongValue(0L))); } else if ("SRID".equals(jp.getCurrentName())) { typeDefinition.setSrid(jp.nextTextValue()); } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken();/*from w ww. ja v a 2 s.c o m*/ typeDefinition.getAnnotations().add(jp.getCodec().readValue(jp, Annotation.class)); } } } return typeDefinition; }
From source file:com.netflix.discovery.converters.jackson.serializer.ApplicationXmlDeserializer.java
@Override public Application deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { String name = null;/*from w ww .j ava2 s . com*/ List<InstanceInfo> instances = new ArrayList<>(); while (jp.nextToken() == JsonToken.FIELD_NAME) { String fieldName = jp.getCurrentName(); jp.nextToken(); // to point to value if ("name".equals(fieldName)) { name = jp.getValueAsString(); } else if ("instance".equals(fieldName)) { instances.add(jp.readValueAs(InstanceInfo.class)); } else { throw new JsonMappingException("Unexpected field " + fieldName, jp.getCurrentLocation()); } } return new Application(name, instances); }
From source file:org.apache.ode.jacob.soup.jackson.ChannelRefDeserializer.java
@Override public ChannelRef deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { Object target = null;//from w ww .j a va 2 s. c o m while (jp.nextToken() != JsonToken.END_OBJECT) { String fieldname = jp.getCurrentName(); if (jp.getCurrentToken() == JsonToken.FIELD_NAME) { // if we're not already on the field, advance by one. jp.nextToken(); } if ("target".equals(fieldname)) { target = jp.readValueAs(Object.class); } } if (target == null) { throw ctxt.mappingException(ChannelRef.class); } return new ChannelRef(target); }
From source file:com.amazonaws.hal.client.HalJsonLinkUnmarshaller.java
@Override public HalLink unmarshall(JsonUnmarshallerContext context) throws Exception { HalLink halLink = new HalLink(); JsonToken token = context.getCurrentToken(); while (token != null && token != JsonToken.END_OBJECT) { if (token == JsonToken.FIELD_NAME) { if (context.testExpression("href")) { context.nextToken();//from w ww .ja v a 2s. c om halLink.setHref(context.readText()); } else if (context.testExpression("name")) { context.nextToken(); halLink.setName(context.readText()); } else if (context.testExpression("title")) { context.nextToken(); halLink.setTitle(context.readText()); } else if (context.testExpression("templated")) { context.nextToken(); halLink.setTemplated(Boolean.valueOf(context.readText())); } else if (context.testExpression("deprecation")) { context.nextToken(); halLink.setDeprecation(context.readText()); } else { // Ignore this. Likely one of hreflang, profile, type context.nextToken(); } } token = context.nextToken(); } return halLink; }
From source file:org.springframework.security.oauth2.common.exceptions.OAuth2ExceptionJackson2Deserializer.java
@Override public OAuth2Exception deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { JsonToken t = jp.getCurrentToken();// ww w .j av a2 s . co m if (t == JsonToken.START_OBJECT) { t = jp.nextToken(); } Map<String, Object> errorParams = new HashMap<String, Object>(); for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) { // Must point to field name String fieldName = jp.getCurrentName(); // And then the value... t = jp.nextToken(); // Note: must handle null explicitly here; value deserializers won't Object value; if (t == JsonToken.VALUE_NULL) { value = null; } // Some servers might send back complex content else if (t == JsonToken.START_ARRAY) { value = jp.readValueAs(List.class); } else if (t == JsonToken.START_OBJECT) { value = jp.readValueAs(Map.class); } else { value = jp.getText(); } errorParams.put(fieldName, value); } Object errorCode = errorParams.get("error"); String errorMessage = errorParams.containsKey("error_description") ? errorParams.get("error_description").toString() : null; if (errorMessage == null) { errorMessage = errorCode == null ? "OAuth Error" : errorCode.toString(); } OAuth2Exception ex; if ("invalid_client".equals(errorCode)) { ex = new InvalidClientException(errorMessage); } else if ("unauthorized_client".equals(errorCode)) { ex = new UnauthorizedUserException(errorMessage); } else if ("invalid_grant".equals(errorCode)) { if (errorMessage.toLowerCase().contains("redirect") && errorMessage.toLowerCase().contains("match")) { ex = new RedirectMismatchException(errorMessage); } else { ex = new InvalidGrantException(errorMessage); } } else if ("invalid_scope".equals(errorCode)) { ex = new InvalidScopeException(errorMessage); } else if ("invalid_token".equals(errorCode)) { ex = new InvalidTokenException(errorMessage); } else if ("invalid_request".equals(errorCode)) { ex = new InvalidRequestException(errorMessage); } else if ("redirect_uri_mismatch".equals(errorCode)) { ex = new RedirectMismatchException(errorMessage); } else if ("unsupported_grant_type".equals(errorCode)) { ex = new UnsupportedGrantTypeException(errorMessage); } else if ("unsupported_response_type".equals(errorCode)) { ex = new UnsupportedResponseTypeException(errorMessage); } else if ("insufficient_scope".equals(errorCode)) { ex = new InsufficientScopeException(errorMessage, OAuth2Utils.parseParameterList((String) errorParams.get("scope"))); } else if ("access_denied".equals(errorCode)) { ex = new UserDeniedAuthorizationException(errorMessage); } else { ex = new OAuth2Exception(errorMessage); } Set<Map.Entry<String, Object>> entries = errorParams.entrySet(); for (Map.Entry<String, Object> entry : entries) { String key = entry.getKey(); if (!"error".equals(key) && !"error_description".equals(key)) { Object value = entry.getValue(); ex.addAdditionalInformation(key, value == null ? null : value.toString()); } } return ex; }
From source file:com.msopentech.odatajclient.engine.data.metadata.edm.EnumTypeDeserializer.java
@Override protected AbstractEnumType doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final AbstractEnumType enumType = ODataVersion.V3 == client.getWorkingVersion() ? new com.msopentech.odatajclient.engine.data.metadata.edm.v3.EnumType() : new com.msopentech.odatajclient.engine.data.metadata.edm.v4.EnumType(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { enumType.setName(jp.nextTextValue()); } else if ("UnderlyingType".equals(jp.getCurrentName())) { enumType.setUnderlyingType(jp.nextTextValue()); } else if ("IsFlags".equals(jp.getCurrentName())) { enumType.setFlags(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("Member".equals(jp.getCurrentName())) { jp.nextToken();/*from www. j a v a 2s .c o m*/ if (enumType instanceof com.msopentech.odatajclient.engine.data.metadata.edm.v3.EnumType) { ((com.msopentech.odatajclient.engine.data.metadata.edm.v3.EnumType) enumType).getMembers() .add(jp.getCodec().readValue(jp, com.msopentech.odatajclient.engine.data.metadata.edm.v3.Member.class)); } else { ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.EnumType) enumType).getMembers() .add(jp.getCodec().readValue(jp, com.msopentech.odatajclient.engine.data.metadata.edm.v4.Member.class)); } } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.EnumType) enumType) .setAnnotation(jp.getCodec().readValue(jp, Annotation.class)); } } } return enumType; }
From source file:com.amazonaws.hal.client.HalJsonMapUnmarshaller.java
@Override public Map<String, Object> unmarshall(JsonUnmarshallerContext context) throws Exception { Map<String, Object> map = new HashMap<>(); JsonToken token = context.getCurrentToken(); while (token != null && token != JsonToken.END_OBJECT) { if (token == JsonToken.FIELD_NAME) { String property = context.readText(); token = context.nextToken(); if (token == JsonToken.START_OBJECT) { context.nextToken();/*from w w w.j a va2 s . com*/ map.put(property, HalJsonMapUnmarshaller.getInstance().unmarshall(context)); } else if (token == JsonToken.START_ARRAY) { context.nextToken(); map.put(property, HalJsonListUnmarshaller.getInstance().unmarshall(context)); } else { map.put(property, JsonUnmarshallerUtil.getObjectForToken(token, context)); } } token = context.nextToken(); } return map; }
From source file:com.msopentech.odatajclient.engine.data.metadata.edm.ComplexTypeDeserializer.java
@Override protected AbstractComplexType doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final AbstractComplexType complexType = ODataVersion.V3 == client.getWorkingVersion() ? new com.msopentech.odatajclient.engine.data.metadata.edm.v3.ComplexType() : new com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { complexType.setName(jp.nextTextValue()); } else if ("Abstract".equals(jp.getCurrentName())) { ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType) complexType) .setAbstractEntityType(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("BaseType".equals(jp.getCurrentName())) { ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType) complexType) .setBaseType(jp.nextTextValue()); } else if ("OpenType".equals(jp.getCurrentName())) { ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType) complexType) .setOpenType(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("Property".equals(jp.getCurrentName())) { jp.nextToken();//from w ww.j a va2s. c om if (complexType instanceof com.msopentech.odatajclient.engine.data.metadata.edm.v3.ComplexType) { ((com.msopentech.odatajclient.engine.data.metadata.edm.v3.ComplexType) complexType) .getProperties().add(jp.getCodec().readValue(jp, com.msopentech.odatajclient.engine.data.metadata.edm.v3.Property.class)); } else { ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType) complexType) .getProperties().add(jp.getCodec().readValue(jp, com.msopentech.odatajclient.engine.data.metadata.edm.v4.Property.class)); } } else if ("NavigationProperty".equals(jp.getCurrentName())) { jp.nextToken(); ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType) complexType) .getNavigationProperties().add(jp.getCodec().readValue(jp, com.msopentech.odatajclient.engine.data.metadata.edm.v4.NavigationProperty.class)); } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.ComplexType) complexType) .setAnnotation(jp.getCodec().readValue(jp, Annotation.class)); } } } return complexType; }