Refine search
@SuppressWarnings("resource") public Object processUnwrapped(JsonParser originalParser, DeserializationContext ctxt, Object bean, TokenBuffer buffered) throws IOException { for (int i = 0, len = _properties.size(); i < len; ++i) { SettableBeanProperty prop = _properties.get(i); JsonParser p = buffered.asParser(); p.nextToken(); prop.deserializeAndSet(p, ctxt, bean); } return bean; } }
/** * Method called to handle set of one or more unknown properties, * stored in their entirety in given {@link TokenBuffer} * (as field entries, name and value). */ @SuppressWarnings("resource") protected Object handleUnknownProperties(DeserializationContext ctxt, Object bean, TokenBuffer unknownTokens) throws IOException { // First: add closing END_OBJECT as marker unknownTokens.writeEndObject(); // note: buffer does NOT have starting START_OBJECT JsonParser bufferParser = unknownTokens.asParser(); while (bufferParser.nextToken() != JsonToken.END_OBJECT) { String propName = bufferParser.getCurrentName(); // Unknown: let's call handler method bufferParser.nextToken(); handleUnknownProperty(bufferParser, ctxt, bean, propName); } return bean; }
/** * Helper method that will append contents of given buffer into this * buffer. * Not particularly optimized; can be made faster if there is need. * * @return This buffer */ @SuppressWarnings("resource") public TokenBuffer append(TokenBuffer other) throws IOException { // Important? If source has native ids, need to store if (!_hasNativeTypeIds) { _hasNativeTypeIds = other.canWriteTypeId(); } if (!_hasNativeObjectIds) { _hasNativeObjectIds = other.canWriteObjectId(); } _mayHaveNativeIds = _hasNativeTypeIds | _hasNativeObjectIds; JsonParser p = other.asParser(); while (p.nextToken() != null) { copyCurrentStructure(p); } return this; }
@SuppressWarnings("resource") protected final Object _deserialize(JsonParser p, DeserializationContext ctxt, int index, String typeId) throws IOException { JsonParser p2 = _tokens[index].asParser(p); JsonToken t = p2.nextToken(); // 29-Sep-2015, tatu: As per [databind#942], nulls need special support if (t == JsonToken.VALUE_NULL) { return null; } TokenBuffer merged = new TokenBuffer(p, ctxt); merged.writeStartArray(); merged.writeString(typeId); merged.copyCurrentStructure(p2); merged.writeEndArray(); // needs to point to START_OBJECT (or whatever first token is) JsonParser mp = merged.asParser(p); mp.nextToken(); return _properties[index].getProperty().deserialize(mp, ctxt); }
@SuppressWarnings("resource") protected final void _deserializeAndSet(JsonParser p, DeserializationContext ctxt, Object bean, int index, String typeId) throws IOException { /* Ok: time to mix type id, value; and we will actually use "wrapper-array" * style to ensure we can handle all kinds of JSON constructs. */ JsonParser p2 = _tokens[index].asParser(p); JsonToken t = p2.nextToken(); // 29-Sep-2015, tatu: As per [databind#942], nulls need special support if (t == JsonToken.VALUE_NULL) { _properties[index].getProperty().set(bean, null); return; } TokenBuffer merged = new TokenBuffer(p, ctxt); merged.writeStartArray(); merged.writeString(typeId); merged.copyCurrentStructure(p2); merged.writeEndArray(); // needs to point to START_OBJECT (or whatever first token is) JsonParser mp = merged.asParser(p); mp.nextToken(); _properties[index].getProperty().deserializeAndSet(mp, ctxt, bean); }
@SuppressWarnings("resource") protected Object _deserializeTypedForId(JsonParser p, DeserializationContext ctxt, TokenBuffer tb) throws IOException { String typeId = p.getText(); JsonDeserializer<Object> deser = _findDeserializer(ctxt, typeId); if (_typeIdVisible) { // need to merge id back in JSON input? if (tb == null) { tb = new TokenBuffer(p, ctxt); } tb.writeFieldName(p.getCurrentName()); tb.writeString(typeId); } if (tb != null) { // need to put back skipped properties? // 02-Jul-2016, tatu: Depending on for JsonParserSequence is initialized it may // try to access current token; ensure there isn't one p.clearCurrentToken(); p = JsonParserSequence.createFlattened(false, tb.asParser(p), p); } // Must point to the next value; tb had no current, jp pointed to VALUE_STRING: p.nextToken(); // to skip past String value // deserializer should take care of closing END_OBJECT as well return deser.deserialize(p, ctxt); }
@SuppressWarnings("resource") @Override public final Object deserializeKey(String key, DeserializationContext ctxt) throws IOException { if (key == null) { // is this even legal call? return null; } TokenBuffer tb = new TokenBuffer(ctxt.getParser(), ctxt); tb.writeString(key); try { // Ugh... should not have to give parser which may or may not be correct one... JsonParser p = tb.asParser(); p.nextToken(); Object result = _delegate.deserialize(p, ctxt); if (result != null) { return result; } return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation"); } catch (Exception re) { return ctxt.handleWeirdKey(_keyClass, key, "not a valid representation: %s", re.getMessage()); } }
/** * Helper method called for rare case of pointing to {@link JsonToken#VALUE_NULL} * token. While this is most often an erroneous condition, there is one specific * case with XML handling where polymorphic type with no properties is exposed * as such, and should be handled same as empty Object. * * @since 2.7 */ protected Object deserializeFromNull(JsonParser p, DeserializationContext ctxt) throws IOException { // 17-Dec-2015, tatu: Highly specialized case, mainly to support polymorphic // "empty" POJOs deserialized from XML, where empty XML tag synthesizes a // `VALUE_NULL` token. if (p.requiresCustomCodec()) { // not only XML module, but mostly it... @SuppressWarnings("resource") TokenBuffer tb = new TokenBuffer(p, ctxt); tb.writeEndObject(); JsonParser p2 = tb.asParser(p); p2.nextToken(); // to point to END_OBJECT // note: don't have ObjectId to consider at this point, so: Object ob = _vanillaProcessing ? vanillaDeserialize(p2, ctxt, JsonToken.END_OBJECT) : deserializeFromObject(p2, ctxt); p2.close(); return ob; } return ctxt.handleUnexpectedToken(handledType(), p); }
if (t == JsonToken.START_OBJECT) { if (p.nextToken() != JsonToken.FIELD_NAME) { ctxt.reportWrongTokenException(baseType(), JsonToken.FIELD_NAME, "need JSON String that contains type id (for subtype of "+baseTypeName()+")"); p.nextToken(); p = JsonParserSequence.createFlattened(false, tb.asParser(p), p); p.nextToken();
protected Object _deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { if (jp.canReadTypeId()) { Object typeId = jp.getTypeId(); if (typeId != null) { return _deserializeWithNativeTypeId(jp, ctxt, typeId); } } String typeId = _locateTypeId(jp, ctxt); JsonDeserializer<Object> deser = _findDeserializer(ctxt, typeId); if (_typeIdVisible && !_usesExternalId() && jp.getCurrentToken() == JsonToken.START_OBJECT) { TokenBuffer tb = new TokenBuffer(null, false); tb.writeStartObject(); tb.writeFieldName(_typePropertyName); tb.writeString(typeId); jp = JsonParserSequence.createFlattened(false, tb.asParser(jp), jp); jp.nextToken(); } Object value = deser.deserialize(jp, ctxt); return value; } }