Search in sources :

Example 11 with SerializedString

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.io.SerializedString in project jackson-core by FasterXML.

the class TestRawStringWriting method _testWithRaw.

private void _testWithRaw(JsonFactory f, boolean useBytes) throws Exception {
    JsonGenerator g;
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    StringWriter sw = new StringWriter();
    if (useBytes) {
        g = f.createGenerator(ObjectWriteContext.empty(), bytes, JsonEncoding.UTF8);
    } else {
        g = f.createGenerator(ObjectWriteContext.empty(), sw);
    }
    g.writeStartArray();
    g.writeRawValue(new SerializedString("\"foo\""));
    g.writeRawValue(new SerializedString("12"));
    g.writeRaw(new SerializedString(", false"));
    g.writeEndArray();
    g.close();
    JsonParser p = useBytes ? f.createParser(ObjectReadContext.empty(), bytes.toByteArray()) : f.createParser(ObjectReadContext.empty(), sw.toString());
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    assertToken(JsonToken.VALUE_STRING, p.nextToken());
    assertEquals("foo", p.getText());
    assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
    assertEquals(12, p.getIntValue());
    assertToken(JsonToken.VALUE_FALSE, p.nextToken());
    assertToken(JsonToken.END_ARRAY, p.nextToken());
    p.close();
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString)

Example 12 with SerializedString

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.io.SerializedString in project bson4jackson by michel-kraemer.

the class BsonGeneratorTest method characterEscapes.

/**
 * Test if {@link CharacterEscapes} are supported
 * @throws Exception if something goes wrong
 */
@Test
public void characterEscapes() throws Exception {
    JsonNode node = new ObjectMapper().readTree("{ \"some.field\": \"some.val\", " + "\"another\": \"field\", " + "\".some\": \".field\", " + "\"some.\": \"field.\" }");
    ObjectMapper bsonMapper = new ObjectMapper(new BsonFactory());
    bsonMapper.getFactory().setCharacterEscapes(new CharacterEscapes() {

        private static final long serialVersionUID = 283833498358662446L;

        @Override
        public int[] getEscapeCodesForAscii() {
            int[] escapes = CharacterEscapes.standardAsciiEscapesForJSON();
            escapes['.'] = CharacterEscapes.ESCAPE_CUSTOM;
            return escapes;
        }

        @Override
        public SerializableString getEscapeSequence(int ch) {
            switch(ch) {
                case '.':
                    return new SerializedString("\uff0e");
            }
            return null;
        }
    });
    byte[] bsonBytes = bsonMapper.writeValueAsBytes(node);
    byte[] sBytes = new byte[] { // document length
    0x61, 0x00, 0x00, 0x00, // type = string
    0x02, // 's'   'o'   'm'   'e'
    0x73, 0x6f, 0x6d, 0x65, // escape sequence
    (byte) 0xef, (byte) 0xbc, (byte) 0x8e, // 'f'   'i'   'e'   'l'   'd'
    0x66, 0x69, 0x65, 0x6c, 0x64, // end of string
    0x00, // string length (0x0b = 10 characters + trailing 0x00)
    0x0b, 0x00, 0x00, 0x00, // 's'   'o'   'm'   'e'
    0x73, 0x6f, 0x6d, 0x65, // escape sequence
    (byte) 0xef, (byte) 0xbc, (byte) 0x8e, // 'v'   'a'   'l'
    0x76, 0x61, 0x6c, // end of string
    0x00, // type = string
    0x02, // 'a'   'n'   'o'   't'   'h'   'e'   'r'
    0x61, 0x6e, 0x6f, 0x74, 0x68, 0x65, 0x72, // end of string
    0x00, // string length (5 characters + trailing 0x00)
    0x06, 0x00, 0x00, 0x00, // 'f'   'i'   'e'   'l'   'd'
    0x66, 0x69, 0x65, 0x6c, 0x64, // end of string
    0x00, // type = string
    0x02, // escape sequence
    (byte) 0xef, (byte) 0xbc, (byte) 0x8e, // 's'   'o'   'm'   'e'
    0x73, 0x6f, 0x6d, 0x65, // end of string
    0x00, // string length (8 characters + trailing 0x00)
    0x09, 0x00, 0x00, 0x00, // escape sequence
    (byte) 0xef, (byte) 0xbc, (byte) 0x8e, // 'f'   'i'   'e'   'l'   'd'
    0x66, 0x69, 0x65, 0x6c, 0x64, // end of string
    0x00, // type = string
    0x02, // 's'   'o'   'm'   'e'
    0x73, 0x6f, 0x6d, 0x65, // escape sequence
    (byte) 0xef, (byte) 0xbc, (byte) 0x8e, // end of string
    0x00, // string length (8 characters + trailing 0x00)
    0x09, 0x00, 0x00, 0x00, // 'f'   'i'   'e'   'l'   'd'
    0x66, 0x69, 0x65, 0x6c, 0x64, // escape sequence
    (byte) 0xef, (byte) 0xbc, (byte) 0x8e, // end of string
    0x00, // end of document
    0x00 };
    assertArrayEquals(sBytes, bsonBytes);
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) SerializableString(com.fasterxml.jackson.core.SerializableString) CharacterEscapes(com.fasterxml.jackson.core.io.CharacterEscapes) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 13 with SerializedString

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.io.SerializedString in project curiostack by curioswitch.

the class SerializeSupport method serializeString.

public static SerializedString serializeString(String name) {
    SerializedString s = new SerializedString(name);
    // Eagerly compute encodings.
    s.asQuotedChars();
    s.asQuotedUTF8();
    s.asUnquotedUTF8();
    return s;
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString)

Example 14 with SerializedString

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.io.SerializedString in project jackson-core by FasterXML.

the class NextXxxAccessTest method _testIssue34.

private void _testIssue34(int mode) throws Exception {
    final int TESTROUNDS = 223;
    final String DOC_PART = "{ \"fieldName\": 1 }";
    // build the big document to trigger issue
    StringBuilder sb = new StringBuilder(2000);
    for (int i = 0; i < TESTROUNDS; ++i) {
        sb.append(DOC_PART);
    }
    final String DOC = sb.toString();
    SerializableString fieldName = new SerializedString("fieldName");
    JsonParser parser = createParser(mode, DOC);
    for (int i = 0; i < TESTROUNDS - 1; i++) {
        assertEquals(JsonToken.START_OBJECT, parser.nextToken());
        // These will succeed
        assertTrue(parser.nextFieldName(fieldName));
        parser.nextLongValue(-1);
        assertEquals(JsonToken.END_OBJECT, parser.nextToken());
    }
    assertEquals(JsonToken.START_OBJECT, parser.nextToken());
    // This will fail
    assertTrue(parser.nextFieldName(fieldName));
    parser.close();
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) SerializedString(com.fasterxml.jackson.core.io.SerializedString)

Example 15 with SerializedString

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.io.SerializedString in project jackson-core by FasterXML.

the class NextXxxAccessTest method _testNextFieldNameIndent.

private void _testNextFieldNameIndent(int mode) throws Exception {
    final String DOC = "{\n  \"name\" : \n  [\n  ]\n   }";
    JsonParser p = createParser(mode, DOC);
    assertToken(JsonToken.START_OBJECT, p.nextToken());
    assertTrue(p.nextFieldName(new SerializedString("name")));
    assertToken(JsonToken.START_ARRAY, p.nextToken());
    assertToken(JsonToken.END_ARRAY, p.nextToken());
    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)

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