本文整理汇总了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();
}
}
示例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);
}
}
示例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();
}
}
示例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));
}