Search in sources :

Example 1 with SerializedString

use of com.fasterxml.jackson.core.io.SerializedString in project jackson-core by FasterXML.

the class TestSerializedString method testFailedAccess.

public void testFailedAccess() throws IOException {
    final String INPUT = "Bit longer text";
    SerializableString sstr = new SerializedString(INPUT);
    final byte[] buffer = new byte[INPUT.length() - 2];
    final char[] ch = new char[INPUT.length() - 2];
    final ByteBuffer bbuf = ByteBuffer.allocate(INPUT.length() - 2);
    assertEquals(-1, sstr.appendQuotedUTF8(buffer, 0));
    assertEquals(-1, sstr.appendQuoted(ch, 0));
    assertEquals(-1, sstr.putQuotedUTF8(bbuf));
    bbuf.rewind();
    assertEquals(-1, sstr.appendUnquotedUTF8(buffer, 0));
    assertEquals(-1, sstr.appendUnquoted(ch, 0));
    assertEquals(-1, sstr.putUnquotedUTF8(bbuf));
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) SerializableString(com.fasterxml.jackson.core.SerializableString) SerializedString(com.fasterxml.jackson.core.io.SerializedString) SerializableString(com.fasterxml.jackson.core.SerializableString) ByteBuffer(java.nio.ByteBuffer)

Example 2 with SerializedString

use of com.fasterxml.jackson.core.io.SerializedString in project jackson-core by FasterXML.

the class NextXxxAccessTest method _testIssue38.

private void _testIssue38(int mode) throws Exception {
    final String DOC = "{\"field\" :\"value\"}";
    SerializableString fieldName = new SerializedString("field");
    JsonParser parser = createParser(mode, DOC);
    assertEquals(JsonToken.START_OBJECT, parser.nextToken());
    assertTrue(parser.nextFieldName(fieldName));
    assertEquals(JsonToken.VALUE_STRING, parser.nextToken());
    assertEquals("value", parser.getText());
    assertEquals(JsonToken.END_OBJECT, parser.nextToken());
    if (mode != MODE_DATA_INPUT) {
        assertNull(parser.nextToken());
    }
    parser.close();
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) SerializedString(com.fasterxml.jackson.core.io.SerializedString)

Example 3 with SerializedString

use of com.fasterxml.jackson.core.io.SerializedString in project jackson-core by FasterXML.

the class NextXxxAccessTest method _testIsNextTokenName4.

private void _testIsNextTokenName4(int mode) throws Exception {
    final String DOC = "{\"name\":-123,\"name2\":99}";
    JsonParser p = createParser(mode, DOC);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    assertTrue(p.nextFieldName(new SerializedString("name")));
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(-123, p.getIntValue());
    assertTrue(p.nextFieldName(new SerializedString("name2")));
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(99, p.getIntValue());
    assertToken(JsonToken.END_OBJECT, p.nextToken());
    if (mode != MODE_DATA_INPUT) {
        assertNull(p.nextToken());
    }
    p.close();
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) SerializedString(com.fasterxml.jackson.core.io.SerializedString)

Example 4 with SerializedString

use of com.fasterxml.jackson.core.io.SerializedString in project jackson-core by FasterXML.

the class NextXxxAccessTest method _testNextNameWithLong.

private void _testNextNameWithLong(int mode) throws Exception {
    // do 5 meg thingy
    final int SIZE = 5 * 1024 * 1024;
    StringBuilder sb = new StringBuilder(SIZE + 20);
    sb.append("{");
    Random rnd = new Random(1);
    int count = 0;
    while (sb.length() < SIZE) {
        ++count;
        if (sb.length() > 1) {
            sb.append(", ");
        }
        int val = rnd.nextInt();
        sb.append('"');
        sb.append("f" + val);
        sb.append("\":");
        sb.append(String.valueOf(val % 1000));
    }
    sb.append("}");
    final String DOC = sb.toString();
    JsonParser parser = createParser(mode, DOC);
    assertToken(JsonToken.START_OBJECT, parser.nextToken());
    rnd = new Random(1);
    for (int i = 0; i < count; ++i) {
        int exp = rnd.nextInt();
        SerializableString expName = new SerializedString("f" + exp);
        assertTrue(parser.nextFieldName(expName));
        assertToken(JsonToken.VALUE_NUMBER_INT, parser.nextToken());
        assertEquals(exp % 1000, parser.getIntValue());
    }
    assertToken(JsonToken.END_OBJECT, parser.nextToken());
    parser.close();
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) Random(java.util.Random) SerializedString(com.fasterxml.jackson.core.io.SerializedString)

Example 5 with SerializedString

use of com.fasterxml.jackson.core.io.SerializedString in project jackson-databind by FasterXML.

the class TestJsonNode method testRawValue.

// [databind#743]
public void testRawValue() throws Exception {
    ObjectNode root = MAPPER.createObjectNode();
    root.putRawValue("a", new RawValue(new SerializedString("[1, 2, 3]")));
    assertEquals("{\"a\":[1, 2, 3]}", MAPPER.writeValueAsString(root));
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) RawValue(com.fasterxml.jackson.databind.util.RawValue)

Aggregations

SerializedString (com.fasterxml.jackson.core.io.SerializedString)23 SerializableString (com.fasterxml.jackson.core.SerializableString)4 Test (org.junit.Test)4 JsonpCharacterEscapes (com.fasterxml.jackson.core.util.JsonpCharacterEscapes)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 CharacterEscapes (com.fasterxml.jackson.core.io.CharacterEscapes)1 UTF8DataInputJsonParser (com.fasterxml.jackson.core.json.UTF8DataInputJsonParser)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 RawValue (com.fasterxml.jackson.databind.util.RawValue)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 BigDecimal (java.math.BigDecimal)1 ByteBuffer (java.nio.ByteBuffer)1 Random (java.util.Random)1