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.EntityTypeDeserializer.java
@Override protected AbstractEntityType doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final AbstractEntityType entityType = ODataVersion.V3 == client.getWorkingVersion() ? new com.msopentech.odatajclient.engine.data.metadata.edm.v3.EntityType() : new com.msopentech.odatajclient.engine.data.metadata.edm.v4.EntityType(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { entityType.setName(jp.nextTextValue()); } else if ("Abstract".equals(jp.getCurrentName())) { entityType.setAbstractEntityType(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("BaseType".equals(jp.getCurrentName())) { entityType.setBaseType(jp.nextTextValue()); } else if ("OpenType".equals(jp.getCurrentName())) { entityType.setOpenType(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("HasStream".equals(jp.getCurrentName())) { entityType.setHasStream(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("Key".equals(jp.getCurrentName())) { jp.nextToken();//from w w w .ja v a2 s . c o m entityType.setKey(jp.getCodec().readValue(jp, EntityKey.class)); } else if ("Property".equals(jp.getCurrentName())) { jp.nextToken(); if (entityType instanceof com.msopentech.odatajclient.engine.data.metadata.edm.v3.EntityType) { ((com.msopentech.odatajclient.engine.data.metadata.edm.v3.EntityType) entityType) .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.EntityType) entityType) .getProperties().add(jp.getCodec().readValue(jp, com.msopentech.odatajclient.engine.data.metadata.edm.v4.Property.class)); } } else if ("NavigationProperty".equals(jp.getCurrentName())) { jp.nextToken(); if (entityType instanceof com.msopentech.odatajclient.engine.data.metadata.edm.v3.EntityType) { ((com.msopentech.odatajclient.engine.data.metadata.edm.v3.EntityType) entityType) .getNavigationProperties().add(jp.getCodec().readValue(jp, com.msopentech.odatajclient.engine.data.metadata.edm.v3.NavigationProperty.class)); } else { ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.EntityType) entityType) .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.EntityType) entityType) .setAnnotation(jp.getCodec().readValue(jp, Annotation.class)); } } } return entityType; }
From source file:com.amazonaws.hal.client.HalJsonLinksUnmarshaller.java
@Override public Map<String, HalLink> unmarshall(JsonUnmarshallerContext context) throws Exception { Map<String, HalLink> links = new LinkedHashMap<>(); JsonToken token = context.getCurrentToken(); while (token != null && token != JsonToken.END_OBJECT) { if (token == JsonToken.FIELD_NAME) { if (context.testExpression("curie")) { context.nextToken();/*from w w w . j a v a 2s . c o m*/ HalJsonCurieUnmarshaller.getInstance().unmarshall(context); } else { String relation = context.readText(); token = context.nextToken(); if (token == JsonToken.START_ARRAY) { List<HalLink> halLinks = new HalJsonArrayUnmarshaller<>( HalJsonLinkUnmarshaller.getInstance()).unmarshall(context); int i = 0; for (HalLink halLink : halLinks) { links.put(relation + "_" + i++, halLink); } } else { links.put(relation, HalJsonLinkUnmarshaller.getInstance().unmarshall(context)); } } } token = context.nextToken(); } return links; }
From source file:com.amazonaws.hal.client.HalJsonResourceUnmarshaller.java
@Override public HalResource unmarshall(JsonUnmarshallerContext context) throws Exception { HalResource halResource = new HalResource(); JsonToken token = context.getCurrentToken(); if (token == null) { token = context.nextToken();// w ww .ja v a2 s . c om } while (token != null && token != JsonToken.END_OBJECT) { if (token == JsonToken.FIELD_NAME) { if (context.testExpression("_links")) { context.nextToken(); halResource.setLinks(HalJsonLinksUnmarshaller.getInstance().unmarshall(context)); } else if (context.testExpression("_embedded")) { context.nextToken(); halResource.setEmbedded(HalJsonEmbeddedUnmarshaller.getInstance().unmarshall(context)); } else { String property = context.readText(); token = context.nextToken(); if (token == JsonToken.START_OBJECT) { context.nextToken(); halResource.addProperty(property, HalJsonMapUnmarshaller.getInstance().unmarshall(context)); } else if (token == JsonToken.START_ARRAY) { context.nextToken(); halResource.addProperty(property, HalJsonListUnmarshaller.getInstance().unmarshall(context)); } else { halResource.addProperty(property, JsonUnmarshallerUtil.getObjectForToken(token, context)); } } } token = context.nextToken(); } return halResource; }
From source file:org.onosproject.north.aaa.api.parser.impl.ApplicationParser.java
@Override public Set<Application> parseJson(InputStream stream) throws IOException, ParseException { ObjectMapper mapper = new ObjectMapper(); JsonNode jsonNode = mapper.readTree(stream); JsonParser jp = jsonNode.traverse(); Set<Application> applicationSet = new HashSet<>(); // continue parsing the token till the end of input is reached while (!jp.isClosed()) { // get the token JsonToken token = jp.nextToken(); // if its the last token then we are done if (token == null) { break; }//from ww w . j ava2 s. co m if (JsonToken.FIELD_NAME.equals(token) && "applications".equals(jp.getCurrentName())) { token = jp.nextToken(); if (!JsonToken.START_ARRAY.equals(token)) { // bail out throw new ParseException("expected ARRAY after applications"); } while (true) { token = jp.nextToken(); if (JsonToken.END_ARRAY.equals(token)) { // bail out break; } if (JsonToken.START_OBJECT.equals(token)) { Application app = jsonToApplication(jp); applicationSet.add(app); } } } } return applicationSet; }
From source file:org.onosproject.north.aaa.api.parser.impl.ScopeParser.java
@Override public Set<Scope> parseJson(InputStream stream) throws IOException, ParseException { // begin parsing JSON to Application class ObjectMapper mapper = new ObjectMapper(); JsonNode jsonNode = mapper.readTree(stream); JsonParser jp = jsonNode.traverse(); Set<Scope> scopeSet = new HashSet<>(); // continue parsing the token till the end of input is reached while (!jp.isClosed()) { // get the token JsonToken token = jp.nextToken(); // if its the last token then we are done if (token == null) { break; }// w w w . j a v a 2 s. c o m if (JsonToken.FIELD_NAME.equals(token) && "scopes".equals(jp.getCurrentName())) { token = jp.nextToken(); if (!JsonToken.START_ARRAY.equals(token)) { // bail out throw new ParseException("expected ARRAY after scopes"); } while (true) { token = jp.nextToken(); if (JsonToken.END_ARRAY.equals(token)) { // bail out break; } if (JsonToken.START_OBJECT.equals(token)) { Scope scope = jsonToScope(jp); scopeSet.add(scope); } } } } return scopeSet; }
From source file:com.msopentech.odatajclient.engine.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.metadata.edm.v3.EnumType() : new com.msopentech.odatajclient.engine.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 w w w .j av a2 s .c o m if (enumType instanceof com.msopentech.odatajclient.engine.metadata.edm.v3.EnumType) { ((com.msopentech.odatajclient.engine.metadata.edm.v3.EnumType) enumType).getMembers() .add(jp.getCodec().readValue(jp, com.msopentech.odatajclient.engine.metadata.edm.v3.Member.class)); } else { ((com.msopentech.odatajclient.engine.metadata.edm.v4.EnumType) enumType).getMembers() .add(jp.getCodec().readValue(jp, com.msopentech.odatajclient.engine.metadata.edm.v4.Member.class)); } } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); ((com.msopentech.odatajclient.engine.metadata.edm.v4.EnumType) enumType) .setAnnotation(jp.getCodec().readValue(jp, Annotation.class)); } } } return enumType; }
From source file:com.amazonaws.hal.client.HalJsonEmbeddedUnmarshaller.java
@Override public Map<String, HalResource> unmarshall(JsonUnmarshallerContext context) throws Exception { Map<String, HalResource> embedded = new LinkedHashMap<>(); JsonToken token = context.getCurrentToken(); while (token != null && token != JsonToken.END_OBJECT) { if (token == JsonToken.FIELD_NAME) { // Ignore the field name and move to the next token. The item's key will be the embedded resource's selfHref. token = context.nextToken(); if (token == JsonToken.START_ARRAY) { List<HalResource> halResources = new HalJsonArrayUnmarshaller<>( HalJsonResourceUnmarshaller.getInstance()).unmarshall(context); for (HalResource halResource : halResources) { embedded.put(halResource._getSelfHref(), halResource); }/* w ww.ja va 2 s . com*/ } else { HalResource halResource = HalJsonResourceUnmarshaller.getInstance().unmarshall(context); embedded.put(halResource._getSelfHref(), halResource); } } token = context.nextToken(); } return embedded; }
From source file:com.ryan.ryanreader.jsonwrap.JsonBufferedObject.java
@Override protected void buildBuffered(final JsonParser jp) throws IOException { JsonToken jt;//from w w w.j a v a 2 s . c o m while ((jt = jp.nextToken()) != JsonToken.END_OBJECT) { if (jt != JsonToken.FIELD_NAME) throw new JsonParseException("Expecting field name, got " + jt.name(), jp.getCurrentLocation()); final String fieldName = jp.getCurrentName(); final JsonValue value = new JsonValue(jp); synchronized (this) { properties.put(fieldName, value); notifyAll(); } value.buildInThisThread(); } }
From source file:com.msopentech.odatajclient.engine.data.metadata.edm.EntitySetDeserializer.java
@Override protected AbstractEntitySet doDeserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final AbstractEntitySet entitySet = ODataVersion.V3 == client.getWorkingVersion() ? new com.msopentech.odatajclient.engine.data.metadata.edm.v3.EntitySet() : new com.msopentech.odatajclient.engine.data.metadata.edm.v4.EntitySet(); for (; jp.getCurrentToken() != JsonToken.END_OBJECT; jp.nextToken()) { final JsonToken token = jp.getCurrentToken(); if (token == JsonToken.FIELD_NAME) { if ("Name".equals(jp.getCurrentName())) { entitySet.setName(jp.nextTextValue()); } else if ("EntityType".equals(jp.getCurrentName())) { entitySet.setEntityType(jp.nextTextValue()); } else if ("IncludeInServiceDocument".equals(jp.getCurrentName())) { ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.EntitySet) entitySet) .setIncludeInServiceDocument(BooleanUtils.toBoolean(jp.nextTextValue())); } else if ("NavigationPropertyBinding".equals(jp.getCurrentName())) { jp.nextToken();//from w w w . j a v a 2s . c o m ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.EntitySet) entitySet) .getNavigationPropertyBindings() .add(jp.getCodec().readValue(jp, NavigationPropertyBinding.class)); } else if ("Annotation".equals(jp.getCurrentName())) { jp.nextToken(); ((com.msopentech.odatajclient.engine.data.metadata.edm.v4.EntitySet) entitySet) .setAnnotation(jp.getCodec().readValue(jp, Annotation.class)); } } } return entitySet; }
From source file:com.basistech.rosette.dm.jackson.ListAttributeDeserializer.java
@Override @SuppressWarnings("unchecked") public ListAttribute deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { if (jp.getCurrentToken() == JsonToken.START_OBJECT) { // this is what we expect. // we advance to be in the same place the 'else' will be -- the first FIELD_NAME. jp.nextToken();/*from w w w .j ava 2s .co m*/ } else { /* In a full AnnotatedText, which is already doing some polymorphism shuffling, we end up here. */ /* We find a FIELD_NAME for the first field of the object */ if (jp.getCurrentToken() != JsonToken.FIELD_NAME) { throw ctxt.wrongTokenException(jp, JsonToken.START_OBJECT, "ListAttributeDeserializer called not at or FIELD_NAME of first field"); } /* We are at the field name, ready for the loop. */ } TokenBuffer tb = null; for (JsonToken t = jp.getCurrentToken(); t == JsonToken.FIELD_NAME; t = jp.nextToken()) { String name = jp.getCurrentName(); if ("itemType".equals(name)) { // gotcha! return deserialize(jp, ctxt, tb); } if (tb == null) { tb = new TokenBuffer(null, false); } tb.copyCurrentStructure(jp); } throw ctxt.mappingException("No itemType provided in a list"); }