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


Java JsonFactory.createJsonGenerator方法代碼示例

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


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

示例1: getJSON

import com.fasterxml.jackson.core.JsonFactory; //導入方法依賴的package包/類
public String getJSON() {
  JsonFactory jf = new JsonFactory();
  // OutputStream os = new ByteArrayOutputStream();
  HeapDataOutputStream hdos = new HeapDataOutputStream(org.apache.geode.internal.Version.CURRENT);
  try {
    JsonGenerator jg = jf.createJsonGenerator(hdos, JsonEncoding.UTF8);
    enableDisableJSONGeneratorFeature(jg);
    getJSONString(jg, m_pdxInstance);
    jg.close();
    return new String(hdos.toByteArray());
  } catch (IOException e) {
    throw new RuntimeException(e.getMessage());
  } finally {
    hdos.close();
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:17,代碼來源:PdxToJSON.java

示例2: convert

import com.fasterxml.jackson.core.JsonFactory; //導入方法依賴的package包/類
@Override
public String convert(final List<ComplexNestedType> object) {
    try {
        StringWriter writer = new StringWriter();
        JsonFactory jsonFactory = new MappingJsonFactory();
        JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer);
        jsonGenerator.writeObject(object);
        return writer.toString();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:aws,項目名稱:aws-sdk-java-v2,代碼行數:13,代碼來源:ComplexTypeIntegrationTest.java

示例3: getJSONByteArray

import com.fasterxml.jackson.core.JsonFactory; //導入方法依賴的package包/類
public byte[] getJSONByteArray() {
  JsonFactory jf = new JsonFactory();
  HeapDataOutputStream hdos = new HeapDataOutputStream(org.apache.geode.internal.Version.CURRENT);
  try {
    JsonGenerator jg = jf.createJsonGenerator(hdos, JsonEncoding.UTF8);
    enableDisableJSONGeneratorFeature(jg);
    getJSONString(jg, m_pdxInstance);
    jg.close();
    return hdos.toByteArray();
  } catch (IOException e) {
    throw new RuntimeException(e.getMessage());
  } finally {
    hdos.close();
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:16,代碼來源:PdxToJSON.java

示例4: testParsingAttributesCASServerV4_2AndBefore

import com.fasterxml.jackson.core.JsonFactory; //導入方法依賴的package包/類
@Test
public void testParsingAttributesCASServerV4_2AndBefore() throws Exception {
    final JsonFactory jsonFactory = new JsonFactory(new ObjectMapper());
    final Map<String, Object> attributes = new HashMap<>();
    attributes.put(KEY, VALUE);
    attributes.put(NAME, TOKEN);
    final StringWriter writer = new StringWriter();
    try (final JsonGenerator jsonGenerator = jsonFactory.createJsonGenerator(writer)) {
        jsonGenerator.writeStartObject();
        jsonGenerator.writeStringField("id", ID);
        jsonGenerator.writeArrayFieldStart("attributes");
        for (final Map.Entry<String, Object> entry : attributes.entrySet()) {
            jsonGenerator.writeStartObject();
            jsonGenerator.writeObjectField(entry.getKey(), entry.getValue());
            jsonGenerator.writeEndObject();
        }
        jsonGenerator.writeEndArray();
        jsonGenerator.writeEndObject();
    }
    final String body = writer.toString();
    final CasOAuthWrapperClient client = new CasOAuthWrapperClient();
    final CasOAuthWrapperProfile profile = client.extractUserProfile(body);
    assertEquals(ID, profile.getId());
    assertEquals(2, profile.getAttributes().size());
    assertEquals(VALUE, profile.getAttribute(KEY));
    assertEquals(TOKEN, profile.getAttribute(NAME));
}
 
開發者ID:yaochi,項目名稱:pac4j-plus,代碼行數:28,代碼來源:CasOAuthWrapperClientTests.java


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