fleece-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hendrik Dev <hendrikde...@gmail.com>
Subject JsonGenerator chaining enforced
Date Fri, 27 Jun 2014 15:34:15 GMT
Hi,

don't know if this is an issue but it seems that the JsonGenerator
must be used in fluent/chaining style:


    @Test
    public void generateChain() {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final JsonGenerator generator = Json.createGenerator(baos);
        generator.writeStartObject().write("firstName",
"John").writeEnd().close();
        assertEquals("{\"firstName\":\"John\"}", new
String(baos.toByteArray()));
    } //this testcase works well

    @Test
    public void generateNonChain() {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final JsonGenerator generator = Json.createGenerator(baos);
        generator.writeStartObject();
        generator.write("firstName", "John");
        generator.writeEnd();
        generator.close();
        assertEquals("{\"firstName\":\"John\"}", new
String(baos.toByteArray()));
    } //this fails because of a leading and dangling comma

API spec say: -can- be chained

Thanks
Hendrik

Mime
View raw message