Search in sources :

Example 1 with JsonbException

use of javax.json.bind.JsonbException in project colab by Heigvd.

the class WebsocketClient method onRawMessage.

/**
 * On message callback.
 *
 * @param message the message
 */
@OnMessage
public void onRawMessage(String message) {
    try {
        if (message.charAt(0) == '[') {
            Jsonb jsonb = JsonbProvider.getJsonb();
            Type type = new GenericType<ArrayList<WsMessage>>() {
            }.getType();
            onMessage((List) jsonb.fromJson(message, type));
        } else {
            Jsonb jsonb = JsonbProvider.getJsonb();
            onMessage(jsonb.fromJson(message, WsMessage.class));
        }
    } catch (JsonbException ex) {
        logger.trace("");
    }
}
Also used : Jsonb(javax.json.bind.Jsonb) GenericType(javax.ws.rs.core.GenericType) Type(java.lang.reflect.Type) WsMessage(ch.colabproject.colab.api.ws.message.WsMessage) JsonbException(javax.json.bind.JsonbException) ArrayList(java.util.ArrayList) OnMessage(javax.websocket.OnMessage)

Example 2 with JsonbException

use of javax.json.bind.JsonbException in project jersey by eclipse-ee4j.

the class JsonBindingProvider method readFrom.

@Override
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
    final EntityInputStream entityInputStream = new EntityInputStream(entityStream);
    entityStream = entityInputStream;
    if (entityInputStream.isEmpty()) {
        throw new NoContentException(LocalizationMessages.ERROR_JSONB_EMPTYSTREAM());
    }
    Jsonb jsonb = getJsonb(type);
    try {
        return jsonb.fromJson(entityStream, genericType);
    } catch (JsonbException e) {
        throw new ProcessingException(LocalizationMessages.ERROR_JSONB_DESERIALIZATION(), e);
    }
}
Also used : Jsonb(javax.json.bind.Jsonb) JsonbException(javax.json.bind.JsonbException) EntityInputStream(org.glassfish.jersey.message.internal.EntityInputStream) NoContentException(javax.ws.rs.core.NoContentException) ProcessingException(javax.ws.rs.ProcessingException)

Example 3 with JsonbException

use of javax.json.bind.JsonbException in project smallrye-graphql by smallrye.

the class DefaultMapAdapter method toObject.

private <T> T toObject(Reference reference, T t) {
    ReferenceType type = reference.getType();
    String className = reference.getClassName();
    if (!type.equals(ReferenceType.SCALAR)) {
        String jsonString = JsonBCreator.getJsonB().toJson(t);
        try {
            Jsonb jsonb = JsonBCreator.getJsonB(className);
            Class<?> clazz = classloadingService.loadClass(className);
            return (T) jsonb.fromJson(jsonString, clazz);
        } catch (JsonbException jbe) {
            throw new RuntimeException(jbe);
        }
    }
    return t;
}
Also used : Jsonb(javax.json.bind.Jsonb) JsonbException(javax.json.bind.JsonbException) ReferenceType(io.smallrye.graphql.schema.model.ReferenceType)

Example 4 with JsonbException

use of javax.json.bind.JsonbException in project quarkus-resteasy-problem by TietoEVRY.

the class RestEasyClassicJsonbExceptionMapperTest method processingExceptionWithJsonbExceptionCauseShouldProduceHttp400.

@Test
void processingExceptionWithJsonbExceptionCauseShouldProduceHttp400() {
    ProcessingException exception = new ProcessingException(new JsonbException("Something is wrong"));
    Response response = mapper.toResponse(exception);
    assertThat(response.getStatus()).isEqualTo(400);
}
Also used : Response(javax.ws.rs.core.Response) JsonbException(javax.json.bind.JsonbException) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.jupiter.api.Test)

Example 5 with JsonbException

use of javax.json.bind.JsonbException in project jakartaee-framework by next-colors.

the class CodeEnumDeserializer method deserialize.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public T deserialize(@NonNull final JsonParser parser, @NonNull final DeserializationContext ctx, @NonNull final Type rtType) {
    Class<T> enumClass = (Class<T>) rtType;
    Class<C> enumCodeClass = ICodeEnum.getCodeClass(enumClass);
    try {
        C code = enumCodeClass.cast(ConvertUtils.convert(parser.getString(), enumCodeClass));
        return ICodeEnum.codeOf(enumClass, code);
    } catch (Exception e) {
        throw new JsonbException(ExceptionUtils.getMessage(e), e);
    }
}
Also used : JsonbException(javax.json.bind.JsonbException) JsonbException(javax.json.bind.JsonbException)

Aggregations

JsonbException (javax.json.bind.JsonbException)9 Jsonb (javax.json.bind.Jsonb)4 ReferenceType (io.smallrye.graphql.schema.model.ReferenceType)2 Type (java.lang.reflect.Type)2 ProcessingException (javax.ws.rs.ProcessingException)2 SerializationException (org.axonframework.serialization.SerializationException)2 WsMessage (ch.colabproject.colab.api.ws.message.WsMessage)1 GraphQLScalarType (graphql.schema.GraphQLScalarType)1 TransformException (io.smallrye.graphql.transformation.TransformException)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 ArrayList (java.util.ArrayList)1 JsonValue (javax.json.JsonValue)1 OnMessage (javax.websocket.OnMessage)1 GenericType (javax.ws.rs.core.GenericType)1 NoContentException (javax.ws.rs.core.NoContentException)1 Response (javax.ws.rs.core.Response)1 SimpleSerializedObject (org.axonframework.serialization.SimpleSerializedObject)1 UnknownSerializedType (org.axonframework.serialization.UnknownSerializedType)1 EntityInputStream (org.glassfish.jersey.message.internal.EntityInputStream)1 Test (org.junit.jupiter.api.Test)1