@Override public void flush() throws IOException { if (!_closed) { _generator.flush(); } }
@Override public void flush() throws IOException { delegate.flush(); } @Override public void close() throws IOException { delegate.close(); }
@Override public void writeResponseEnd() throws IOException { jsonGenerator.flush(); // Terminate the last output line, then write an extra blank line, so users can tell the response was not cut off. outputStream.write(new byte[]{'\n', '\n'}); outputStream.flush(); }
@Override public void writeResponseEnd() throws IOException { jsonGenerator.flush(); // Terminate the last output line, then write an extra blank line, so users can tell the response was not cut off. outputStream.write(new byte[]{'\n', '\n'}); outputStream.flush(); }
@Override public void writeResponseEnd() throws IOException { jsonGenerator.writeEndArray(); // End with LF. jsonGenerator.flush(); outputStream.write('\n'); }
@Override public void writeResponseEnd() throws IOException { jsonGenerator.writeEndArray(); // End with LF. jsonGenerator.flush(); outputStream.write('\n'); }
@Override public void flush() throws IOException { gen.flush(); out.flush(); }
@Override public byte[] getBuffer() { try { gen.flush(); } catch (IOException e) { FSTUtil.<RuntimeException>rethrow(e); } return out.getBuf(); }
/** * Write the actual JSON content to the stream. * @param stream the output stream to use * @param object the value to be rendered, as returned from {@link #filterModel} * @throws IOException if writing failed */ protected void writeContent(OutputStream stream, Object object) throws IOException { JsonGenerator generator = this.objectMapper.getFactory().createGenerator(stream, this.encoding); writePrefix(generator, object); Object value = object; Class<?> serializationView = null; FilterProvider filters = null; if (value instanceof MappingJacksonValue) { MappingJacksonValue container = (MappingJacksonValue) value; value = container.getValue(); serializationView = container.getSerializationView(); filters = container.getFilters(); } ObjectWriter objectWriter = (serializationView != null ? this.objectMapper.writerWithView(serializationView) : this.objectMapper.writer()); if (filters != null) { objectWriter = objectWriter.with(filters); } objectWriter.writeValue(generator, value); writeSuffix(generator, object); generator.flush(); }
/** * Helper method used when value to serialize is {@link Closeable} and its <code>close()</code> * method is to be called right after serialization has been called */ private final void _writeCloseableValue(JsonGenerator g, Object value, SerializationConfig cfg) throws IOException { Closeable toClose = (Closeable) value; try { _serializerProvider(cfg).serializeValue(g, value); if (cfg.isEnabled(SerializationFeature.FLUSH_AFTER_WRITE_VALUE)) { g.flush(); } } catch (Exception e) { ClassUtil.closeOnFailAndThrowAsIOE(null, toClose, e); return; } toClose.close(); }
@Override public void writeTree(JsonGenerator jgen, TreeNode rootNode) throws IOException, JsonProcessingException { SerializationConfig config = getSerializationConfig(); _serializerProvider(config).serializeValue(jgen, rootNode); if (config.isEnabled(SerializationFeature.FLUSH_AFTER_WRITE_VALUE)) { jgen.flush(); } }
/** * Method to serialize given JSON Tree, using generator * provided. */ public void writeTree(JsonGenerator jgen, JsonNode rootNode) throws IOException, JsonProcessingException { SerializationConfig config = getSerializationConfig(); _serializerProvider(config).serializeValue(jgen, rootNode); if (config.isEnabled(SerializationFeature.FLUSH_AFTER_WRITE_VALUE)) { jgen.flush(); } }
@Test public void shouldSerializeIssuedAtDateInSeconds() throws Exception { ClaimsHolder holder = holderFor("iat", new Date(1478874000)); serializer.serialize(holder, jsonGenerator, serializerProvider); jsonGenerator.flush(); assertThat(writer.toString(), is(equalTo("{\"iat\":1478874}"))); }
@Test public void shouldSerializeCustomDateInSeconds() throws Exception { ClaimsHolder holder = holderFor("birthdate", new Date(1478874000)); serializer.serialize(holder, jsonGenerator, serializerProvider); jsonGenerator.flush(); assertThat(writer.toString(), is(equalTo("{\"birthdate\":1478874}"))); }
@Test public void shouldSerializeDoubles() throws Exception { ClaimsHolder holder = holderFor("fraction", 23.45); serializer.serialize(holder, jsonGenerator, serializerProvider); jsonGenerator.flush(); assertThat(writer.toString(), is(equalTo("{\"fraction\":23.45}"))); }
@Test public void shouldSerializeNulls() throws Exception { ClaimsHolder holder = holderFor("id", null); serializer.serialize(holder, jsonGenerator, serializerProvider); jsonGenerator.flush(); assertThat(writer.toString(), is(equalTo("{\"id\":null}"))); }
@Test public void shouldSerializeMultipleItemsAudienceAsArray() throws Exception { ClaimsHolder holder = holderFor("aud", new String[]{"auth0", "auth10"}); serializer.serialize(holder, jsonGenerator, serializerProvider); jsonGenerator.flush(); assertThat(writer.toString(), is(equalTo("{\"aud\":[\"auth0\",\"auth10\"]}"))); }
@Test public void shouldSerializeStrings() throws Exception { ClaimsHolder holder = holderFor("name", "Auth0 Inc"); serializer.serialize(holder, jsonGenerator, serializerProvider); jsonGenerator.flush(); assertThat(writer.toString(), is(equalTo("{\"name\":\"Auth0 Inc\"}"))); }
@Test public void shouldSerializeBooleans() throws Exception { ClaimsHolder holder = holderFor("pro", true); serializer.serialize(holder, jsonGenerator, serializerProvider); jsonGenerator.flush(); assertThat(writer.toString(), is(equalTo("{\"pro\":true}"))); }
@Test public void shouldSerializeCustomObject() throws Exception { UserPojo user = new UserPojo("Michael", 1); ClaimsHolder holder = holderFor("users", user); serializer.serialize(holder, jsonGenerator, serializerProvider); jsonGenerator.flush(); assertThat(writer.toString(), is(equalTo("{\"users\":{\"name\":\"Michael\",\"id\":1}}"))); }