Search in sources :

Example 6 with JsonbException

use of javax.json.bind.JsonbException in project blaze-persistence by Blazebit.

the class JsonObjectIterator method next.

@Override
public JsonParser.Event next() {
    switch(state) {
        case START:
            if (keyIterator.hasNext()) {
                nextKey();
                setState(State.KEY);
                return JsonParser.Event.KEY_NAME;
            } else {
                setState(State.END);
                return JsonParser.Event.END_OBJECT;
            }
        case KEY:
            setState(State.VALUE);
            JsonValue value = getValue();
            return getValueEvent(value);
        case VALUE:
            if (keyIterator.hasNext()) {
                nextKey();
                setState(State.KEY);
                return JsonParser.Event.KEY_NAME;
            }
            setState(State.END);
            return JsonParser.Event.END_OBJECT;
        default:
            throw new JsonbException("Illegal state");
    }
}
Also used : JsonbException(javax.json.bind.JsonbException) JsonValue(javax.json.JsonValue)

Example 7 with JsonbException

use of javax.json.bind.JsonbException in project showcase-quarkus-eventsourcing by JohT.

the class JsonbSerializer method deserialize.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
public <S, T> T deserialize(SerializedObject<S> serializedObject) {
    try {
        if (SerializedType.emptyType().equals(serializedObject.getType())) {
            return null;
        }
        Class<?> type = classForType(serializedObject.getType());
        if (UnknownSerializedType.class.isAssignableFrom(type)) {
            return (T) new UnknownSerializedType(this, serializedObject);
        }
        SerializedObject<byte[]> byteSerialized = converter.convert(serializedObject, byte[].class);
        return (T) stringSerializer.deserialize(new String(byteSerialized.getData()), type);
    } catch (JsonbException e) {
        throw new SerializationException("Error while deserializing " + serializedObject, e);
    }
}
Also used : SerializationException(org.axonframework.serialization.SerializationException) JsonbException(javax.json.bind.JsonbException) UnknownSerializedType(org.axonframework.serialization.UnknownSerializedType)

Example 8 with JsonbException

use of javax.json.bind.JsonbException in project showcase-quarkus-eventsourcing by JohT.

the class JsonbSerializer method serialize.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
public <T> SerializedObject<T> serialize(Object object, Class<T> expectedRepresentation) {
    try {
        if (String.class.equals(expectedRepresentation)) {
            return new SimpleSerializedObject<>((T) stringSerializer.serialize(object), expectedRepresentation, typeForClass(ObjectUtils.nullSafeTypeOf(object)));
        }
        byte[] serializedBytes = stringSerializer.serialize(object).getBytes();
        T serializedContent = converter.convert(serializedBytes, expectedRepresentation);
        return new SimpleSerializedObject<>(serializedContent, expectedRepresentation, typeForClass(ObjectUtils.nullSafeTypeOf(object)));
    } catch (JsonbException e) {
        throw new SerializationException("Unable to serialize object", e);
    }
}
Also used : SerializationException(org.axonframework.serialization.SerializationException) JsonbException(javax.json.bind.JsonbException) SimpleSerializedObject(org.axonframework.serialization.SimpleSerializedObject)

Example 9 with JsonbException

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

the class ArgumentHelper method correctComplexObjectFromJsonString.

/**
 * This is used once we have a valid jsonString, either from above or from complex default value from graphql-java
 *
 * @param jsonString the object represented as a json String
 * @param field the field as created while scanning
 * @return the correct object
 */
private Object correctComplexObjectFromJsonString(String jsonString, Field field) throws AbstractDataFetcherException {
    Type type;
    String className;
    if (field.isAdaptingWith()) {
        className = field.getAdaptWith().getToReference().getClassName();
        type = getType(field.getAdaptWith().getToReference());
    } else {
        type = getType(field.getReference());
        className = field.getReference().getClassName();
    }
    try {
        Jsonb jsonb = JsonBCreator.getJsonB(className);
        return jsonb.fromJson(jsonString, type);
    } catch (JsonbException jbe) {
        throw new TransformException(jbe, field, jsonString);
    }
}
Also used : GraphQLScalarType(graphql.schema.GraphQLScalarType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) ReferenceType(io.smallrye.graphql.schema.model.ReferenceType) Jsonb(javax.json.bind.Jsonb) JsonbException(javax.json.bind.JsonbException) TransformException(io.smallrye.graphql.transformation.TransformException)

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