@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 ObjectCodec _codec() { ObjectCodec c = getCodec(); if (c == null) { throw new IllegalStateException("No ObjectCodec defined for parser, needed for deserialization"); } return c; }
/** * 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; }
@Override public long readFLong() throws IOException { input.nextToken(); return input.getLongValue(); }
/** * 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; }
return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.deserialize(p, ctxt)); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); Object bean = _valueInstantiator.createUsingDefault(ctxt); final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null; for (; p.getCurrentToken() == JsonToken.FIELD_NAME; p.nextToken()) { String propName = p.getCurrentName(); p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case if (activeView != null && !prop.visibleInView(activeView)) { p.skipChildren(); continue; bean = prop.deserializeSetAndReturn(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); tokens.writeFieldName(propName); tokens.copyCurrentStructure(p);
public T processJsonObject(JsonParser jsonParser) throws IOException { while (!jsonParser.nextFieldName(fieldName)) { if (!jsonParser.hasCurrentToken()) { throw new JsonParseException(jsonParser, "Unexpected end of object"); } if (jsonParser.getCurrentToken() == END_OBJECT) { // Unable to find matching field return null; } jsonParser.skipChildren(); // Skip nested structure if currently at the start of one } jsonParser.nextToken(); // Shift to first token of the value return delegate.extract(jsonParser); }
throws IOException JsonToken t = p.getCurrentToken(); if (t == JsonToken.START_OBJECT) { t = p.nextToken(); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null; for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); SettableBeanProperty prop = _beanProperties.find(propName); p.nextToken(); if (prop != null) { // normal case if (activeView != null && !prop.visibleInView(activeView)) { p.skipChildren(); continue; prop.deserializeAndSet(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); tokens.writeFieldName(propName); tokens.copyCurrentStructure(p); } else {
PropertyValueBuffer buffer = creator.startBuilding(p, ctxt, _objectIdReader); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); JsonToken t = p.getCurrentToken(); for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); p.nextToken(); // to point to value t = p.nextToken(); // to move to following FIELD_NAME/END_OBJECT Object bean; try { bean = creator.build(ctxt, buffer); } catch (Exception e) { wrapAndThrow(e, _beanType.getRawClass(), propName, ctxt); continue; // never gets here p.nextToken(); // to skip name tokens.copyCurrentStructure(p); t = p.nextToken(); if (bean.getClass() != _beanType.getRawClass()) { return ctxt.reportBadDefinition(_beanType, String.format( "Cannot create polymorphic instances with external type ids (%s -> %s)", _beanType, bean.getClass()));
throws IOException final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null; for (JsonToken t = p.getCurrentToken(); t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); SettableBeanProperty prop = _beanProperties.find(propName); p.nextToken(); if (prop != null) { // normal case if (activeView != null && !prop.visibleInView(activeView)) { p.skipChildren(); continue; builder = prop.deserializeSetAndReturn(p, ctxt, builder); } catch (Exception e) { wrapAndThrow(e, builder, propName, ctxt); tokens.writeFieldName(propName); tokens.copyCurrentStructure(p); tokens.writeEndObject(); return _unwrappedPropertyHandler.processUnwrapped(p, ctxt, builder, tokens);
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; }
@Override public DateTime deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { JsonToken t = jp.getCurrentToken(); if (t == JsonToken.VALUE_NUMBER_INT) { return DateTimes.utc(jp.getLongValue()); } if (t == JsonToken.VALUE_STRING) { String str = jp.getText().trim(); if (str.length() == 0) { // [JACKSON-360] return null; } // make sure to preserve time zone information when parsing timestamps return DateTimes.ISO_DATE_OR_TIME_WITH_OFFSET.parse(str); } throw ctxt.mappingException(getValueClass()); } }
if (p.hasToken(JsonToken.START_OBJECT)) { p.nextToken(); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); return deserializeWithUnwrapped(p, ctxt, builder, tokens); Class<?> view = ctxt.getActiveView(); if (view != null) { return deserializeWithView(p, ctxt, builder, view); JsonToken t = p.getCurrentToken(); t = p.nextToken(); for (; t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); builder = prop.deserializeSetAndReturn(p, ctxt, builder); } catch (Exception e) { wrapAndThrow(e, builder, propName, ctxt);
throws IOException final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null; final ExternalTypeHandler ext = _externalTypeIdHandler.start(); for (JsonToken t = p.getCurrentToken(); t == JsonToken.FIELD_NAME; t = p.nextToken()) { String propName = p.getCurrentName(); t = p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case ext.handleTypePropertyValue(p, ctxt, propName, bean); if (activeView != null && !prop.visibleInView(activeView)) { p.skipChildren(); continue; prop.deserializeAndSet(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt);
if (p.hasToken(JsonToken.VALUE_STRING) && ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) { String str = p.getText(); if (str.length() == 0) { return null; ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)); if (!canWrap) { JsonToken t = p.getCurrentToken(); if (t == JsonToken.VALUE_STRING return deserializeFromBase64(p, ctxt); return (Object[]) ctxt.handleUnexpectedToken(_containerType.getRawClass(), p); JsonToken t = p.getCurrentToken(); Object value; value = _elementDeserializer.deserialize(p, ctxt); } else { value = _elementDeserializer.deserializeWithType(p, ctxt, _elementTypeDeserializer);
return _valueInstantiator.createUsingDelegate(ctxt, _delegateDeserializer.deserialize(p, ctxt)); TokenBuffer tokens = new TokenBuffer(p, ctxt); tokens.writeStartObject(); final Object bean = _valueInstantiator.createUsingDefault(ctxt); p.setCurrentValue(bean); final Class<?> activeView = _needViewProcesing ? ctxt.getActiveView() : null; String propName = p.hasTokenId(JsonTokenId.ID_FIELD_NAME) ? p.getCurrentName() : null; for (; propName != null; propName = p.nextFieldName()) { p.nextToken(); SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { // normal case if ((activeView != null) && !prop.visibleInView(activeView)) { p.skipChildren(); continue; prop.deserializeAndSet(p, ctxt, bean); } catch (Exception e) { wrapAndThrow(e, bean, propName, ctxt); tokens.writeFieldName(propName); tokens.copyCurrentStructure(p); continue;
@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(); apps.setVersion(jp.getValueAsLong()); } else if (appHashCodeKey.equals(fieldName)){ apps.setAppsHashCode(jp.getValueAsString()); while (jp.nextToken() != JsonToken.END_ARRAY) { apps.addApplication(applicationReader.readValue(jp));
private void consumeEnd() { try { JsonToken jsonToken = input.nextToken(); if ( jsonToken == null ) return; if ( ! jsonToken.isStructEnd() ) { throw new RuntimeException("end of structure expected found:"+jsonToken+" : value:"+input.getValueAsString()+" fname:'"+input.getCurrentName()+"'"); } } catch (IOException e) { FSTUtil.<RuntimeException>rethrow(e); } }
protected final Object deserializeWithView(JsonParser p, DeserializationContext ctxt, Object bean, Class<?> activeView) throws IOException { if (p.hasTokenId(JsonTokenId.ID_FIELD_NAME)) { String propName = p.getCurrentName(); do { p.nextToken(); // TODO: 06-Jan-2015, tatu: try streamlining call sequences here as well SettableBeanProperty prop = _beanProperties.find(propName); if (prop != null) { if (!prop.visibleInView(activeView)) { p.skipChildren(); continue; } 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; }
@Override public Slice extract(JsonParser jsonParser) throws IOException { JsonToken token = jsonParser.getCurrentToken(); if (token == null) { throw new JsonParseException(jsonParser, "Unexpected end of value"); } if (!token.isScalarValue() || token == VALUE_NULL) { return null; } return utf8Slice(jsonParser.getText()); } }