本文整理汇总了Java中com.fasterxml.jackson.databind.JsonDeserializer.deserialize方法的典型用法代码示例。如果您正苦于以下问题:Java JsonDeserializer.deserialize方法的具体用法?Java JsonDeserializer.deserialize怎么用?Java JsonDeserializer.deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.JsonDeserializer
的用法示例。
在下文中一共展示了JsonDeserializer.deserialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Analyzer<?> deserialize(final JsonParser p, final DeserializationContext ctxt) throws IOException, JsonProcessingException {
final JsonDeserializer<?> specDeserializer = ctxt
.findNonContextualValueDeserializer(TypeFactory.defaultInstance().uncheckedSimpleType(AnalyzerSpec.class));
final AnalyzerSpec spec = (AnalyzerSpec) specDeserializer.deserialize(p, ctxt);
final AnalyzerCreationResult creationResult = spec.getAnalyzerType().tryCreateAnalyzer(spec);
if (!creationResult.wasSuccessful()) {
throw new IOException(
"Could not create analyzer from spec, global result: " + creationResult.getGlobalResult() + ", parameter results: ");
}
return creationResult.getAnalyzer();
}
示例2: _deserializeFromSingleValue
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
@Override
protected T _deserializeFromSingleValue(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
JsonDeserializer<?> valueDes = _valueDeserializer;
final TypeDeserializer typeDeser = _typeDeserializerForValue;
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);
}
@SuppressWarnings("unchecked")
T result = (T) Sequences.sequence(value);
return result;
}
示例3: _deserializeTypedUsingDefaultImpl
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
protected Object _deserializeTypedUsingDefaultImpl(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext, TokenBuffer paramTokenBuffer)
{
JsonDeserializer localJsonDeserializer = _findDefaultImplDeserializer(paramDeserializationContext);
if (localJsonDeserializer != null)
{
if (paramTokenBuffer != null)
{
paramTokenBuffer.writeEndObject();
JsonParser localJsonParser = paramTokenBuffer.asParser(paramJsonParser);
paramJsonParser = localJsonParser;
localJsonParser.nextToken();
}
return localJsonDeserializer.deserialize(paramJsonParser, paramDeserializationContext);
}
Object localObject = TypeDeserializer.deserializeIfNatural(paramJsonParser, paramDeserializationContext, this._baseType);
if (localObject != null)
return localObject;
if (paramJsonParser.getCurrentToken() == JsonToken.START_ARRAY)
return super.deserializeTypedFromAny(paramJsonParser, paramDeserializationContext);
throw paramDeserializationContext.wrongTokenException(paramJsonParser, JsonToken.FIELD_NAME, "missing property '" + this._typePropertyName + "' that is to contain type id (for class " + baseTypeName() + ")");
}
示例4: _deserialize
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
private final Object _deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
{
boolean bool = paramJsonParser.isExpectedStartArrayToken();
String str = _locateTypeId(paramJsonParser, paramDeserializationContext);
JsonDeserializer localJsonDeserializer = _findDeserializer(paramDeserializationContext, str);
if ((this._typeIdVisible) && (paramJsonParser.getCurrentToken() == JsonToken.START_OBJECT))
{
TokenBuffer localTokenBuffer = new TokenBuffer(null);
localTokenBuffer.writeStartObject();
localTokenBuffer.writeFieldName(this._typePropertyName);
localTokenBuffer.writeString(str);
JsonParserSequence localJsonParserSequence = JsonParserSequence.createFlattened(localTokenBuffer.asParser(paramJsonParser), paramJsonParser);
paramJsonParser = localJsonParserSequence;
localJsonParserSequence.nextToken();
}
Object localObject = localJsonDeserializer.deserialize(paramJsonParser, paramDeserializationContext);
if ((bool) && (paramJsonParser.nextToken() != JsonToken.END_ARRAY))
throw paramDeserializationContext.wrongTokenException(paramJsonParser, JsonToken.END_ARRAY, "expected closing END_ARRAY after type information and deserialized value");
return localObject;
}
示例5: _deserialize
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
private final Object _deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext)
{
if (paramJsonParser.getCurrentToken() != JsonToken.START_OBJECT)
throw paramDeserializationContext.wrongTokenException(paramJsonParser, JsonToken.START_OBJECT, "need JSON Object to contain As.WRAPPER_OBJECT type information for class " + baseTypeName());
if (paramJsonParser.nextToken() != JsonToken.FIELD_NAME)
throw paramDeserializationContext.wrongTokenException(paramJsonParser, JsonToken.FIELD_NAME, "need JSON String that contains type id (for subtype of " + baseTypeName() + ")");
String str = paramJsonParser.getText();
JsonDeserializer localJsonDeserializer = _findDeserializer(paramDeserializationContext, str);
paramJsonParser.nextToken();
if ((this._typeIdVisible) && (paramJsonParser.getCurrentToken() == JsonToken.START_OBJECT))
{
TokenBuffer localTokenBuffer = new TokenBuffer(null);
localTokenBuffer.writeStartObject();
localTokenBuffer.writeFieldName(this._typePropertyName);
localTokenBuffer.writeString(str);
JsonParserSequence localJsonParserSequence = JsonParserSequence.createFlattened(localTokenBuffer.asParser(paramJsonParser), paramJsonParser);
paramJsonParser = localJsonParserSequence;
localJsonParserSequence.nextToken();
}
Object localObject = localJsonDeserializer.deserialize(paramJsonParser, paramDeserializationContext);
if (paramJsonParser.nextToken() != JsonToken.END_OBJECT)
throw paramDeserializationContext.wrongTokenException(paramJsonParser, JsonToken.END_OBJECT, "expected closing END_OBJECT after type information and deserialized value");
return localObject;
}
示例6: deserializeUsingCustom
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
private Collection<String> deserializeUsingCustom(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext, Collection<String> paramCollection, JsonDeserializer<String> paramJsonDeserializer)
{
while (true)
{
JsonToken localJsonToken = paramJsonParser.nextToken();
if (localJsonToken == JsonToken.END_ARRAY)
break;
String str;
if (localJsonToken == JsonToken.VALUE_NULL)
str = null;
else
str = (String)paramJsonDeserializer.deserialize(paramJsonParser, paramDeserializationContext);
paramCollection.add(str);
}
return paramCollection;
}
示例7: deserialize
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
public Collection<Object> deserialize(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext, Collection<Object> paramCollection)
{
if (!paramJsonParser.isExpectedStartArrayToken())
return handleNonArray(paramJsonParser, paramDeserializationContext, paramCollection);
JsonDeserializer localJsonDeserializer = this._valueDeserializer;
TypeDeserializer localTypeDeserializer = this._valueTypeDeserializer;
while (true)
{
JsonToken localJsonToken = paramJsonParser.nextToken();
if (localJsonToken == JsonToken.END_ARRAY)
break;
Object localObject;
if (localJsonToken == JsonToken.VALUE_NULL)
localObject = null;
else if (localTypeDeserializer == null)
localObject = localJsonDeserializer.deserialize(paramJsonParser, paramDeserializationContext);
else
localObject = localJsonDeserializer.deserializeWithType(paramJsonParser, paramDeserializationContext, localTypeDeserializer);
paramCollection.add(localObject);
}
return paramCollection;
}
示例8: handleNonArray
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
protected final Collection<Object> handleNonArray(JsonParser paramJsonParser, DeserializationContext paramDeserializationContext, Collection<Object> paramCollection)
{
if (!paramDeserializationContext.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY))
throw paramDeserializationContext.mappingException(this._collectionType.getRawClass());
JsonDeserializer localJsonDeserializer = this._valueDeserializer;
TypeDeserializer localTypeDeserializer = this._valueTypeDeserializer;
Object localObject;
if (paramJsonParser.getCurrentToken() == JsonToken.VALUE_NULL)
localObject = null;
else if (localTypeDeserializer == null)
localObject = localJsonDeserializer.deserialize(paramJsonParser, paramDeserializationContext);
else
localObject = localJsonDeserializer.deserializeWithType(paramJsonParser, paramDeserializationContext, localTypeDeserializer);
paramCollection.add(localObject);
return paramCollection;
}
示例9: deserializeTypedFromObject
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
@Override
public Object deserializeTypedFromObject(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
JsonNode node = jp.readValueAsTree();
NamedDefinition res = NamedProviders.get((Class<NamedDefinition>) _baseType.getRawClass(), node.get("type").asText());
if (res == null) {
return null;
}
JavaType type = SimpleType.construct(res.getClass());
JsonParser jsonParser = new TreeTraversingParser(node, jp.getCodec());
if (jsonParser.getCurrentToken() == null) {
jsonParser.nextToken();
}
JsonDeserializer<Object> deser = ctxt.findContextualValueDeserializer(type, _property);
return deser.deserialize(jsonParser, ctxt);
}
示例10: _deserializeEntries
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected T _deserializeEntries(JsonParser jp, DeserializationContext ctxt) throws IOException {
final KeyDeserializer keyDes = keyDeserializer;
final JsonDeserializer<?> valueDes = valueDeserializer;
final TypeDeserializer typeDeser = typeDeserializerForValue;
MapF<Object, Object> map = newInstance();
for (; jp.getCurrentToken() == JsonToken.FIELD_NAME; jp.nextToken()) {
String fieldName = jp.getCurrentName();
Object key = (keyDes == null) ? fieldName : keyDes.deserializeKey(fieldName, ctxt);
JsonToken t = jp.nextToken();
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);
}
map.put(key, value);
}
return (T) map.unmodifiable();
}
示例11: _deserializeContents
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected T _deserializeContents(JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonDeserializer<?> valueDes = valueDeserializer;
JsonToken t;
final TypeDeserializer typeDeser = typeDeserializerForValue;
CollectionF<Object> collection = newInstance();
while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
Object value;
if (t == JsonToken.VALUE_NULL) {
value = valueDes.getNullValue();
} else if (typeDeser == null) {
value = valueDes.deserialize(jp, ctxt);
} else {
value = valueDes.deserializeWithType(jp, ctxt, typeDeser);
}
collection.add(value);
}
return (T) collection.unmodifiable();
}
示例12: _deserializeSingle
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected T _deserializeSingle(JsonParser jp, DeserializationContext ctxt) throws IOException {
JsonDeserializer<?> valueDes = valueDeserializer;
final TypeDeserializer typeDeser = typeDeserializerForValue;
CollectionF<Object> collection = newInstance();
Object value;
if (jp.getCurrentToken() == JsonToken.VALUE_NULL) {
value = valueDes.getNullValue();
} else if (typeDeser == null) {
value = valueDes.deserialize(jp, ctxt);
} else {
value = valueDes.deserializeWithType(jp, ctxt, typeDeser);
}
collection.add(value);
return (T) collection.unmodifiable();
}
示例13: shouldThrowOnNullTree
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
@Test
public void shouldThrowOnNullTree() throws Exception {
exception.expect(JWTDecodeException.class);
exception.expectMessage("Parsing the Header's JSON resulted on a Null map");
JsonDeserializer deserializer = new HeaderDeserializer();
JsonParser parser = mock(JsonParser.class);
ObjectCodec codec = mock(ObjectCodec.class);
DeserializationContext context = mock(DeserializationContext.class);
when(codec.readValue(eq(parser), any(TypeReference.class))).thenReturn(null);
when(parser.getCodec()).thenReturn(codec);
deserializer.deserialize(parser, context);
}
示例14: deserialize
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
@Override
public Object deserialize(JsonParser p, DeserializationContext ctx) throws IOException {
if(jobsManager == null) {
throw new IllegalStateException("This deserializer need a jobsManager instance, see 'JobParametersDeserializer.setJobsManager'");
}
final JsonStreamContext jsc = p.getParsingContext();
String paramName = null;
JsonStreamContext parent = jsc;
while(parent != null) {
paramName = parent.getCurrentName();
if(paramName != null) {
break;
}
parent = parent.getParent();
}
if(parent == null) {
throw new NullPointerException("Something wrong: we can not find our parent object, " +
"may be you use this deserializer on custom object?");
}
JobParameters.Builder r = (JobParameters.Builder) parent.getParent().getCurrentValue();
String jobType = r.getType();
JobDescription desc = jobsManager.getDescription(jobType);
JobParameterDescription param = desc.getParameters().get(paramName);
TypeFactory typeFactory = ctx.getTypeFactory();
JavaType type;
if(param == null) {
type = typeFactory.constructType(Object.class);
} else {
type = typeFactory.constructType(param.getType());
}
JsonDeserializer<Object> deser = ctx.findNonContextualValueDeserializer(type);
try {
return deser.deserialize(p, ctx);
} catch (Exception e) {
throw new RuntimeException("Can not deserialize '" + jobType + "." + paramName + "' job parameter ", e );
}
}
示例15: deserialize
import com.fasterxml.jackson.databind.JsonDeserializer; //导入方法依赖的package包/类
@Override
public List<Object> deserialize(JsonParser jp, DeserializationContext ctxt)
throws IOException, JsonProcessingException {
List<Object> result = new ArrayList<Object>();
JsonDeserializer<Object> deser = ctxt.findRootValueDeserializer(contentType);
Object object;
// links is an object, so we parse till we find its end.
while (!JsonToken.END_OBJECT.equals(jp.nextToken())) {
if (!JsonToken.FIELD_NAME.equals(jp.getCurrentToken())) {
throw new JsonParseException("Expected relation name", jp.getCurrentLocation());
}
if (JsonToken.START_ARRAY.equals(jp.nextToken())) {
while (!JsonToken.END_ARRAY.equals(jp.nextToken())) {
object = deser.deserialize(jp, ctxt);
;
result.add(object);
}
} else {
object = deser.deserialize(jp, ctxt);
result.add(object);
}
}
return result;
}