本文整理汇总了Java中com.fasterxml.jackson.core.JsonGenerationException类的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerationException类的具体用法?Java JsonGenerationException怎么用?Java JsonGenerationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonGenerationException类属于com.fasterxml.jackson.core包,在下文中一共展示了JsonGenerationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeMetaData
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
@Override
public void writeMetaData(OutputStream out, ResourceWithMetadata resource, Map<String, ResourceWithMetadata> allApiResources) throws IOException
{
final Object result = processResult(resource,allApiResources);
assistant.getJsonHelper().withWriter(out, new Writer()
{
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
throws JsonGenerationException, JsonMappingException, IOException
{
objectMapper.writeValue(generator, result);
}
});
}
示例2: testWriteValueOutputStreamObject
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
@Test
public void testWriteValueOutputStreamObject() {
boolean status = true;
String[] stringArray = new String[1];
stringArray[0] = "abc";
new MockUp<ObjectWriter>() {
@Mock
public void writeValue(OutputStream out,
Object value) throws IOException, JsonGenerationException, JsonMappingException {
}
};
try {
StandardObjectWriter.writeValue(outputStream,
stringArray);
} catch (IOException e) {
status = false;
}
Assert.assertTrue(status);
}
示例3: testNullInComment
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
@Test
public void testNullInComment() throws IOException
{
final Comment aComment = new Comment();
aComment.setContent(null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
jsonHelper.withWriter(out, new Writer()
{
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
throws JsonGenerationException, JsonMappingException, IOException
{
FilterProvider fp = new SimpleFilterProvider().addFilter(
JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
objectMapper.writer(fp).writeValue(generator, aComment);
}
});
assertEquals("Null values should not be output.", "{\"canEdit\":false,\"canDelete\":false}",
out.toString());
}
示例4: toResponse
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
@Override
public Response toResponse(JsonProcessingException exception) {
if (exception instanceof JsonGenerationException) {
LOG.error("Error generating JSON", exception);
return Response.serverError().build();
}
if (exception.getMessage().startsWith("No suitable constructor found")) {
LOG.error("Unable to deserialize the specific type", exception);
return Response.serverError().build();
}
LOG.info(exception.getLocalizedMessage());
return Response
.status(Response.Status.BAD_REQUEST)
.type(MediaType.APPLICATION_JSON_TYPE)
.entity(createUnauditedErrorStatus(UUID.randomUUID(), ExceptionType.JSON_PARSING, exception.getOriginalMessage()))
.build();
}
示例5: status
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
@CsapDoc ( notes = { "Summary status of host" } , linkTests = "default" )
@RequestMapping ( { "/status" } )
public ObjectNode status ()
throws JsonGenerationException, JsonMappingException,
IOException {
ObjectNode healthJson = jacksonMapper.createObjectNode();
if ( Application.isJvmInManagerMode() ) {
healthJson.put( "error", "vmHealth is only enabled on CsAgent urls." );
} else {
healthJson = csapApp.statusForAdminOrAgent( ServiceAlertsEnum.ALERT_LEVEL );
}
return healthJson;
}
示例6: serialize
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
@Override
public void serialize(SerializablePagedCollection pagedCol, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonGenerationException
{
if (pagedCol != null)
{
jgen.writeStartObject();
jgen.writeFieldName("list");
jgen.writeStartObject();
serializePagination(pagedCol, jgen);
serializeContext(pagedCol, jgen);
jgen.writeObjectField("entries", pagedCol.getCollection());
serializeIncludedSource(pagedCol, jgen);
jgen.writeEndObject();
jgen.writeEndObject();
}
}
示例7: serviceStop
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
@CsapDoc ( notes = {
"refer to /api/appication/service"
} , linkTests = {
"ServletSample" } , linkPaths = { "/serviceStop/ServletSample_8041" } , linkPostParams = {
"userid=someDeveloper,pass=changeMe,cluster=changeMe,clean=clean" } )
@RequestMapping ( "/serviceStop/{serviceName}" )
@Deprecated
public JsonNode serviceStop (
@PathVariable ( "serviceName" ) String serviceName_port,
@RequestParam ( value = "cluster" , defaultValue = "" ) String cluster,
@RequestParam ( value = "clean" , defaultValue = "" ) String clean,
@RequestParam ( SpringAuthCachingFilter.USERID ) String userid,
@RequestParam ( SpringAuthCachingFilter.PASSWORD ) String inputPass,
HttpServletRequest request )
throws JsonGenerationException, JsonMappingException, IOException {
logger.debug( "DeprecatedApi - use /api/application/service/kill" );
if ( Application.isJvmInManagerMode() ) {
return applicationApi.serviceKill( serviceName_port, stripOffLifecycle(cluster), clean, "keepLogs", userid, inputPass, request );
} else {
ArrayList<String> services = new ArrayList<>() ;
services.add( serviceName_port ) ;
return agentApi.serviceKill( services, clean, null, userid, userid, request );
}
}
示例8: serialize
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
public void serialize(JsonGenerator jgen, BeakerObjectConverter boc) throws JsonGenerationException, IOException {
jgen.writeStartObject();
jgen.writeNumberField("width", w);
if (theStyle!=null) jgen.writeStringField("thestyle", theStyle);
if (theClass!=null) jgen.writeStringField("theclass", theClass);
jgen.writeArrayFieldStart("payload");
for (Object o : payload) {
if ( o instanceof dashRow ) {
((dashRow) o).serialize(jgen, boc);
} else if (!boc.writeObject(o, jgen, true))
jgen.writeObject(o.toString());
}
jgen.writeEndArray();
jgen.writeEndObject();
}
示例9: writePrincipals
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
/**
* Writes the list of <code>Principal</code>s to the JSONGenerator.
*
* @param principals
* the list of principals to be written.
*/
private void writePrincipals(List<Principal> principals)
throws JsonGenerationException, IOException {
if (principals.size() == 1 && principals.get(0).equals(Principal.All)) {
writeJsonKeyValue(JsonDocumentFields.PRINCIPAL, Principal.All.getId());
} else {
writeJsonObjectStart(JsonDocumentFields.PRINCIPAL);
Map<String, List<String>> principalsByScheme = groupPrincipalByScheme(principals);
List<String> principalValues;
for (Map.Entry<String, List<String>> entry : principalsByScheme.entrySet()) {
principalValues = principalsByScheme.get(entry.getKey());
if (principalValues.size() == 1) {
writeJsonKeyValue(entry.getKey(), principalValues.get(0));
} else {
writeJsonArray(entry.getKey(), principalValues);
}
}
writeJsonObjectEnd();
}
}
示例10: withWriter
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
/**
* A callback so a JsonGenerator can be used inline but exception are handled here
* @param outStream OutputStream
* @param writer The writer interface
* @throws IOException
*/
public void withWriter(OutputStream outStream, Writer writer) throws IOException
{
try
{
JsonGenerator generator = objectMapper.getJsonFactory().createJsonGenerator(outStream, encoding);
writer.writeContents(generator, objectMapper);
}
catch (JsonMappingException error)
{
logger.error("Failed to write Json output",error);
}
catch (JsonGenerationException generror)
{
logger.error("Failed to write Json output",generror);
}
}
示例11: writeConditions
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
/**
* Writes the list of conditions to the JSONGenerator.
*
* @param conditions
* the conditions to be written.
*/
private void writeConditions(List<Condition> conditions)
throws JsonGenerationException, IOException {
Map<String, ConditionsByKey> conditionsByType = groupConditionsByTypeAndKey(conditions);
writeJsonObjectStart(JsonDocumentFields.CONDITION);
ConditionsByKey conditionsByKey;
for (Map.Entry<String, ConditionsByKey> entry : conditionsByType
.entrySet()) {
conditionsByKey = conditionsByType.get(entry.getKey());
writeJsonObjectStart(entry.getKey());
for (String key : conditionsByKey.keySet()) {
writeJsonArray(key, conditionsByKey.getConditionsByKey(key));
}
writeJsonObjectEnd();
}
writeJsonObjectEnd();
}
示例12: testSerializeComment
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
@Test
public void testSerializeComment() throws IOException
{
final Comment aComment = new Comment();
aComment.setContent("<b>There it is</b>");
ByteArrayOutputStream out = new ByteArrayOutputStream();
jsonHelper.withWriter(out, new Writer()
{
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
throws JsonGenerationException, JsonMappingException, IOException
{
FilterProvider fp = new SimpleFilterProvider().addFilter(
JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
objectMapper.writer(fp).writeValue(generator, aComment);
}
});
assertTrue(out.toString().contains("{\"content\":\"<b>There it is</b>\""));
}
示例13: logShouldSwallowExceptions
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
@Test
public void logShouldSwallowExceptions() throws JsonProcessingException {
SystemFragment frag = SystemFragment.empty();
Mockito.when(analyzerMock.analyzeSystem()).thenReturn(frag);
Mockito.when(objectMapperMock.writeValueAsString(frag)).thenThrow(Mockito.mock(JsonGenerationException.class));
logSnitch.log();
Mockito.verify(analyzerMock).analyzeSystem();
Mockito.verify(objectMapperMock).writeValueAsString(frag);
}
示例14: serialize
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
@Override
public void serialize(CategoryEntity value, JsonGenerator gen, SerializerProvider provider) throws IOException {
if (null == value) {
throw new JsonGenerationException("Could not serialize object to json, input object to serialize is null");
}
StringWriter writer = new StringWriter();
mapper.writeValue(writer, value);
gen.writeFieldName(writer.toString());
}
示例15: serialize
import com.fasterxml.jackson.core.JsonGenerationException; //导入依赖的package包/类
@Override
public void serialize(JSONOptions value, JsonGenerator jgen, SerializerProvider provider) throws IOException,
JsonGenerationException {
if (value.opaque != null) {
jgen.writeObject(value.opaque);
} else {
jgen.writeTree(value.root);
}
}