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");
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations