use of com.fasterxml.jackson.core.JsonParser in project OpenAM by OpenRock.
the class RestSTSInstanceConfigTest method testJsonStringMarshalling.
@Test
public void testJsonStringMarshalling() throws IOException {
RestSTSInstanceConfig origConfig = createInstanceConfig("/bob", WITH_TLS_OFFLOAD_CONFIG, WITH_SAML2_CONFIG, WITH_OIDC_CONFIG, WITH_CUSTOM_VALIDATOR, WITH_CUSTOM_PROVIDER, WITH_CTS_TOKEN_PERSISTENCE);
/*
This is how the Crest HttpServletAdapter ultimately constitutes a JsonValue from a json string. See the
org.forgerock.json.resource.servlet.HttpUtils.parseJsonBody (called from HttpServletAdapter.getJsonContent)
for details.
*/
JsonParser parser = new ObjectMapper().getFactory().createParser(origConfig.toJson().toString());
final Object content = parser.readValueAs(Object.class);
assertEquals(origConfig, RestSTSInstanceConfig.fromJson(new JsonValue(content)));
}
use of com.fasterxml.jackson.core.JsonParser in project OpenAM by OpenRock.
the class SoapSTSInstanceConfigTest method testJsonStringMarshalling.
@Test
public void testJsonStringMarshalling() throws IOException {
SoapSTSInstanceConfig origConfig = createInstanceConfig("/bobo/instance1", "http://host.com:8080/am", WITH_KEYSTORE_CONFIG, WITH_VALIDATE_CONFIG, DELEGATION_VALIDATORS_SPECIFIED, CUSTOM_DELEGATION_HANDLER, WITH_SAML2_CONFIG, WITH_OIDC_CONFIG, !WITH_CTS_TOKEN_PERSISTENCE);
/*
This is how the Crest HttpServletAdapter ultimately constitutes a JsonValue from a json string. See the
org.forgerock.json.resource.servlet.HttpUtils.parseJsonBody (called from HttpServletAdapter.getJsonContent)
for details.
*/
JsonParser parser = new ObjectMapper().getFactory().createParser(origConfig.toJson().toString());
final Object content = parser.readValueAs(Object.class);
assertEquals(origConfig, SoapSTSInstanceConfig.fromJson(new JsonValue(content)));
}
use of com.fasterxml.jackson.core.JsonParser in project jackson-core by FasterXML.
the class Surrogate223Test method testSurrogatesByteBacked.
// for [core#223]
public void testSurrogatesByteBacked() throws Exception {
ByteArrayOutputStream out;
JsonGenerator g;
final String toQuote = new String(Character.toChars(0x1F602));
// just sanity check
assertEquals(2, toQuote.length());
// default should be disabled:
// assertFalse(JSON_F.isEnabled(JsonGenerator.Feature.ESCAPE_UTF8_SURROGATES));
out = new ByteArrayOutputStream();
g = JSON_F.createGenerator(out);
g.writeStartArray();
g.writeString(toQuote);
g.writeEndArray();
g.close();
// brackets, quotes, 4-byte encoding
assertEquals(2 + 2 + 4, out.size());
// Also parse back to ensure correctness
JsonParser p = JSON_F.createParser(out.toByteArray());
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertToken(JsonToken.END_ARRAY, p.nextToken());
p.close();
// but may revert back to original behavior
out = new ByteArrayOutputStream();
g = JSON_F.createGenerator(out);
// g.enable(JsonGenerator.Feature.ESCAPE_UTF8_SURROGATES);
g.writeStartArray();
g.writeString(toQuote);
g.writeEndArray();
g.close();
// brackets, quotes, 2 x 6 byte JSON escape
assertEquals(2 + 2 + 12, out.size());
}
use of com.fasterxml.jackson.core.JsonParser in project jackson-core by FasterXML.
the class Surrogate223Test method testSurrogatesCharBacked.
// for [core#223]
public void testSurrogatesCharBacked() throws Exception {
Writer out;
JsonGenerator g;
final String toQuote = new String(Character.toChars(0x1F602));
// just sanity check
assertEquals(2, toQuote.length());
// default should be disabled:
// assertFalse(JSON_F.isEnabled(JsonGenerator.Feature.ESCAPE_UTF8_SURROGATES));
out = new StringWriter();
g = JSON_F.createGenerator(out);
g.writeStartArray();
g.writeString(toQuote);
g.writeEndArray();
g.close();
// brackets, quotes, 2 chars as is
assertEquals(2 + 2 + 2, out.toString().length());
// Also parse back to ensure correctness
JsonParser p = JSON_F.createParser(out.toString());
assertToken(JsonToken.START_ARRAY, p.nextToken());
assertToken(JsonToken.VALUE_STRING, p.nextToken());
assertToken(JsonToken.END_ARRAY, p.nextToken());
p.close();
// but may revert back to original behavior
out = new StringWriter();
g = JSON_F.createGenerator(out);
// g.enable(JsonGenerator.Feature.ESCAPE_UTF8_SURROGATES);
g.writeStartArray();
g.writeString(toQuote);
g.writeEndArray();
g.close();
// brackets, quotes, 2 x 6 byte JSON escape
assertEquals(2 + 2 + 12, out.toString().length());
}
use of com.fasterxml.jackson.core.JsonParser in project jackson-core by FasterXML.
the class TestParserOverrides method _testTokenAccess.
/*
/**********************************************************
/* Actual test methods
/**********************************************************
*/
public void _testTokenAccess(JsonFactory jf, boolean useStream) throws Exception {
final String DOC = "[ ]";
JsonParser jp = useStream ? jf.createParser(new ByteArrayInputStream(DOC.getBytes("UTF-8"))) : jf.createParser(DOC);
assertNull(jp.currentToken());
jp.clearCurrentToken();
assertNull(jp.currentToken());
assertNull(jp.getEmbeddedObject());
assertToken(JsonToken.START_ARRAY, jp.nextToken());
assertToken(JsonToken.START_ARRAY, jp.currentToken());
jp.clearCurrentToken();
assertNull(jp.currentToken());
// Also: no codec defined by default
try {
jp.readValueAsTree();
fail("Should get exception without codec");
} catch (IllegalStateException e) {
verifyException(e, "No ObjectCodec defined");
}
jp.close();
}
Aggregations