Search in sources :

Example 6 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 7 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 8 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)

Example 9 with SerializedString

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

the class TestTokenBuffer method testBasicSerialize.

public void testBasicSerialize() throws IOException {
    TokenBuffer buf;
    // let's see how empty works...
    buf = new TokenBuffer(MAPPER, false);
    assertEquals("", MAPPER.writeValueAsString(buf));
    buf.close();
    buf = new TokenBuffer(MAPPER, false);
    buf.writeStartArray();
    buf.writeBoolean(true);
    buf.writeBoolean(false);
    long l = 1L + Integer.MAX_VALUE;
    buf.writeNumber(l);
    buf.writeNumber((short) 4);
    buf.writeNumber(0.5);
    buf.writeEndArray();
    assertEquals(aposToQuotes("[true,false," + l + ",4,0.5]"), MAPPER.writeValueAsString(buf));
    buf.close();
    buf = new TokenBuffer(MAPPER, false);
    buf.writeStartObject();
    buf.writeFieldName(new SerializedString("foo"));
    buf.writeNull();
    buf.writeFieldName("bar");
    buf.writeNumber(BigInteger.valueOf(123));
    buf.writeFieldName("dec");
    buf.writeNumber(BigDecimal.valueOf(5).movePointLeft(2));
    assertEquals(aposToQuotes("{'foo':null,'bar':123,'dec':0.05}"), MAPPER.writeValueAsString(buf));
    buf.close();
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString)

Example 10 with SerializedString

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

the class NextXxxAccessTest method _testIsNextTokenName2.

private void _testIsNextTokenName2(int mode) throws Exception {
    final String DOC = "{\"name\":123,\"name2\":14,\"x\":\"name\"}";
    JsonParser p = createParser(mode, DOC);
    SerializableString NAME = new SerializedString("name");
    assertFalse(p.nextFieldName(NAME));
    assertToken(JsonToken.START_OBJECT, p.currentToken());
    assertTrue(p.nextFieldName(NAME));
    assertToken(JsonToken.FIELD_NAME, p.currentToken());
    assertEquals(NAME.getValue(), p.getCurrentName());
    assertEquals(NAME.getValue(), p.getText());
    assertFalse(p.nextFieldName(NAME));
    assertToken(JsonToken.VALUE_NUMBER_INT, p.currentToken());
    assertEquals(123, p.getIntValue());
    assertFalse(p.nextFieldName(NAME));
    assertToken(JsonToken.FIELD_NAME, p.currentToken());
    assertEquals("name2", p.getCurrentName());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertFalse(p.nextFieldName(NAME));
    assertToken(JsonToken.FIELD_NAME, p.currentToken());
    assertEquals("x", p.getCurrentName());
    assertFalse(p.nextFieldName(NAME));
    assertToken(JsonToken.VALUE_STRING, p.currentToken());
    assertFalse(p.nextFieldName(NAME));
    assertToken(JsonToken.END_OBJECT, p.currentToken());
    if (mode != MODE_DATA_INPUT) {
        assertFalse(p.nextFieldName(NAME));
        assertNull(p.currentToken());
    }
    p.close();
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) SerializedString(com.fasterxml.jackson.core.io.SerializedString)

Aggregations

SerializedString (com.fasterxml.jackson.core.io.SerializedString)18 SerializableString (com.fasterxml.jackson.core.SerializableString)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 RawValue (com.fasterxml.jackson.databind.util.RawValue)1 StringWriter (java.io.StringWriter)1 BigDecimal (java.math.BigDecimal)1 ByteBuffer (java.nio.ByteBuffer)1 Random (java.util.Random)1