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