@Override public void writeTo(Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { Jsonb jsonb = getJsonb(type); try { entityStream.write(jsonb.toJson(o).getBytes(AbstractMessageReaderWriterProvider.getCharset(mediaType))); entityStream.flush(); } catch (IOException e) { throw new ProcessingException(LocalizationMessages.ERROR_JSONB_SERIALIZATION(), e); } }
@Override public void render(final Object object, final Context ctx) throws Exception { if (ctx.accepts(this.type)) { ctx.type(this.type) .send(jsonb.toJson(object)); } }
@Override public String[] getMessages() { try { return new String[]{mapper.toJson(messageList)}; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void writeTo(Object t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws java.io.IOException, javax.ws.rs.WebApplicationException { Jsonb jsonb = getJsonb(type); try { entityStream = new DelegatingOutputStream(entityStream) { @Override public void flush() throws IOException { // don't flush as this is a performance hit on Undertow. // and causes chunked encoding to happen. } }; entityStream.write(jsonb.toJson(t).getBytes(getCharset(mediaType))); entityStream.flush(); } catch (Throwable e) { throw new ProcessingException(Messages.MESSAGES.jsonBSerializationError(e.toString()), e); } } }
@Override public void onEvent(final ZipkinSpan zipkinSpan) { final String json = jsonb.toJson(zipkinSpan); spanLogger.info(wrapAsList ? '[' + json + ']' : json); } }
/** * Returns a new instance of {@link Value} converting to JSON first * * @param json the value * @return the new Value instance * @throws NullPointerException when json is null */ public static Value of(Object json) throws NullPointerException { Objects.requireNonNull(json, "json is required"); return new ValueJSON(JSONB.toJson(json)); } }
@Override public boolean add(T t) { requireNonNull(t, "object is required"); return arraySet.add(JSONB.toJson(t)); }
@Override public void writeTo(final T t, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException { getJsonb(type).toJson(t, entityStream); }
@Override public void writeTo(final T t, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException { getJsonb(type).toJson(t, entityStream); }
@Override public boolean retainAll(Collection<?> collection) { requireNonNull(collection, "collection is required"); collection.removeIf(e -> !arraySet.contains(JSONB.toJson(e))); return true; }
public <T> Record toRecord(final T data, final Supplier<Jsonb> jsonbProvider, final Supplier<RecordBuilderFactory> recordBuilderProvider) { if (Record.class.isInstance(data)) { return Record.class.cast(data); } if (JsonObject.class.isInstance(data)) { return json2Record(recordBuilderProvider.get(), JsonObject.class.cast(data)); } final Jsonb jsonb = jsonbProvider.get(); return json2Record(recordBuilderProvider.get(), jsonb.fromJson(jsonb.toJson(data), JsonObject.class)); }
@Override public <K, V> void put(K key, V value) { requireNonNull(key, "key is required"); requireNonNull(value, "value is required"); if (JsonValue.checkType(value)) { bucket.upsert(RawJsonDocument.create(key.toString(), JSONB.toJson(value.toString()))); } else { bucket.upsert(JsonDocument.create(key.toString(), JsonObjectCouchbaseUtil.toJson(JSONB, value))); } }
private String toDefault(final DefaultValueInspector.Instance instance, final ParameterMeta p) { if (instance.isCreated()) { return null; } if (Collection.class.isInstance(instance.getValue()) || Map.class.isInstance(instance.getValue())) { // @Experimental("not primitives are a challenge, for now use that but can change if not adapted") return defaultMapper.toJson(instance.getValue()); } return defaultValueInspector.findDefault(instance.getValue(), p); }
@Override public <K, V> void put(K key, V value) throws NullPointerException { Objects.requireNonNull(key, "Key is required"); Objects.requireNonNull(value, "value is required"); BaseDocument baseDocument = new BaseDocument(); baseDocument.setKey(key.toString()); baseDocument.addAttribute(VALUE, JSONB.toJson(value)); if (arangoDB.db(bucketName).collection(namespace).documentExists(key.toString())) { arangoDB.db(bucketName).collection(namespace).deleteDocument(key.toString()); } arangoDB.db(bucketName).collection(namespace) .insertDocument(baseDocument); }
public void save(final CreateProject event) { final String project = event.getRequest().getBuildConfiguration().getGroup() + ':' + event.getRequest().getBuildConfiguration().getArtifact(); logger .info(jsonb .toJson(new Representation(project, event.getRequest().getSources() == null ? 0 : event.getRequest().getSources().size(), event.getRequest().getProcessors() == null ? 0 : event.getRequest().getProcessors().size(), ofNullable(event.getRequest().getFacets()).orElseGet(Collections::emptyList)))); }
@Benchmark @Override public Object yasson() { ByteArrayOutputStream baos = JsonUtils.byteArrayOutputStream(); JSON_SOURCE().provider().yasson().toJson(JSON_SOURCE().nextPojo(), baos); return baos; }