本文整理匯總了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));
}