You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Felipe Lorenz <fe...@idealogic.com.br> on 2014/02/25 15:09:14 UTC

Rest + JSON

Hello,

I have been working on projects with Struts2 + Rest + JSON.

It is just perfect.

But, there is always a but, when I use JSON as response I have to 
define the json plugin and add the rules in the struts.xml file.

I know rest plugin has it own json solution through adding ".json" in 
the end of URL, but I always falls in the cyclic exception. I complete 
understand this exception, what I don´t know is how to configure it.

I mean, there is a way to put a limit in how deep the objetcs will be 
parsed? Or even describe what I want in the json response?

Thanks in advance,
Felipe Lorenz

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Rest + JSON

Posted by Rahul Tokase <ra...@gmail.com>.
Just a thought

In struts2 json plugin we can have control using annotations. May be you
can seek/find the same in rest plugin.


On Wed, Feb 26, 2014 at 12:51 PM, Lukasz Lenart <lu...@apache.org>wrote:

> 2014-02-25 19:08 GMT+01:00 Felipe Lorenz <fe...@idealogic.com.br>:
> > Hi,
> >
> > I was not clear with my doubt. I dont´t want to use json-plugin, since
> > rest-plugin already has a json solution.
> >
> > I wanna try to use 100% of rest-plugin json solution and, at same time,
> keep
> > the control over the data is returned.
>
> I think the only option you have is to write your own
> ContentTypeHandler [1] and override built-in JSON handler
>
> [1]
> http://struts.apache.org/release/2.3.x/docs/rest-plugin.html#RESTPlugin-CustomContentTypeHandlers
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Rest + JSON

Posted by Lukasz Lenart <lu...@apache.org>.
The simplest way is to prepare a patch or Pull Request via GitHub -
then I can easily review your proposal

2014-02-26 17:17 GMT+01:00 Felipe Lorenz <fe...@idealogic.com.br>:
> Hello Lukasz,
>
> There is any impact if we add the following code in the JsonLibHandler
> class:
>
> JsonConfig jsonConfig = new JsonConfig();
> jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
>
> Just right above the line:
>
> if (target != null && sb.length() > 0 && sb.charAt(0) == '[') {
>
> And use it?
>
> I can't see a reason to not use it. Since it is throwing Exception in the
> actual code at same time will not make difference if my object does not
> contain a cyclic reference.
>
> What is your opinion?
>
> Also, it is just a workaround for the cyclic problem. I still want to have
> same control over the results, using ContentTypeHandler, as in the
> json-plugin.
>
> There is a way to read some parameter coming from the request by the
> ContentTypeHandler?
>
> Thanks,
> Felipe Lorenz
>
> Em 26/02/2014 10:02, Lukasz Lenart escreveu:
>>
>> You can always share your work as a patch or a plugin ;-)
>>
>> 2014-02-26 14:00 GMT+01:00 Felipe Lorenz <fe...@idealogic.com.br>:
>>>
>>> Thanks Lukasz, I think I´ll create a CustomContentTypeHandler.
>>>
>>> Em 26/02/2014 04:21, Lukasz Lenart escreveu:
>>>>
>>>>
>>>> 2014-02-25 19:08 GMT+01:00 Felipe Lorenz
>>>> <fe...@idealogic.com.br>:
>>>>>
>>>>>
>>>>> Hi,
>>>>>
>>>>> I was not clear with my doubt. I dont´t want to use json-plugin, since
>>>>> rest-plugin already has a json solution.
>>>>>
>>>>> I wanna try to use 100% of rest-plugin json solution and, at same time,
>>>>> keep
>>>>> the control over the data is returned.
>>>>
>>>>
>>>>
>>>> I think the only option you have is to write your own
>>>> ContentTypeHandler [1] and override built-in JSON handler
>>>>
>>>> [1]
>>>>
>>>>
>>>> http://struts.apache.org/release/2.3.x/docs/rest-plugin.html#RESTPlugin-CustomContentTypeHandlers
>>>>
>>>>
>>>> Regards
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Rest + JSON

Posted by Felipe Lorenz <fe...@idealogic.com.br>.
Hello Lukasz,

There is any impact if we add the following code in the JsonLibHandler 
class:

JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);

Just right above the line:

if (target != null && sb.length() > 0 && sb.charAt(0) == '[') {

And use it?

I can't see a reason to not use it. Since it is throwing Exception in 
the actual code at same time will not make difference if my object does 
not contain a cyclic reference.

What is your opinion?

Also, it is just a workaround for the cyclic problem. I still want to 
have same control over the results, using ContentTypeHandler, as in the 
json-plugin.

There is a way to read some parameter coming from the request by the 
ContentTypeHandler?

Thanks,
Felipe Lorenz

Em 26/02/2014 10:02, Lukasz Lenart escreveu:
> You can always share your work as a patch or a plugin ;-)
> 
> 2014-02-26 14:00 GMT+01:00 Felipe Lorenz 
> <fe...@idealogic.com.br>:
>> Thanks Lukasz, I think I´ll create a CustomContentTypeHandler.
>> 
>> Em 26/02/2014 04:21, Lukasz Lenart escreveu:
>>> 
>>> 2014-02-25 19:08 GMT+01:00 Felipe Lorenz 
>>> <fe...@idealogic.com.br>:
>>>> 
>>>> Hi,
>>>> 
>>>> I was not clear with my doubt. I dont´t want to use json-plugin, 
>>>> since
>>>> rest-plugin already has a json solution.
>>>> 
>>>> I wanna try to use 100% of rest-plugin json solution and, at same 
>>>> time,
>>>> keep
>>>> the control over the data is returned.
>>> 
>>> 
>>> I think the only option you have is to write your own
>>> ContentTypeHandler [1] and override built-in JSON handler
>>> 
>>> [1]
>>> 
>>> http://struts.apache.org/release/2.3.x/docs/rest-plugin.html#RESTPlugin-CustomContentTypeHandlers
>>> 
>>> 
>>> Regards
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Rest + JSON

Posted by Lukasz Lenart <lu...@apache.org>.
You can always share your work as a patch or a plugin ;-)

2014-02-26 14:00 GMT+01:00 Felipe Lorenz <fe...@idealogic.com.br>:
> Thanks Lukasz, I think I´ll create a CustomContentTypeHandler.
>
> Em 26/02/2014 04:21, Lukasz Lenart escreveu:
>>
>> 2014-02-25 19:08 GMT+01:00 Felipe Lorenz <fe...@idealogic.com.br>:
>>>
>>> Hi,
>>>
>>> I was not clear with my doubt. I dont´t want to use json-plugin, since
>>> rest-plugin already has a json solution.
>>>
>>> I wanna try to use 100% of rest-plugin json solution and, at same time,
>>> keep
>>> the control over the data is returned.
>>
>>
>> I think the only option you have is to write your own
>> ContentTypeHandler [1] and override built-in JSON handler
>>
>> [1]
>>
>> http://struts.apache.org/release/2.3.x/docs/rest-plugin.html#RESTPlugin-CustomContentTypeHandlers
>>
>>
>> Regards
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Rest + JSON

Posted by Felipe Lorenz <fe...@idealogic.com.br>.
Thanks Lukasz, I think I´ll create a CustomContentTypeHandler.

Em 26/02/2014 04:21, Lukasz Lenart escreveu:
> 2014-02-25 19:08 GMT+01:00 Felipe Lorenz 
> <fe...@idealogic.com.br>:
>> Hi,
>> 
>> I was not clear with my doubt. I dont´t want to use json-plugin, 
>> since
>> rest-plugin already has a json solution.
>> 
>> I wanna try to use 100% of rest-plugin json solution and, at same 
>> time, keep
>> the control over the data is returned.
> 
> I think the only option you have is to write your own
> ContentTypeHandler [1] and override built-in JSON handler
> 
> [1]
> http://struts.apache.org/release/2.3.x/docs/rest-plugin.html#RESTPlugin-CustomContentTypeHandlers
> 
> 
> Regards

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Rest + JSON

Posted by Lukasz Lenart <lu...@apache.org>.
2014-02-25 19:08 GMT+01:00 Felipe Lorenz <fe...@idealogic.com.br>:
> Hi,
>
> I was not clear with my doubt. I dont´t want to use json-plugin, since
> rest-plugin already has a json solution.
>
> I wanna try to use 100% of rest-plugin json solution and, at same time, keep
> the control over the data is returned.

I think the only option you have is to write your own
ContentTypeHandler [1] and override built-in JSON handler

[1] http://struts.apache.org/release/2.3.x/docs/rest-plugin.html#RESTPlugin-CustomContentTypeHandlers


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Rest + JSON

Posted by Felipe Lorenz <fe...@idealogic.com.br>.
Hi,

I was not clear with my doubt. I dont´t want to use json-plugin, since 
rest-plugin already has a json solution.

I wanna try to use 100% of rest-plugin json solution and, at same time, 
keep the control over the data is returned.

Thanks,
Felipe Lorenz

Em 25/02/2014 13:25, Lukasz Lenart escreveu:
> http://struts.apache.org/release/2.3.x/docs/json-plugin.html#JSONPlugin-CustomizingSerializationandDeserialization
> ?
> 
> 2014-02-25 15:09 GMT+01:00 Felipe Lorenz 
> <fe...@idealogic.com.br>:
>> Hello,
>> 
>> I have been working on projects with Struts2 + Rest + JSON.
>> 
>> It is just perfect.
>> 
>> But, there is always a but, when I use JSON as response I have to 
>> define the
>> json plugin and add the rules in the struts.xml file.
>> 
>> I know rest plugin has it own json solution through adding ".json" in 
>> the
>> end of URL, but I always falls in the cyclic exception. I complete
>> understand this exception, what I don´t know is how to configure it.
>> 
>> I mean, there is a way to put a limit in how deep the objetcs will be
>> parsed? Or even describe what I want in the json response?
>> 
>> Thanks in advance,
>> Felipe Lorenz
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Rest + JSON

Posted by Lukasz Lenart <lu...@apache.org>.
http://struts.apache.org/release/2.3.x/docs/json-plugin.html#JSONPlugin-CustomizingSerializationandDeserialization
?

2014-02-25 15:09 GMT+01:00 Felipe Lorenz <fe...@idealogic.com.br>:
> Hello,
>
> I have been working on projects with Struts2 + Rest + JSON.
>
> It is just perfect.
>
> But, there is always a but, when I use JSON as response I have to define the
> json plugin and add the rules in the struts.xml file.
>
> I know rest plugin has it own json solution through adding ".json" in the
> end of URL, but I always falls in the cyclic exception. I complete
> understand this exception, what I don´t know is how to configure it.
>
> I mean, there is a way to put a limit in how deep the objetcs will be
> parsed? Or even describe what I want in the json response?
>
> Thanks in advance,
> Felipe Lorenz
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org