当前位置: 首页>>代码示例>>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;未经允许,请勿转载。