Java Code Examples for com.fasterxml.jackson.databind.DeserializationContext#readValue()

The following examples show how to use com.fasterxml.jackson.databind.DeserializationContext#readValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtensionClientOutputDeserializer.java    From webauthn4j with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ExtensionClientOutput<?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {

    String name = p.getParsingContext().getCurrentName();
    if (name == null) {
        name = p.getParsingContext().getParent().getCurrentName();
    }

    DeserializationConfig config = ctxt.getConfig();
    AnnotatedClass annotatedClass = AnnotatedClassResolver.resolveWithoutSuperTypes(config, ExtensionClientOutput.class);
    Collection<NamedType> namedTypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(config, annotatedClass);

    for (NamedType namedType : namedTypes) {
        if (Objects.equals(namedType.getName(), name)) {
            return (ExtensionClientOutput<?>) ctxt.readValue(p, namedType.getType());
        }
    }

    logger.warn("Unknown extension '{}' is contained.", name);
    return ctxt.readValue(p, UnknownExtensionClientOutput.class);
}
 
Example 2
Source File: CloudEventDeserializer.java    From sdk-java with Apache License 2.0 6 votes vote down vote up
@Override
public CloudEvent deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    // In future we could eventually find a better solution avoiding this buffering step, but now this is the best option
    // Other sdk does the same in order to support all versions
    ObjectNode node = ctxt.readValue(p, ObjectNode.class);

    try {
        return new JsonMessage(p, node).read(CloudEventBuilder::fromSpecVersion);
    } catch (RuntimeException e) {
        // Yeah this is bad but it's needed to support checked exceptions...
        if (e.getCause() instanceof IOException) {
            throw (IOException) e.getCause();
        }
        throw MismatchedInputException.wrapWithPath(e, null);
    }
}
 
Example 3
Source File: ExtensionAuthenticatorOutputDeserializer.java    From webauthn4j with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ExtensionAuthenticatorOutput<?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {

    String name = p.getParsingContext().getCurrentName();
    if (name == null) {
        name = p.getParsingContext().getParent().getCurrentName();
    }

    DeserializationConfig config = ctxt.getConfig();
    AnnotatedClass annotatedClass = AnnotatedClassResolver.resolveWithoutSuperTypes(config, ExtensionAuthenticatorOutput.class);
    Collection<NamedType> namedTypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(config, annotatedClass);

    for (NamedType namedType : namedTypes) {
        if (Objects.equals(namedType.getName(), name)) {
            return (ExtensionAuthenticatorOutput<?>) ctxt.readValue(p, namedType.getType());
        }
    }

    logger.warn("Unknown extension '{}' is contained.", name);
    return ctxt.readValue(p, UnknownExtensionAuthenticatorOutput.class);
}
 
Example 4
Source File: AuthenticationExtensionClientInputDeserializer.java    From webauthn4j with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AuthenticationExtensionClientInput<?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {

    String name = p.getParsingContext().getCurrentName();
    if (name == null) {
        name = p.getParsingContext().getParent().getCurrentName();
    }

    DeserializationConfig config = ctxt.getConfig();
    AnnotatedClass annotatedClass = AnnotatedClassResolver.resolveWithoutSuperTypes(config, AuthenticationExtensionClientInput.class);
    Collection<NamedType> namedTypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(config, annotatedClass);

    for (NamedType namedType : namedTypes) {
        if (Objects.equals(namedType.getName(), name)) {
            return (AuthenticationExtensionClientInput<?>) ctxt.readValue(p, namedType.getType());
        }
    }

    logger.warn("Unknown extension '{}' is contained.", name);
    return ctxt.readValue(p, UnknownExtensionClientInput.class);
}
 
Example 5
Source File: KogitoModule.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public DataStream deserialize( JsonParser jp, DeserializationContext ctxt) throws IOException {
    DataStream stream = org.kie.kogito.rules.DataSource.createStream();
    List list = ctxt.readValue( jp, collectionType );
    list.forEach( stream::append );
    return stream;
}
 
Example 6
Source File: RiotAPIService.java    From orianna with MIT License 5 votes vote down vote up
@Override
public FailedRequestStrategy deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
    final Configuration config = context.readValue(parser, Configuration.class);
    try {
        return config.getType().getType().getConstructor(Configuration.class).newInstance(config);
    } catch(InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
        | SecurityException e) {
        LOGGER.error("Failed to instantiate strategy " + config.getType().getType().getCanonicalName() + "!", e);
        throw new OriannaException("Failed to instantiate strategy " + config.getType().getType().getCanonicalName()
            + "! Report this to the orianna team.", e);
    }
}
 
Example 7
Source File: KogitoQuarkusObjectMapper.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public DataStream deserialize( JsonParser jp, DeserializationContext ctxt) throws IOException {
    DataStream stream = DataSource.createStream();
    List list = ctxt.readValue( jp, collectionType );
    list.forEach( stream::append );
    return stream;
}
 
Example 8
Source File: KogitoQuarkusObjectMapper.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public DataStore deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    DataStore store = DataSource.createStore();
    List list = ctxt.readValue( jp, collectionType );
    list.forEach( store::add );
    return store;
}
 
Example 9
Source File: KogitoSpringObjectMapper.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public DataStream deserialize( JsonParser jp, DeserializationContext ctxt) throws IOException {
    DataStream stream = DataSource.createStream();
    List list = ctxt.readValue( jp, collectionType );
    list.forEach( stream::append );
    return stream;
}
 
Example 10
Source File: KogitoSpringObjectMapper.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Override
public DataStore deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
    DataStore store = DataSource.createStore();
    List list = ctxt.readValue( jp, collectionType );
    list.forEach( store::add );
    return store;
}
 
Example 11
Source File: AuthenticationExtensionsAuthenticatorOutputsEnvelopeDeserializer.java    From webauthn4j with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AuthenticationExtensionsAuthenticatorOutputsEnvelope<? extends ExtensionAuthenticatorOutput<?>> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    JavaType javaType = SimpleType.constructUnsafe(AuthenticationExtensionsAuthenticatorOutputs.class);
    AuthenticationExtensionsAuthenticatorOutputs<? extends ExtensionAuthenticatorOutput<?>> authenticationExtensionsAuthenticatorOutputs = ctxt.readValue(p, javaType);
    int length = (int) p.getCurrentLocation().getByteOffset();
    return new AuthenticationExtensionsAuthenticatorOutputsEnvelope<>(authenticationExtensionsAuthenticatorOutputs, length);
}
 
Example 12
Source File: NodeDeserializer.java    From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 5 votes vote down vote up
protected ValueNode deserializeValueNode(JsonParser p, DeserializationContext context, JsonLocation startLocation)
        throws IOException {
    final Model model = (Model) context.getAttribute(ATTRIBUTE_MODEL);
    final AbstractNode parent = (AbstractNode) context.getAttribute(ATTRIBUTE_PARENT);
    final JsonPointer ptr = (JsonPointer) context.getAttribute(ATTRIBUTE_POINTER);

    Object v = context.readValue(p, Object.class);

    ValueNode node = model.valueNode(parent, ptr, v);
    node.setStartLocation(createLocation(startLocation));
    node.setEndLocation(createLocation(p.getCurrentLocation()));

    return node;
}
 
Example 13
Source File: MonetaryAmountDeserializer.java    From jackson-datatype-money with MIT License 5 votes vote down vote up
@Override
public M deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
    BigDecimal amount = null;
    CurrencyUnit currency = null;

    while (parser.nextToken() != JsonToken.END_OBJECT) {
        final String field = parser.getCurrentName();

        parser.nextToken();

        if (field.equals(names.getAmount())) {
            amount = context.readValue(parser, BigDecimal.class);
        } else if (field.equals(names.getCurrency())) {
            currency = context.readValue(parser, CurrencyUnit.class);
        } else if (field.equals(names.getFormatted())) {
            //noinspection UnnecessaryContinue
            continue;
        } else if (context.isEnabled(FAIL_ON_UNKNOWN_PROPERTIES)) {
            throw UnrecognizedPropertyException.from(parser, MonetaryAmount.class, field,
                    Arrays.asList(names.getAmount(), names.getCurrency(), names.getFormatted()));
        } else {
            parser.skipChildren();
        }
    }

    checkPresent(parser, amount, names.getAmount());
    checkPresent(parser, currency, names.getCurrency());

    return factory.create(amount, currency);
}
 
Example 14
Source File: KernelService.java    From orianna with MIT License 5 votes vote down vote up
@Override
public FailedRequestStrategy deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
    final Configuration config = context.readValue(parser, Configuration.class);
    try {
        return config.getType().getType().getConstructor(Configuration.class).newInstance(config);
    } catch(InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
        | SecurityException e) {
        LOGGER.error("Failed to instantiate strategy " + config.getType().getType().getCanonicalName() + "!", e);
        throw new OriannaException("Failed to instantiate strategy " + config.getType().getType().getCanonicalName()
            + "! Report this to the orianna team.", e);
    }
}
 
Example 15
Source File: COSEKeyEnvelopeDeserializer.java    From webauthn4j with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public COSEKeyEnvelope deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    COSEKey coseKey = ctxt.readValue(p, COSEKey.class);
    int length = (int) p.getCurrentLocation().getByteOffset();
    return new COSEKeyEnvelope(coseKey, length);
}
 
Example 16
Source File: ConvertingDeserializer.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Object deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    Object substitute = deserializationContext.readValue(jsonParser, substituteType);
    return inputConverter.convertInput(substitute, detectedType, environment, valueMapper);
}
 
Example 17
Source File: AwsModule.java    From beam with Apache License 2.0 4 votes vote down vote up
@Override
public AWSCredentialsProvider deserialize(JsonParser jsonParser, DeserializationContext context)
    throws IOException {
  return context.readValue(jsonParser, AWSCredentialsProvider.class);
}
 
Example 18
Source File: UnknownExtensionClientOutputDeserializer.java    From webauthn4j with Apache License 2.0 4 votes vote down vote up
@Override
public UnknownExtensionClientOutput deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    Serializable value = ctxt.readValue(p, Serializable.class);
    return new UnknownExtensionClientOutput(p.getCurrentName(), value);
}
 
Example 19
Source File: UnknownExtensionAuthenticatorOutputDeserializer.java    From webauthn4j with Apache License 2.0 4 votes vote down vote up
@Override
public UnknownExtensionAuthenticatorOutput deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
    Serializable value = ctxt.readValue(p, Serializable.class);
    return new UnknownExtensionAuthenticatorOutput(p.getCurrentName(), value);
}
 
Example 20
Source File: ConvertingDeserializer.java    From graphql-spqr with Apache License 2.0 4 votes vote down vote up
@Override
public Object deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
    return deserializationContext.readValue(jsonParser, javaType);
}