use of com.fasterxml.jackson.core.JsonFactory in project jackson-core by FasterXML.
the class TestJDKSerializability method testGenerationException.
public void testGenerationException() throws Exception {
JsonFactory jf = new JsonFactory();
JsonGenerator g = jf.createGenerator(new ByteArrayOutputStream());
JsonGenerationException exc = null;
g.writeStartObject();
try {
g.writeNumber(4);
fail("Should not get here");
} catch (JsonGenerationException e) {
exc = e;
}
g.close();
byte[] stuff = jdkSerialize(exc);
JsonGenerationException result = jdkDeserialize(stuff);
assertNotNull(result);
}
use of com.fasterxml.jackson.core.JsonFactory in project jackson-databind by FasterXML.
the class TestGeneratorUsingMapper method testPojoWritingFailing.
public void testPojoWritingFailing() throws IOException {
// regular factory can't do it, without a call to setCodec()
JsonFactory jf = new JsonFactory();
try {
StringWriter sw = new StringWriter();
JsonGenerator gen = jf.createGenerator(sw);
gen.writeObject(new Pojo());
gen.close();
fail("Expected an exception: got sw '" + sw.toString() + "'");
} catch (IllegalStateException e) {
verifyException(e, "No ObjectCodec defined");
}
}
use of com.fasterxml.jackson.core.JsonFactory in project graylog2-server by Graylog2.
the class JsonProcessingExceptionMapperTest method testToResponse.
@Test
public void testToResponse() throws Exception {
final ExceptionMapper<JsonProcessingException> mapper = new JsonProcessingExceptionMapper();
final JsonParser jsonParser = new JsonFactory().createParser("");
final JsonMappingException exception = new JsonMappingException(jsonParser, "Boom!", new RuntimeException("rootCause"));
final Response response = mapper.toResponse(exception);
assertEquals(response.getStatusInfo(), Response.Status.BAD_REQUEST);
assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
assertTrue(response.hasEntity());
assertTrue(response.getEntity() instanceof ApiError);
final ApiError responseEntity = (ApiError) response.getEntity();
assertTrue(responseEntity.getMessage().startsWith("Boom!"));
}
use of com.fasterxml.jackson.core.JsonFactory in project ig-json-parser by Instagram.
the class DeserializeTest method testCustomParse.
@Test
public void testCustomParse() throws Exception {
String value = "hey there";
StringWriter stringWriter = new StringWriter();
ExtensibleJSONWriter writer = new ExtensibleJSONWriter(stringWriter);
writer.object().key(CustomParseContainerUUT.INNER_FIELD_NAME).object().key(CustomParseContainerUUT.CustomParseUUT.STRING_FIELD_NAME).value(value).endObject().endObject();
String inputString = stringWriter.toString();
JsonParser jp = new JsonFactory().createParser(inputString);
jp.nextToken();
CustomParseContainerUUT uut = CustomParseContainerUUT__JsonHelper.parseFromJson(jp);
assertEquals(value, uut.getCustomParseUUT().getStringField());
}
use of com.fasterxml.jackson.core.JsonFactory in project ig-json-parser by Instagram.
the class DeserializeTest method testMapNullValue.
@Test
public void testMapNullValue() throws Exception {
StringWriter stringWriter = new StringWriter();
ExtensibleJSONWriter writer = new ExtensibleJSONWriter(stringWriter);
final String keyWithNullValue = "key_with_null_value";
writer.object().key(MapUUT.STRING_STRING_MAP_FIELD_NAME).object().key(keyWithNullValue).value(null).endObject().endObject();
String inputString = stringWriter.toString();
JsonParser jp = new JsonFactory().createParser(inputString);
jp.nextToken();
MapUUT uut = MapUUT__JsonHelper.parseFromJson(jp);
assertTrue(uut.stringStringMapField.containsKey(keyWithNullValue));
assertNull(uut.stringStringMapField.get(keyWithNullValue));
}
Aggregations