You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@johnzon.apache.org by Hendrik Dev <he...@gmail.com> on 2014/06/27 17:34:15 UTC
JsonGenerator chaining enforced
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
Re: JsonGenerator chaining enforced
Posted by Romain Manni-Bucau <rm...@gmail.com>.
should be fixed
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-06-27 19:16 GMT+02:00 Romain Manni-Bucau <rm...@gmail.com>:
> Would have expected JsonGeneratorFacade (no generics) and new JsonGeneratorFacade(gesonGeneratorImpl/*
> pretty or not */)
>
> but yes you got the idea otheriwse. I have few cycles now (I'm on IRC if
> you want) so trying to fix it in the coming hour.
>
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> 2014-06-27 18:12 GMT+02:00 Hendrik Dev <he...@gmail.com>:
>
> sure
>>
>> maybe something like this:
>>
>> https://github.com/salyh/fleece_tmp/commit/2dbb1dfb2f728a32ffcbf804d5e7dae3bea18558
>>
>> On Fri, Jun 27, 2014 at 5:36 PM, Romain Manni-Bucau
>> <rm...@gmail.com> wrote:
>> > Yes this is the case (see the mapper impl).
>> >
>> > But you are right. Spec mandates it to be a single instance.
>> >
>> > I think the easiest will be to get a JsonGeneratorFacade delegate to
>> > JsonGenerateImpl (names are just to give the idea). Wouldn't need a lot
>> of
>> > dev.
>> >
>> > Do you want to have a try?
>> >
>> >
>> >
>> > Romain Manni-Bucau
>> > Twitter: @rmannibucau
>> > Blog: http://rmannibucau.wordpress.com/
>> > LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> > Github: https://github.com/rmannibucau
>> >
>> >
>> > 2014-06-27 17:34 GMT+02:00 Hendrik Dev <he...@gmail.com>:
>> >
>> >> 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
>> >>
>>
>
>
Re: JsonGenerator chaining enforced
Posted by Hendrik Dev <he...@gmail.com>.
just saw the commit, its nicer than my stuff
On Fri, Jun 27, 2014 at 7:16 PM, Romain Manni-Bucau
<rm...@gmail.com> wrote:
> Would have expected JsonGeneratorFacade (no generics) and new
> JsonGeneratorFacade(gesonGeneratorImpl/*
> pretty or not */)
>
> but yes you got the idea otheriwse. I have few cycles now (I'm on IRC if
> you want) so trying to fix it in the coming hour.
>
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> 2014-06-27 18:12 GMT+02:00 Hendrik Dev <he...@gmail.com>:
>
>> sure
>>
>> maybe something like this:
>>
>> https://github.com/salyh/fleece_tmp/commit/2dbb1dfb2f728a32ffcbf804d5e7dae3bea18558
>>
>> On Fri, Jun 27, 2014 at 5:36 PM, Romain Manni-Bucau
>> <rm...@gmail.com> wrote:
>> > Yes this is the case (see the mapper impl).
>> >
>> > But you are right. Spec mandates it to be a single instance.
>> >
>> > I think the easiest will be to get a JsonGeneratorFacade delegate to
>> > JsonGenerateImpl (names are just to give the idea). Wouldn't need a lot
>> of
>> > dev.
>> >
>> > Do you want to have a try?
>> >
>> >
>> >
>> > Romain Manni-Bucau
>> > Twitter: @rmannibucau
>> > Blog: http://rmannibucau.wordpress.com/
>> > LinkedIn: http://fr.linkedin.com/in/rmannibucau
>> > Github: https://github.com/rmannibucau
>> >
>> >
>> > 2014-06-27 17:34 GMT+02:00 Hendrik Dev <he...@gmail.com>:
>> >
>> >> 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
>> >>
>>
Re: JsonGenerator chaining enforced
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Would have expected JsonGeneratorFacade (no generics) and new
JsonGeneratorFacade(gesonGeneratorImpl/*
pretty or not */)
but yes you got the idea otheriwse. I have few cycles now (I'm on IRC if
you want) so trying to fix it in the coming hour.
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-06-27 18:12 GMT+02:00 Hendrik Dev <he...@gmail.com>:
> sure
>
> maybe something like this:
>
> https://github.com/salyh/fleece_tmp/commit/2dbb1dfb2f728a32ffcbf804d5e7dae3bea18558
>
> On Fri, Jun 27, 2014 at 5:36 PM, Romain Manni-Bucau
> <rm...@gmail.com> wrote:
> > Yes this is the case (see the mapper impl).
> >
> > But you are right. Spec mandates it to be a single instance.
> >
> > I think the easiest will be to get a JsonGeneratorFacade delegate to
> > JsonGenerateImpl (names are just to give the idea). Wouldn't need a lot
> of
> > dev.
> >
> > Do you want to have a try?
> >
> >
> >
> > Romain Manni-Bucau
> > Twitter: @rmannibucau
> > Blog: http://rmannibucau.wordpress.com/
> > LinkedIn: http://fr.linkedin.com/in/rmannibucau
> > Github: https://github.com/rmannibucau
> >
> >
> > 2014-06-27 17:34 GMT+02:00 Hendrik Dev <he...@gmail.com>:
> >
> >> 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
> >>
>
Re: JsonGenerator chaining enforced
Posted by Hendrik Dev <he...@gmail.com>.
sure
maybe something like this:
https://github.com/salyh/fleece_tmp/commit/2dbb1dfb2f728a32ffcbf804d5e7dae3bea18558
On Fri, Jun 27, 2014 at 5:36 PM, Romain Manni-Bucau
<rm...@gmail.com> wrote:
> Yes this is the case (see the mapper impl).
>
> But you are right. Spec mandates it to be a single instance.
>
> I think the easiest will be to get a JsonGeneratorFacade delegate to
> JsonGenerateImpl (names are just to give the idea). Wouldn't need a lot of
> dev.
>
> Do you want to have a try?
>
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
> 2014-06-27 17:34 GMT+02:00 Hendrik Dev <he...@gmail.com>:
>
>> 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
>>
Re: JsonGenerator chaining enforced
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Yes this is the case (see the mapper impl).
But you are right. Spec mandates it to be a single instance.
I think the easiest will be to get a JsonGeneratorFacade delegate to
JsonGenerateImpl (names are just to give the idea). Wouldn't need a lot of
dev.
Do you want to have a try?
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-06-27 17:34 GMT+02:00 Hendrik Dev <he...@gmail.com>:
> 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
>