Search in sources :

Example 1 with KeyDeserializer

use of org.codehaus.jackson.map.KeyDeserializer in project st-js by st-js.

the class JSMapDeserializer method _readAndBind.

/*
	 * /********************************************************** /* Internal methods
	 * /**********************************************************
	 */
/**
 * <p>_readAndBind.</p>
 *
 * @param jp a {@link org.codehaus.jackson.JsonParser} object.
 * @param ctxt a {@link org.codehaus.jackson.map.DeserializationContext} object.
 * @param result a {@link org.stjs.javascript.Map} object.
 * @throws java.io.IOException if any.
 * @throws org.codehaus.jackson.JsonProcessingException if any.
 */
protected final void _readAndBind(JsonParser jp, DeserializationContext ctxt, Map<String, Object> result) throws IOException, JsonProcessingException {
    JsonToken t = jp.getCurrentToken();
    if (t == JsonToken.START_OBJECT) {
        t = jp.nextToken();
    }
    final KeyDeserializer keyDes = _keyDeserializer;
    final JsonDeserializer<Object> valueDes = _valueDeserializer;
    final TypeDeserializer typeDeser = _valueTypeDeserializer;
    for (; t == JsonToken.FIELD_NAME; t = jp.nextToken()) {
        // Must point to field name
        String fieldName = jp.getCurrentName();
        Object key = (keyDes == null) ? fieldName : keyDes.deserializeKey(fieldName, ctxt);
        // 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;
        } else if (typeDeser == null) {
            value = valueDes.deserialize(jp, ctxt);
        } else {
            value = valueDes.deserializeWithType(jp, ctxt, typeDeser);
        }
        /*
			 * !!! 23-Dec-2008, tatu: should there be an option to verify that there are no duplicate field names?
			 * (and/or what to do, keep-first or keep-last)
			 */
        result.$put(key.toString(), value);
    }
}
Also used : JsonToken(org.codehaus.jackson.JsonToken) TypeDeserializer(org.codehaus.jackson.map.TypeDeserializer) KeyDeserializer(org.codehaus.jackson.map.KeyDeserializer)

Aggregations

JsonToken (org.codehaus.jackson.JsonToken)1 KeyDeserializer (org.codehaus.jackson.map.KeyDeserializer)1 TypeDeserializer (org.codehaus.jackson.map.TypeDeserializer)1