Search in sources :

Example 6 with SerializedString

use of org.apache.flink.shaded.jackson2.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 7 with SerializedString

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

the class BasicGeneratorFilteringTest method testSingleMatchFilteringWithPathAlternate1.

// Alternative take, using slightly different calls for FIELD_NAME, START_ARRAY
public void testSingleMatchFilteringWithPathAlternate1() throws Exception {
    StringWriter w = new StringWriter();
    FilteringGeneratorDelegate gen = new FilteringGeneratorDelegate(JSON_F.createGenerator(ObjectWriteContext.empty(), w), new NameMatchFilter("value"), // includePath
    true, // multipleMatches
    false);
    // final String JSON = "{'a':123,'array':[1,2],'ob':{'value0':2,'value':[3],'value2':'foo'},'b':true}";
    gen.writeStartObject();
    gen.writeFieldName(new SerializedString("a"));
    gen.writeNumber(123);
    gen.writeFieldName("array");
    gen.writeStartArray(2);
    gen.writeNumber("1");
    gen.writeNumber((short) 2);
    gen.writeEndArray();
    gen.writeFieldName(new SerializedString("ob"));
    gen.writeStartObject();
    gen.writeNumberField("value0", 2);
    gen.writeFieldName(new SerializedString("value"));
    gen.writeStartArray(1);
    // just to vary generation method
    gen.writeString(new SerializedString("x"));
    gen.writeEndArray();
    gen.writeStringField("value2", "foo");
    gen.writeEndObject();
    gen.writeBooleanField("b", true);
    gen.writeEndObject();
    gen.close();
    assertEquals(aposToQuotes("{'ob':{'value':['x']}}"), w.toString());
    assertEquals(1, gen.getMatchCount());
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString)

Example 8 with SerializedString

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

the class BasicGeneratorFilteringTest method testSingleMatchFilteringWithPathRawBinary.

public void testSingleMatchFilteringWithPathRawBinary() throws Exception {
    StringWriter w = new StringWriter();
    FilteringGeneratorDelegate gen = new FilteringGeneratorDelegate(JSON_F.createGenerator(ObjectWriteContext.empty(), w), new NameMatchFilter("array"), // includePath
    true, // multipleMatches
    false);
    // final String JSON = "{'header':['ENCODED',raw],'array':['base64stuff',1,2,3,4,5,6.25,7.5],'extra':[1,2,3,4,5,6.25,7.5]}";
    gen.writeStartObject();
    gen.writeFieldName("header");
    gen.writeStartArray();
    gen.writeBinary(new byte[] { 1 });
    gen.writeRawValue(new SerializedString("1"));
    gen.writeRawValue("2");
    gen.writeEndArray();
    gen.writeFieldName("array");
    gen.writeStartArray();
    gen.writeBinary(new byte[] { 1 });
    gen.writeNumber((short) 1);
    gen.writeNumber((int) 2);
    gen.writeNumber((long) 3);
    gen.writeNumber(BigInteger.valueOf(4));
    gen.writeRaw(" ");
    gen.writeNumber(new BigDecimal("5.0"));
    gen.writeRaw(new SerializedString(" /*x*/"));
    gen.writeNumber(6.25f);
    gen.writeNumber(7.5);
    gen.writeEndArray();
    gen.writeArrayFieldStart("extra");
    gen.writeNumber((short) 1);
    gen.writeNumber((int) 2);
    gen.writeNumber((long) 3);
    gen.writeNumber(BigInteger.valueOf(4));
    gen.writeNumber(new BigDecimal("5.0"));
    gen.writeNumber(6.25f);
    gen.writeNumber(7.5);
    gen.writeEndArray();
    gen.writeEndObject();
    gen.close();
    assertEquals(aposToQuotes("{'array':['AQ==',1,2,3,4 ,5.0 /*x*/,6.25,7.5]}"), w.toString());
    assertEquals(1, gen.getMatchCount());
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) BigDecimal(java.math.BigDecimal)

Example 9 with SerializedString

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

the class JsonpCharacterEscapesTest method testGetEscapeSequenceOne.

@Test
public void testGetEscapeSequenceOne() {
    JsonpCharacterEscapes jsonpCharacterEscapes = JsonpCharacterEscapes.instance();
    assertEquals(new SerializedString("\\u2028"), jsonpCharacterEscapes.getEscapeSequence(0x2028));
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) JsonpCharacterEscapes(com.fasterxml.jackson.core.util.JsonpCharacterEscapes) Test(org.junit.Test)

Example 10 with SerializedString

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

the class TrailingCommasTest method testObjectTrailingCommaWithNextFieldNameStr.

@Test
public void testObjectTrailingCommaWithNextFieldNameStr() throws Exception {
    String json = "{\"a\": true, \"b\": false,}";
    JsonParser p = createParser(factory, mode, json);
    assertEquals(JsonToken.START_OBJECT, p.nextToken());
    assertTrue(p.nextFieldName(new SerializedString("a")));
    assertToken(JsonToken.VALUE_TRUE, p.nextToken());
    assertTrue(p.nextFieldName(new SerializedString("b")));
    assertToken(JsonToken.VALUE_FALSE, p.nextToken());
    if (features.contains(Feature.ALLOW_TRAILING_COMMA)) {
        assertFalse(p.nextFieldName(new SerializedString("c")));
        assertToken(JsonToken.END_OBJECT, p.currentToken());
        assertEnd(p);
    } else {
        try {
            p.nextFieldName(new SerializedString("c"));
            fail("No exception thrown");
        } catch (Exception e) {
            verifyException(e, "Unexpected character ('}' (code 125))");
        }
    }
    p.close();
}
Also used : SerializedString(com.fasterxml.jackson.core.io.SerializedString) SerializedString(com.fasterxml.jackson.core.io.SerializedString) IOException(java.io.IOException) UTF8DataInputJsonParser(com.fasterxml.jackson.core.json.UTF8DataInputJsonParser) Test(org.junit.Test)

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