/** * Method that fetches next token (as if calling {@link #nextToken}) and * verifies whether it is {@link JsonToken#FIELD_NAME}; if it is, * returns same as {@link #getCurrentName()}, otherwise null. * * @since 2.5 */ public String nextFieldName() throws IOException { return (nextToken() == JsonToken.FIELD_NAME) ? getCurrentName() : null; }
@Override public String readStringUTF() throws IOException { if ( unknownFallbackReadFieldName != null ) { String unkReadAhead = unknownFallbackReadFieldName; unknownFallbackReadFieldName = null; return unkReadAhead; } JsonToken jsonToken = input.nextToken(); if ( jsonToken == JsonToken.VALUE_NULL ) return null; if ( jsonToken == JsonToken.FIELD_NAME ) return input.getCurrentName(); return input.getText(); }
public T find(JsonParser jp, T defaultValue) throws IOException { if (jp.getCurrentToken() == JsonToken.FIELD_NAME) { return stringLookup.getOrDefault(jp.getCurrentName(), defaultValue); } return find(jp.getTextCharacters(), jp.getTextOffset(), jp.getTextLength(), defaultValue); }
protected final Object deserializeWithView(JsonParser p, DeserializationContext ctxt, Object bean, Class<?> activeView) throws IOException { JsonToken t = p.getCurrentToken(); for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); // Skip field name: p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { if (!prop.visibleInView(activeView)) { p.skipChildren(); continue; } try { bean = prop.deserializeSetAndReturn(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } continue; } handleUnknownVanilla(p, ctxt, bean, propName); } return bean; }
protected static void expectField(String name, JsonParser p) throws IOException, JsonParseException { if (p.getCurrentToken() != JsonToken.FIELD_NAME) { throw new JsonParseException(p, "expected field name, but was: " + p.getCurrentToken()); } if (!name.equals(p.getCurrentName())) { throw new JsonParseException(p, "expected field '" + name + "', but was: '" + p.getCurrentName() + "'"); } p.nextToken(); }
protected Object mapObject(JsonParser p, DeserializationContext ctxt, Map<Object,Object> m) throws IOException { JsonToken t = p.getCurrentToken(); if (t == JsonToken.START_OBJECT) { t = p.nextToken(); } if (t == JsonToken.END_OBJECT) { return m; } // NOTE: we are guaranteed to point to FIELD_NAME String key = p.getCurrentName(); do { p.nextToken(); // and possibly recursive merge here Object old = m.get(key); Object newV; if (old != null) { newV = deserialize(p, ctxt, old); } else { newV = deserialize(p, ctxt); } if (newV != old) { m.put(key, newV); } } while ((key = p.nextFieldName()) != null); return m; }
@Override public Applications deserialize(JsonParser jp, DeserializationContext context) throws IOException { if (Thread.currentThread().isInterrupted()) { throw new JsonParseException(jp, "processing aborted"); while((jsonToken = jp.nextToken()) != JsonToken.END_OBJECT){ String fieldName = jp.getCurrentName(); jsonToken = jp.nextToken(); ObjectReader applicationReader = DeserializerStringCache.init(mapper.readerFor(Application.class), context); if (jsonToken == JsonToken.START_ARRAY) { while (jp.nextToken() != JsonToken.END_ARRAY) { apps.addApplication(applicationReader.readValue(jp));
/** * Streamlined version that is only used when no "special" * features are enabled. */ private final Object vanillaDeserialize(JsonParser p, DeserializationContext ctxt, JsonToken t) throws IOException { final Object bean = _valueInstantiator.createUsingDefault(ctxt); // [databind#631]: Assign current value, to be accessible by custom serializers p.setCurrentValue(bean); if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) { String propName = p.getCurrentName(); do { p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case try { prop.deserializeAndSet(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } continue; } handleUnknownVanilla(p, ctxt, bean, propName); } while ((propName = p.nextFieldName()) != null); } return bean; }
public InstanceInfo deserialize(JsonParser jp, DeserializationContext context) throws IOException { if (Thread.currentThread().isInterrupted()) { throw new JsonParseException(jp, "processing aborted"); while ((jsonToken = jp.nextToken()) != JsonToken.END_OBJECT) { InstanceInfoField instanceInfoField = InstanceInfoField.lookup.find(jp); jsonToken = jp.nextToken(); if (instanceInfoField != null && jsonToken != JsonToken.VALUE_NULL) { switch(instanceInfoField) { ()->{ try { return jp.getText().toUpperCase(); } catch (IOException e) { throw new RuntimeJsonMappingException(e.getMessage()); break; case PORT: while ((jsonToken = jp.nextToken()) != JsonToken.END_OBJECT) { PortField field = PortField.lookup.find(jp); switch(field) { break; default: autoUnmarshalEligible(jp.getCurrentName(), jp.getValueAsString(), builder.getRawInstance()); autoUnmarshalEligible(jp.getCurrentName(), jp.getValueAsString(), builder.getRawInstance());
if (!nested) { token = parser.nextToken(); if (!nested && token != JsonToken.START_OBJECT) { throw new IOException("Expected data to start with an Object, but was " + token); token = parser.nextToken(); while (token != JsonToken.END_OBJECT) { switch (token) { case FIELD_NAME: fieldName = parser.getCurrentName(); break; case START_OBJECT: case FLOAT: if (handleFloatNumbersAsText) { doc.setString(fieldName, parser.getText()); case DOUBLE: if (handleFloatNumbersAsText) { doc.setString(fieldName, parser.getText()); case BIG_DECIMAL: if (handleFloatNumbersAsText) { doc.setString(fieldName, parser.getText()); token = parser.nextToken();
key = p.nextFieldName(); } else if (p.hasToken(JsonToken.FIELD_NAME)) { key = p.getCurrentName(); } else { key = null; JsonToken t = p.nextToken(); // to get to value if (_ignorableProperties != null && _ignorableProperties.contains(key)) { p.skipChildren(); // and skip it (in case of array/object) continue; p.nextToken(); // from value to END_OBJECT or FIELD_NAME Map<Object,Object> result; try {
try { JsonParser parser = jf.createParser(jsonmessage); parser.nextToken(); //shift past the START_OBJECT that begins the JSON while (parser.nextToken() != JsonToken.END_OBJECT) { String fieldname = parser.getCurrentName(); if (!INTERESTING_FIELDS.contains(fieldname)) { parser.skipChildren(); continue; parser.nextToken(); // move to value, or START_OBJECT/START_ARRAY String value; if (parser.getCurrentToken() == JsonToken.START_ARRAY) value += parser.getText(); value = parser.getText();
private static List<String> readAttachmentsObject(JsonParser jsonParser) throws IOException { List<String> attachmentNameList = new ArrayList<String>(); while(jsonParser.nextToken() != JsonToken.END_OBJECT) { String attachmentName = jsonParser.getCurrentName(); jsonParser.nextToken(); if(jsonParser.getCurrentToken() != JsonToken.START_OBJECT) { String message = CouchDbDocument.ATTACHMENTS_NAME + " contains an invalid object."; throw new JsonParseException(message, jsonParser.getCurrentLocation()); } readIgnoreObject(jsonParser); attachmentNameList.add(attachmentName); } return attachmentNameList; }
@Override public String readStringUTF() throws IOException { if ( unknownFallbackReadFieldName != null ) { String unkReadAhead = unknownFallbackReadFieldName; unknownFallbackReadFieldName = null; return unkReadAhead; } JsonToken jsonToken = input.nextToken(); if ( jsonToken == JsonToken.VALUE_NULL ) return null; if ( jsonToken == JsonToken.FIELD_NAME ) return input.getCurrentName(); return input.getText(); }
protected Object deserializeEnumUsingPropertyBased(final JsonParser p, final DeserializationContext ctxt, final PropertyBasedCreator creator) throws IOException { PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, null); JsonToken t = p.getCurrentToken(); for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); p.nextToken(); // to point to value SettableBeanProperty creatorProp = creator.findCreatorProperty(propName); if (creatorProp != null) { buffer.assignParameter(creatorProp, _deserializeWithErrorWrapping(p, ctxt, creatorProp)); continue; } if (buffer.readIdProperty(propName)) { continue; } } return creator.build(ctxt, buffer); }
/** * Method that fetches next token (as if calling {@link #nextToken}) and * verifies whether it is {@link JsonToken#FIELD_NAME} with specified name * and returns result of that comparison. * It is functionally equivalent to: *<pre> * return (nextToken() == JsonToken.FIELD_NAME) && str.getValue().equals(getCurrentName()); *</pre> * but may be faster for parser to verify, and can therefore be used if caller * expects to get such a property name from input next. * * @param str Property name to compare next token to (if next token is * <code>JsonToken.FIELD_NAME</code>) */ public boolean nextFieldName(SerializableString str) throws IOException { return (nextToken() == JsonToken.FIELD_NAME) && str.getValue().equals(getCurrentName()); }
/** * Parses attributes as a Map, used in both parseWebIdentitySessionContext and parseSessionContext * * @return attributes for either session context or web identity session context * @throws IOException */ private Map<String, String> parseAttributes() throws IOException { if (jsonParser.nextToken() != JsonToken.START_OBJECT) { throw new JsonParseException("Not a Attributes object", jsonParser.getCurrentLocation()); } Map<String, String> attributes = new HashMap<>(); while (jsonParser.nextToken() != JsonToken.END_OBJECT) { String key = jsonParser.getCurrentName(); String value = jsonParser.nextTextValue(); attributes.put(key, value); } return attributes; }
String propertyName = p.getCurrentName(); do { p.nextToken(); SettableBeanProperty property = _beanProperties.find(propertyName);
keyName = p.nextFieldName(); } else if (p.hasToken(JsonToken.FIELD_NAME)) { keyName = p.getCurrentName(); } else { keyName = null; JsonToken t = p.nextToken(); // to get to value p.nextToken(); // from value to END_OBJECT or FIELD_NAME EnumMap<?,?> result; try { p.nextToken(); p.skipChildren(); continue;
/** * Streamlined version that is only used when no "special" * features are enabled. */ private final Object vanillaDeserialize(JsonParser p, DeserializationContext ctxt, JsonToken t) throws IOException { Object bean = _valueInstantiator.createUsingDefault(ctxt); for (; p.getCurrentToken() == JsonToken.FIELD_NAME; p.nextToken()) { String propName = p.getCurrentName(); // Skip field name: p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case try { bean = prop.deserializeSetAndReturn(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); } } else { handleUnknownVanilla(p, ctxt, bean, propName); } } return bean; }