You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@samza.apache.org by Shekar Tippur <ct...@gmail.com> on 2014/12/08 11:53:24 UTC

Having trouble deserializing nested json payload

I have a nested JSON as payload.

For example,

{

  "source_ip": "1.2.3.4",

"source_type":null,

"creation_time":"1415296951",

"criticality":"4",

"raw":{"ACKNOWLEDGED":"false"}

}


I am using GSON to deserialize the payload.

I am having trouble with the nested part. "raw":{"ACKNOWLEDGED":"false"}

In my gson structure, I was trying to define it as

private JSONObject raw;

But this seem to throw a exception -

 Exception in thread "ThreadJob"
org.codehaus.jackson.map.JsonMappingException: No serializer found for
class org.json.JSONObject and no properties discovered to create
BeanSerializer (to avoid exception, disable
SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference
chain:
java.util.HashMap["event"]->samza.examples.wikipedia.system.ArgosAlert["raw"])

Appreciate if someone could point out how to handle this.

- Shekar

Re: Having trouble deserializing nested json payload

Posted by Chris Riccomini <cr...@linkedin.com.INVALID>.
Hey Paul,

We're on:

  jacksonVersion = "1.8.5"

The reason for this is to maintain compatibility with what YARN (Avro,
Jersey, hadoop-common) is depending on. If they upgrade, we will.


Cheers,
Chris

On 12/8/14 10:50 AM, "Paul Brown" <pr...@mult.ifario.us> wrote:

>Hopefully you're on a more modern version of Jackson; the Codehaus version
>is ancient at this point with 2.4.4 being the latest (
>https://github.com/fasterxml/jackson).
>
>
>‹
>prb@mult.ifario.us | Multifarious, Inc. | http://mult.ifario.us/
>
>On Mon, Dec 8, 2014 at 10:38 AM, Chris Riccomini <
>criccomini@linkedin.com.invalid> wrote:
>
>> Hey Shekar,
>>
>> It sounds like you're mixing serializers. Samza's JSON (de)serializer is
>> implemented using Jackson:
>>
>>   http://jackson.codehaus.org/
>>
>> The JSONObject is part of org.json:
>>
>>   http://www.json.org/java/index.html
>>
>> These are two different implementations of a JSON serializer. You're
>> giving Jackson a JSONObject from the org.json implementation, and it
>> doesn't know how to serializer it. I'm sorry, but I'm not too familiar
>> with either GSON or org.json's JSON implementation, so I can't help much
>> beyond this.
>>
>> Cheers,
>> Chris
>>
>> On 12/8/14 2:53 AM, "Shekar Tippur" <ct...@gmail.com> wrote:
>>
>> >I have a nested JSON as payload.
>> >
>> >For example,
>> >
>> >{
>> >
>> >  "source_ip": "1.2.3.4",
>> >
>> >"source_type":null,
>> >
>> >"creation_time":"1415296951",
>> >
>> >"criticality":"4",
>> >
>> >"raw":{"ACKNOWLEDGED":"false"}
>> >
>> >}
>> >
>> >
>> >I am using GSON to deserialize the payload.
>> >
>> >I am having trouble with the nested part.
>>"raw":{"ACKNOWLEDGED":"false"}
>> >
>> >In my gson structure, I was trying to define it as
>> >
>> >private JSONObject raw;
>> >
>> >But this seem to throw a exception -
>> >
>> > Exception in thread "ThreadJob"
>> >org.codehaus.jackson.map.JsonMappingException: No serializer found for
>> >class org.json.JSONObject and no properties discovered to create
>> >BeanSerializer (to avoid exception, disable
>> >SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference
>> >chain:
>> 
>>>java.util.HashMap["event"]->samza.examples.wikipedia.system.ArgosAlert["
>>>ra
>> >w"])
>> >
>> >Appreciate if someone could point out how to handle this.
>> >
>> >- Shekar
>>
>>


Re: Having trouble deserializing nested json payload

Posted by Shekar Tippur <ct...@gmail.com>.
My bad guys. I was not thinking properly.
Chris - you are right. I was mixing things.

- Shekar

On Mon, Dec 8, 2014 at 10:50 AM, Paul Brown <pr...@mult.ifario.us> wrote:

> Hopefully you're on a more modern version of Jackson; the Codehaus version
> is ancient at this point with 2.4.4 being the latest (
> https://github.com/fasterxml/jackson).
>
>
> —
> prb@mult.ifario.us | Multifarious, Inc. | http://mult.ifario.us/
>
> On Mon, Dec 8, 2014 at 10:38 AM, Chris Riccomini <
> criccomini@linkedin.com.invalid> wrote:
>
> > Hey Shekar,
> >
> > It sounds like you're mixing serializers. Samza's JSON (de)serializer is
> > implemented using Jackson:
> >
> >   http://jackson.codehaus.org/
> >
> > The JSONObject is part of org.json:
> >
> >   http://www.json.org/java/index.html
> >
> > These are two different implementations of a JSON serializer. You're
> > giving Jackson a JSONObject from the org.json implementation, and it
> > doesn't know how to serializer it. I'm sorry, but I'm not too familiar
> > with either GSON or org.json's JSON implementation, so I can't help much
> > beyond this.
> >
> > Cheers,
> > Chris
> >
> > On 12/8/14 2:53 AM, "Shekar Tippur" <ct...@gmail.com> wrote:
> >
> > >I have a nested JSON as payload.
> > >
> > >For example,
> > >
> > >{
> > >
> > >  "source_ip": "1.2.3.4",
> > >
> > >"source_type":null,
> > >
> > >"creation_time":"1415296951",
> > >
> > >"criticality":"4",
> > >
> > >"raw":{"ACKNOWLEDGED":"false"}
> > >
> > >}
> > >
> > >
> > >I am using GSON to deserialize the payload.
> > >
> > >I am having trouble with the nested part. "raw":{"ACKNOWLEDGED":"false"}
> > >
> > >In my gson structure, I was trying to define it as
> > >
> > >private JSONObject raw;
> > >
> > >But this seem to throw a exception -
> > >
> > > Exception in thread "ThreadJob"
> > >org.codehaus.jackson.map.JsonMappingException: No serializer found for
> > >class org.json.JSONObject and no properties discovered to create
> > >BeanSerializer (to avoid exception, disable
> > >SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference
> > >chain:
> >
> >java.util.HashMap["event"]->samza.examples.wikipedia.system.ArgosAlert["ra
> > >w"])
> > >
> > >Appreciate if someone could point out how to handle this.
> > >
> > >- Shekar
> >
> >
>

Re: Having trouble deserializing nested json payload

Posted by Paul Brown <pr...@mult.ifario.us>.
Hopefully you're on a more modern version of Jackson; the Codehaus version
is ancient at this point with 2.4.4 being the latest (
https://github.com/fasterxml/jackson).


—
prb@mult.ifario.us | Multifarious, Inc. | http://mult.ifario.us/

On Mon, Dec 8, 2014 at 10:38 AM, Chris Riccomini <
criccomini@linkedin.com.invalid> wrote:

> Hey Shekar,
>
> It sounds like you're mixing serializers. Samza's JSON (de)serializer is
> implemented using Jackson:
>
>   http://jackson.codehaus.org/
>
> The JSONObject is part of org.json:
>
>   http://www.json.org/java/index.html
>
> These are two different implementations of a JSON serializer. You're
> giving Jackson a JSONObject from the org.json implementation, and it
> doesn't know how to serializer it. I'm sorry, but I'm not too familiar
> with either GSON or org.json's JSON implementation, so I can't help much
> beyond this.
>
> Cheers,
> Chris
>
> On 12/8/14 2:53 AM, "Shekar Tippur" <ct...@gmail.com> wrote:
>
> >I have a nested JSON as payload.
> >
> >For example,
> >
> >{
> >
> >  "source_ip": "1.2.3.4",
> >
> >"source_type":null,
> >
> >"creation_time":"1415296951",
> >
> >"criticality":"4",
> >
> >"raw":{"ACKNOWLEDGED":"false"}
> >
> >}
> >
> >
> >I am using GSON to deserialize the payload.
> >
> >I am having trouble with the nested part. "raw":{"ACKNOWLEDGED":"false"}
> >
> >In my gson structure, I was trying to define it as
> >
> >private JSONObject raw;
> >
> >But this seem to throw a exception -
> >
> > Exception in thread "ThreadJob"
> >org.codehaus.jackson.map.JsonMappingException: No serializer found for
> >class org.json.JSONObject and no properties discovered to create
> >BeanSerializer (to avoid exception, disable
> >SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference
> >chain:
> >java.util.HashMap["event"]->samza.examples.wikipedia.system.ArgosAlert["ra
> >w"])
> >
> >Appreciate if someone could point out how to handle this.
> >
> >- Shekar
>
>

Re: Having trouble deserializing nested json payload

Posted by Chris Riccomini <cr...@linkedin.com.INVALID>.
Hey Shekar,

It sounds like you're mixing serializers. Samza's JSON (de)serializer is
implemented using Jackson:

  http://jackson.codehaus.org/

The JSONObject is part of org.json:

  http://www.json.org/java/index.html

These are two different implementations of a JSON serializer. You're
giving Jackson a JSONObject from the org.json implementation, and it
doesn't know how to serializer it. I'm sorry, but I'm not too familiar
with either GSON or org.json's JSON implementation, so I can't help much
beyond this.

Cheers,
Chris

On 12/8/14 2:53 AM, "Shekar Tippur" <ct...@gmail.com> wrote:

>I have a nested JSON as payload.
>
>For example,
>
>{
>
>  "source_ip": "1.2.3.4",
>
>"source_type":null,
>
>"creation_time":"1415296951",
>
>"criticality":"4",
>
>"raw":{"ACKNOWLEDGED":"false"}
>
>}
>
>
>I am using GSON to deserialize the payload.
>
>I am having trouble with the nested part. "raw":{"ACKNOWLEDGED":"false"}
>
>In my gson structure, I was trying to define it as
>
>private JSONObject raw;
>
>But this seem to throw a exception -
>
> Exception in thread "ThreadJob"
>org.codehaus.jackson.map.JsonMappingException: No serializer found for
>class org.json.JSONObject and no properties discovered to create
>BeanSerializer (to avoid exception, disable
>SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference
>chain:
>java.util.HashMap["event"]->samza.examples.wikipedia.system.ArgosAlert["ra
>w"])
>
>Appreciate if someone could point out how to handle this.
>
>- Shekar