johnzon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hendrik Dev <hendrikde...@gmail.com>
Subject Re: prettification
Date Mon, 12 Oct 2015 08:49:43 GMT
ok, with that i can reproduce, will have a look today ....

@Test
    public void prettySimpleStructure() {

        final JsonWriterFactory writerFactory =
Json.createWriterFactory(new HashMap<String, Object>() {
            {
                put(JsonGenerator.PRETTY_PRINTING, true);
            }
        });

        StringWriter buffer = new StringWriter();

            try (final JsonWriter writer = writerFactory.createWriter(buffer)) {


writer.write(Json.createObjectBuilder().add("firstName",
"John").build());

            }
        assertEquals("{\n" + "  \"firstName\":\"John\"\n" + "}",
buffer.toString());
    }

On Mon, Oct 12, 2015 at 10:20 AM, Romain Manni-Bucau
<rmannibucau@gmail.com> wrote:
> I used:
>
> try (final JsonReader reader = readerFactory.createReader(new
> ByteArrayInputStream(someString.getBytes()))) {
>     try (final JsonWriter writer = writerFactory.createWriter(buffer))
> { // buffer is a StringWriter
>         writer.write(reader.read());
>     }
> }
>
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau>
|
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com>
>
> 2015-10-12 10:18 GMT+02:00 Hendrik Dev <hendrikdev22@gmail.com>:
>
>> i can look into this but cannot reproduce
>>
>> @Test
>>     public void prettySimple() {
>>         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
>>         final JsonGenerator generator =
>> Json.createGeneratorFactory(new HashMap<String, Object>() {{
>>             put(JsonGenerator.PRETTY_PRINTING, true);
>>         }}).createGenerator(baos);
>>
>>         generator.writeStartObject().write("firstName",
>> "John").writeEnd().close();
>>         assertEquals("{\n" +
>>
>>                         "  \"firstName\":\"John\"\n" +
>>
>>                         "}", new String(baos.toByteArray()));
>>
>>     }
>>
>> Can you provide a failing test?
>>
>> On Sun, Oct 11, 2015 at 9:33 PM, Romain Manni-Bucau
>> <rmannibucau@gmail.com> wrote:
>> > Hi guys,
>> >
>> > prettifying a json with johnzon leads to empty lines, what do you think
>> > about it? I'm tempted t get rid of them.
>> >
>> > Here is a sample:
>> >
>> > ----
>> > {"foo":"bar"}
>> > ----
>> >
>> > -> with johnzon
>> >
>> > -----
>> >
>> > {
>> >
>> >   "foo":"bar"
>> > }
>> > ----
>> >
>> >
>> > -> expected
>> >
>> > -----
>> > {
>> >   "foo":"bar"
>> > }
>> > ----
>> >
>> > If anyone wants to work on it happy to let you hack or I will tackle it
>> > next week probably.
>> >
>> > Romain Manni-Bucau
>> > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
>> > <http://rmannibucau.wordpress.com> | Github <
>> https://github.com/rmannibucau> |
>> > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
>> > <http://www.tomitribe.com>
>>
>>
>>
>> --
>> Hendrik Saly (salyh, hendrikdev22)
>> @hendrikdev22
>> PGP: 0x22D7F6EC
>>



-- 
Hendrik Saly (salyh, hendrikdev22)
@hendrikdev22
PGP: 0x22D7F6EC

Mime
View raw message