當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonGenerator.flush方法代碼示例

本文整理匯總了Java中com.fasterxml.jackson.core.JsonGenerator.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonGenerator.flush方法的具體用法?Java JsonGenerator.flush怎麽用?Java JsonGenerator.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.fasterxml.jackson.core.JsonGenerator的用法示例。


在下文中一共展示了JsonGenerator.flush方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: _testFailOnWritingStringNotFieldName

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
private void _testFailOnWritingStringNotFieldName(JsonFactory f, boolean useReader) throws Exception
{
    JsonGenerator gen;
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    if (useReader) {
        gen = f.createGenerator(ObjectWriteContext.empty(), new OutputStreamWriter(bout, "UTF-8"));
    } else {
        gen = f.createGenerator(ObjectWriteContext.empty(), bout, JsonEncoding.UTF8);
    }
    gen.writeStartObject();
    
    try {
        StringReader reader = new StringReader("a");
        gen.writeString(reader, -1);
        gen.flush();
        String json = bout.toString("UTF-8");
        fail("Should not have let "+gen.getClass().getName()+".writeString() be used in place of 'writeFieldName()': output = "+json);
    } catch (JsonProcessingException e) {
        verifyException(e, "can not write a String");
    }
    gen.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:GeneratorFailFromReaderTest.java

示例2: _testFailOnWritingStringFromNullReader

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
private void _testFailOnWritingStringFromNullReader(JsonFactory f, boolean useReader) throws Exception{
    JsonGenerator gen;
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    if (useReader) {
        gen = f.createGenerator(ObjectWriteContext.empty(), new OutputStreamWriter(bout, "UTF-8"));
    } else {
        gen = f.createGenerator(ObjectWriteContext.empty(), bout, JsonEncoding.UTF8);
    }
    gen.writeStartObject();

    try {
        gen.writeFieldName("a");
        gen.writeString(null, -1);
        gen.flush();
        String json = bout.toString("UTF-8");
        fail("Should not have let "+gen.getClass().getName()+".writeString() ': output = "+json);
    } catch (JsonProcessingException e) {
        verifyException(e, "null reader");
    }
    gen.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:GeneratorFailFromReaderTest.java

示例3: _testDupFieldNameWrites

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
private void _testDupFieldNameWrites(JsonFactory f, boolean useReader) throws Exception
{
    JsonGenerator gen;
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    if (useReader) {
        gen = f.createGenerator(ObjectWriteContext.empty(), new OutputStreamWriter(bout, "UTF-8"));
    } else {
        gen = f.createGenerator(ObjectWriteContext.empty(), bout, JsonEncoding.UTF8);
    }
    gen.writeStartObject();
    gen.writeFieldName("a");
    
    try {
        gen.writeFieldName("b");
        gen.flush();
        String json = bout.toString("UTF-8");
        fail("Should not have let two consecutive field name writes succeed: output = "+json);
    } catch (JsonProcessingException e) {
        verifyException(e, "can not write a field name, expecting a value");
    }
    gen.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:GeneratorFailTest.java

示例4: _testFailOnWritingStringNotFieldName

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
private void _testFailOnWritingStringNotFieldName(JsonFactory f, boolean useReader) throws Exception
{
    JsonGenerator gen;
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    if (useReader) {
        gen = f.createGenerator(ObjectWriteContext.empty(), new OutputStreamWriter(bout, "UTF-8"));
    } else {
        gen = f.createGenerator(ObjectWriteContext.empty(), bout, JsonEncoding.UTF8);
    }
    gen.writeStartObject();
    
    try {
        gen.writeString("a");
        gen.flush();
        String json = bout.toString("UTF-8");
        fail("Should not have let "+gen.getClass().getName()+".writeString() be used in place of 'writeFieldName()': output = "+json);
    } catch (JsonProcessingException e) {
        verifyException(e, "can not write a String");
    }
    gen.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:GeneratorFailTest.java

示例5: writeTo

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
@Override
public void writeTo(
    Object o, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
    MultivaluedMap<String, Object> httpHeaders, OutputStream os) throws IOException {
  String fields = uriInfo.getQueryParameters() == null ? null
      : uriInfo.getQueryParameters().getFirst("fields");

  FieldFilter fieldFilter = FieldFilter.create(fields);
  if (!fieldFilter.hasFilters()) {
    super.writeTo(o, type, genericType, annotations, mediaType, httpHeaders, os);
    return;
  }

  JsonGenerator jgen = objectMapper.getFactory().createGenerator(os);
  TokenBuffer tokenBuffer = new TokenBuffer(objectMapper, false);
  objectMapper.writeValue(tokenBuffer, o);
  JsonParser jsonParser = tokenBuffer.asParser();
  fieldFilter.writeJson(jsonParser, jgen);
  jgen.flush();
}
 
開發者ID:cerner,項目名稱:beadledom,代碼行數:21,代碼來源:FilteringJacksonJsonProvider.java

示例6: doTestBigInteger

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
protected void doTestBigInteger(JsonGenerator generator, ByteArrayOutputStream os) throws Exception {
    // Big integers cannot be handled explicitly, but if some values happen to be big ints,
    // we can still call parser.map() and get the bigint value so that eg. source filtering
    // keeps working
    BigInteger bigInteger = BigInteger.valueOf(Long.MAX_VALUE).add(BigInteger.ONE);
    generator.writeStartObject();
    generator.writeFieldName("foo");
    generator.writeString("bar");
    generator.writeFieldName("bigint");
    generator.writeNumber(bigInteger);
    generator.writeEndObject();
    generator.flush();
    byte[] serialized = os.toByteArray();

    XContentParser parser = xcontentType().xContent().createParser(NamedXContentRegistry.EMPTY, serialized);
    Map<String, Object> map = parser.map();
    assertEquals("bar", map.get("foo"));
    assertEquals(bigInteger, map.get("bigint"));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:20,代碼來源:BaseXContentTestCase.java

示例7: getBeakerCodeCells

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
private List<BeakerCodeCell> getBeakerCodeCells(Object value) {
  List<BeakerCodeCell> beakerCodeCellList = null;
  StringWriter sw = new StringWriter();
  JsonGenerator jgen = null;
  try {
    jgen = objectMapper.getFactory().createGenerator(sw);
    objectSerializer.writeObject(value, jgen, true);
    jgen.flush();
    sw.flush();
    beakerCodeCellList = Arrays.asList(objectMapper.readValue(sw.toString(), BeakerCodeCell[].class));
  } catch (IOException e) {
    e.printStackTrace();
  }

  return beakerCodeCellList;
}
 
開發者ID:twosigma,項目名稱:beaker-notebook-archive,代碼行數:17,代碼來源:GetCodeCellsHandler.java

示例8: toString

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
public String toString(boolean pretty)
{
   try
   {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      JsonGenerator json = new JsonFactory().createGenerator(baos);
      if (pretty)
         json.useDefaultPrettyPrinter();
      write(json, new HashSet());
      json.flush();
      baos.flush();

      return new String(baos.toByteArray());
   }
   catch (Exception ex)
   {
      throw new RuntimeException(ex);
   }
}
 
開發者ID:wellsb1,項目名稱:fort_w,代碼行數:20,代碼來源:JSObject.java

示例9: buildJSONFromFields

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
private String buildJSONFromFields(Collection<SearchHitField> values) {
	JsonFactory nodeFactory = new JsonFactory();
	try {
		ByteArrayOutputStream stream = new ByteArrayOutputStream();
		JsonGenerator generator = nodeFactory.createGenerator(stream, JsonEncoding.UTF8);
		generator.writeStartObject();
		for (SearchHitField value : values) {
			if (value.getValues().size() > 1) {
				generator.writeArrayFieldStart(value.getName());
				for (Object val : value.getValues()) {
					generator.writeObject(val);
				}
				generator.writeEndArray();
			} else {
				generator.writeObjectField(value.getName(), value.getValue());
			}
		}
		generator.writeEndObject();
		generator.flush();
		return new String(stream.toByteArray(), Charset.forName("UTF-8"));
	} catch (IOException e) {
		return null;
	}
}
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:25,代碼來源:UKResultMapper.java

示例10: encodeFrame

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
TextWebSocketFrame encodeFrame() throws IOException {
    StringWriter w = new StringWriter();

    JsonGenerator generator = factory.createGenerator(w);
    generator.writeStartObject();
    generator.writeFieldName("type");
    generator.writeString("subscribe");
    generator.writeFieldName("product_ids");
    generator.writeStartArray();
    products.forEach(product -> {
        try {
            generator.writeString(product.getCode());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    generator.writeEndArray();
    generator.writeFieldName("channels");
    generator.writeStartArray();
    generator.writeString("full");
    generator.writeString("heartbeat");
    generator.writeEndArray();
    generator.writeEndObject();
    generator.flush();
    String txt = w.toString();

    return new TextWebSocketFrame(true, 0, txt);
}
 
開發者ID:cloudwall,項目名稱:libcwfincore,代碼行數:29,代碼來源:SubscribeRequest.java

示例11: encodeFrame

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
String encodeFrame() throws IOException {
    StringWriter w = new StringWriter();

    JsonGenerator generator = factory.createGenerator(w);
    generator.writeStartObject();
    generator.writeFieldName("client_oid");
    generator.writeString(getClientOrderId().getId());
    generator.writeFieldName("size");
    generator.writeString(getQuantity().getValue().toString());
    if (price != null && stopPrice == null) {
        generator.writeStringField("type", "limit");
        generator.writeFieldName("price");
        generator.writeString(getPrice().getValue().toString());
        generator.writeBooleanField("post_only", true);
    } else if (stopPrice != null) {
        generator.writeStringField("type", "stop");
        generator.writeFieldName("price");
        generator.writeString(getStopPrice().getValue().toString());
    }
    generator.writeFieldName("side");
    generator.writeString(getSide().toString().toLowerCase());
    generator.writeFieldName("product_id");
    generator.writeString(getProduct().getCode());
    generator.writeFieldName("time_in_force");
    generator.writeString(getTimeInForceCode(getTimeInForce()));
    if (getTimeInForce() == TimeInForce.DAY) {
        generator.writeFieldName("cancel_after");
        generator.writeString("day");
    }
    generator.writeEndObject();
    generator.flush();
    return w.toString();
}
 
開發者ID:cloudwall,項目名稱:libcwfincore,代碼行數:34,代碼來源:GdaxNewOrderSingle.java

示例12: testUtf8Issue462

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
public void testUtf8Issue462() throws Exception
{
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    IOContext ioc = new IOContext(new BufferRecycler(), bytes, true);
    JsonGenerator gen = new UTF8JsonGenerator(ObjectWriteContext.empty(), ioc, 0, bytes,
            JsonFactory.DEFAULT_ROOT_VALUE_SEPARATOR, null, null);
            
    String str = "Natuurlijk is alles gelukt en weer een tevreden klant\uD83D\uDE04";
    int length = 4000 - 38;

    for (int i = 1; i <= length; ++i) {
        gen.writeNumber(1);
    }
    gen.writeString(str);
    gen.flush();
    gen.close();
    
    // Also verify it's parsable?
    JsonParser p = JSON_F.createParser(ObjectReadContext.empty(), bytes.toByteArray());
    for (int i = 1; i <= length; ++i) {
        assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
        assertEquals(1, p.getIntValue());
    }
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals(str, p.getText());
    assertNull(p.nextToken());
    p.close();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:29,代碼來源:TestUtf8Generator.java

示例13: toJSONString

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
/**
 * Output the minimal schema info as JSON. This is different from the default serialization supported by {@link Field}
 * as it has lot more information (such as vector types) which is not needed for understanding the schema.
 * @return
 * @throws Exception
 */
public String toJSONString() throws Exception {
  final JsonFactory factory = new JsonFactory();
  final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  final JsonGenerator jsonGenerator = factory.createGenerator(outputStream);

  toJSONString("root", null, getFields(), jsonGenerator);

  jsonGenerator.flush();
  return outputStream.toString();
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:17,代碼來源:BatchSchema.java

示例14: writeInternal

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
@Override
@SuppressWarnings("deprecation")
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {

	JsonEncoding encoding = getJsonEncoding(outputMessage.getHeaders().getContentType());
	JsonGenerator generator = this.objectMapper.getFactory().createGenerator(outputMessage.getBody(), encoding);
	try {

		JavaType javaType = null;
		if (jackson26Available && type != null && object != null && TypeUtils.isAssignable(type, object.getClass())) {
			javaType = getJavaType(type, null);
		}
		ObjectWriter objectWriter;
		objectWriter = this.objectMapper.writer();
		if (javaType != null && javaType.isContainerType()) {
			objectWriter = objectWriter.withType(javaType);
		}
		objectWriter.writeValue(generator, object);

		generator.flush();

	}
	catch (JsonProcessingException ex) {
		throw new HttpMessageNotWritableException("Could not write content: " + ex.getMessage(), ex);
	}
}
 
開發者ID:JetBrains,項目名稱:teamcity-hashicorp-vault-plugin,代碼行數:28,代碼來源:AbstractJackson2HttpMessageConverter.java

示例15: getJson

import com.fasterxml.jackson.core.JsonGenerator; //導入方法依賴的package包/類
protected String getJson(Object value) throws IOException{
  StringWriter sw = new StringWriter();
  JsonGenerator jgen = objectMapper.getFactory().createGenerator(sw);
  objectSerializer.writeObject(value, jgen, true);
  jgen.flush();
  sw.flush();
  return sw.toString();
}
 
開發者ID:twosigma,項目名稱:beaker-notebook-archive,代碼行數:9,代碼來源:NamespaceClient.java


注:本文中的com.fasterxml.jackson.core.JsonGenerator.flush方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。