use of org.codehaus.jackson.map.TypeDeserializer 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);
}
}
use of org.codehaus.jackson.map.TypeDeserializer in project st-js by st-js.
the class JSArrayDeserializer method handleNonArray.
/**
* Helper method called when current token is no START_ARRAY. Will either throw an exception, or try to handle value
* as if member of implicit array, depending on configuration.
*/
private final Array<Object> handleNonArray(JsonParser jp, DeserializationContext ctxt, Array<Object> result) throws IOException, JsonProcessingException {
// [JACKSON-526]: implicit arrays from single values?
if (!ctxt.isEnabled(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY)) {
throw ctxt.mappingException(_collectionType.getRawClass());
}
JsonDeserializer<Object> valueDes = _valueDeserializer;
final TypeDeserializer typeDeser = _valueTypeDeserializer;
JsonToken t = jp.getCurrentToken();
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);
}
result.push(value);
return result;
}
use of org.codehaus.jackson.map.TypeDeserializer in project st-js by st-js.
the class JSArrayDeserializer method deserialize.
/**
* {@inheritDoc}
*/
@Override
public Array<Object> deserialize(JsonParser jp, DeserializationContext ctxt, Array<Object> result) throws IOException, JsonProcessingException {
// Ok: must point to START_ARRAY (or equivalent)
if (!jp.isExpectedStartArrayToken()) {
return handleNonArray(jp, ctxt, result);
}
JsonDeserializer<Object> valueDes = _valueDeserializer;
JsonToken t;
final TypeDeserializer typeDeser = _valueTypeDeserializer;
while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
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);
}
result.push(value);
}
return result;
}
Aggregations