@Override public <T> T fromJson(Reader reader, Type type) throws JsonbException { //TODO: maybe just use naive reader to stream conversion!? throw new JsonbException("DSL-JSON does not support Reader API. Use InputStream API instead"); }
@Override public <T> T fromJson(String input, Type type) throws JsonbException { if (input == null) throw new JsonbException("input can't be null"); if (type == null) throw new JsonbException("type can't be null"); try { byte[] bytes = input.getBytes("UTF-8"); return (T)dslJson.deserialize(type, bytes, bytes.length); } catch (IOException e) { throw new JsonbException(e.getMessage(), e.getCause()); } }
@Override public <T> T fromJson(InputStream stream, Type type) throws JsonbException { if (stream == null) throw new JsonbException("stream can't be null"); if (type == null) throw new JsonbException("type can't be null"); try { return (T)dslJson.deserialize(type, stream); } catch (IOException e) { throw new JsonbException(e.getMessage(), e.getCause()); } }
@Override public void toJson(Object obj, OutputStream stream) throws JsonbException { if (stream == null) throw new JsonbException("stream can't be null"); try { dslJson.serialize(obj, stream); } catch (IOException | SerializationException ex) { throw new JsonbException(ex.getMessage(), ex.getCause()); } }
public static JsonbProvider provider() { final Iterator<JsonbProvider> it = ServiceLoader.load(JsonbProvider.class).iterator(); if (it.hasNext()) { return it.next(); } try { return JsonbProvider.class.cast(Thread.currentThread().getContextClassLoader().loadClass(DEFAULT_PROVIDER).newInstance()); } catch (final ClassNotFoundException cnfe) { throw new JsonbException(DEFAULT_PROVIDER + " not found", cnfe); } catch (final Exception x) { throw new JsonbException(DEFAULT_PROVIDER + " couldn't be instantiated: " + x, x); } }
public static JsonbProvider provider(final String providerFqn) { if (providerFqn == null) { throw new IllegalArgumentException(); } for (final JsonbProvider provider : ServiceLoader.load(JsonbProvider.class)) { if (providerFqn.equals(provider.getClass().getName())) { return provider; } } final String msg = providerFqn + " not found"; throw new JsonbException(msg, new ClassNotFoundException(msg)); }
@Override protected Instant toInstant(OffsetTime value) { throw new JsonbException(Messages.getMessage(MessageKeys.TIME_TO_EPOCH_MILLIS_ERROR, OffsetTime.class.getSimpleName())); }
/** * Creates a new instance. * * @param beanManager Bean manager. */ public BeanManagerInstanceCreator(Object beanManager) { if (!(beanManager instanceof BeanManager)) { throw new JsonbException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "beanManager instance should be of type '" + BeanManager.class + "'")); } this.beanManager = (BeanManager) beanManager; }
@Override protected OptionalInt deserialize(String jsonValue, Unmarshaller unmarshaller, Type rtType) { try { return OptionalInt.of(Integer.parseInt(jsonValue)); } catch (NumberFormatException e) { throw new JsonbException(Messages.getMessage(MessageKeys.DESERIALIZE_VALUE_ERROR, OptionalInt.class)); } }
private PropertyVisibilityStrategy initPropertyVisibilityStrategy() { final Optional<Object> property = jsonbConfig.getProperty(JsonbConfig.PROPERTY_VISIBILITY_STRATEGY); if (!property.isPresent()) { return null; } final Object propertyVisibilityStrategy = property.get(); if (!(propertyVisibilityStrategy instanceof PropertyVisibilityStrategy)) { throw new JsonbException("JsonbConfig.PROPERTY_VISIBILITY_STRATEGY must be instance of " + PropertyVisibilityStrategy.class); } return (PropertyVisibilityStrategy) propertyVisibilityStrategy; }
private static ParameterizedType findParameterizedSuperclass(Type type) { if (type == null || type instanceof ParameterizedType) { return (ParameterizedType) type; } if (!(type instanceof Class)) { throw new JsonbException("Can't resolve ParameterizedType superclass for: " + type); } return findParameterizedSuperclass(((Class) type).getGenericSuperclass()); }
@Override protected OptionalLong deserialize(String jsonValue, Unmarshaller unmarshaller, Type rtType) { try { return OptionalLong.of(Long.parseLong(jsonValue)); } catch (NumberFormatException e) { throw new JsonbException(Messages.getMessage(MessageKeys.DESERIALIZE_VALUE_ERROR, OptionalLong.class)); } } }
/** * Adds annotation. * * @param annotation Annotation to add. */ public void putAnnotation(Annotation annotation) { if (annotations.containsKey(annotation.annotationType())) { throw new JsonbException(Messages.getMessage(MessageKeys.INTERNAL_ERROR, "Annotation already present: " + annotation)); } annotations.put(annotation.annotationType(), annotation); } }
@Override public JsonType from(final OriginalType obj) { if (obj == null) { return null; } try { return delegate.adaptToJson(obj); } catch (final Exception e) { throw new JsonbException(e.getMessage(), e); } }
@Override public OriginalType to(final JsonType obj) { if (obj == null) { return null; } try { return delegate.adaptFromJson(obj); } catch (final Exception e) { throw new JsonbException(e.getMessage(), e); } }
@Override protected Instant toInstant(LocalTime value) { throw new JsonbException(Messages.getMessage(MessageKeys.TIME_TO_EPOCH_MILLIS_ERROR, LocalTime.class.getSimpleName())); }
@Override public OriginalType to(final JsonType obj) { if (obj == null) { return null; } try { return delegate.adaptFromJson(obj); } catch (final Exception e) { throw new JsonbException(e.getMessage(), e); } }
@Override public JsonType from(final OriginalType obj) { if (obj == null) { return null; } try { return delegate.adaptToJson(obj); } catch (final Exception e) { throw new JsonbException(e.getMessage(), e); } }
@Override protected LocalTime fromInstant(Instant instant) { throw new JsonbException(Messages.getMessage(MessageKeys.TIME_TO_EPOCH_MILLIS_ERROR, LocalTime.class.getSimpleName())); }
@Override protected OffsetTime fromInstant(Instant instant) { throw new JsonbException(Messages.getMessage(MessageKeys.TIME_TO_EPOCH_MILLIS_ERROR, OffsetTime.class.getSimpleName())); }