You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by JOSE L MARTINEZ-AVIAL <jl...@gmail.com> on 2015/11/03 20:13:09 UTC

Set timezone in jsonwriter for date conversion

Hello,
   I'm using Struts 2.3.16.3. I use the json plugin to return information
to the client (browser and ios App). The problem I have is that the
dates/times are local to my server, and since I have the option to know the
client's timezone, I would like to return the date to the client converted
to his local time. In order to do that I need to set the timezone of the
DateFormatter used by the json plugin. I don't see any issue way to do
that, apart from extending JSONWriter. Is that something possible? how I
would indicate the plugin to use my own version of JSONWriter?

Thanks

JL

Re: Set timezone in jsonwriter for date conversion

Posted by Lukasz Lenart <lu...@apache.org>.
Yeah, right now it's hard. I think the best option is to write your
own JSON result with all the custom stuff you need - JSONWriter &
JSONUtil. I'm going to refactor JSON plugin to be more extensible but
it won't happen till Struts 2.5.


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

2015-11-05 1:05 GMT+01:00 JOSE L MARTINEZ-AVIAL <jl...@gmail.com>:
> Hello,
>
>    Let me clarify the issue I have. I would like to be able to customize
> the way the JSON plugin formats the date when converting an objecto to
> json. Specifically, when I'm returning a JSONResult to a client. In order
> to do that I need to modify the DateFormatter used by JSONWriter so I can
> change its timezone. I took a look at the code, and it seems that make that
> modification is going to be hard. It would be something like this:
>
>   Extend JSONWriter to be able to use timezone with a Date(Maybe receiving
> the timezone as a parameter, or using annotation at the field level)
>   Extend JSONUtil to call my custom JSONWriter.
>   Extend JSONResult to call my customer JSONUtil, by overriding the method
> createJSONString. This would pretty much imply copy the whole code, as the
> method has a bunch of dependences from private variables when calling
> JSONUtil.
>
> Can anyone suggest a better approach?
>
> JL
>
> 2015-11-03 14:13 GMT-05:00 JOSE L MARTINEZ-AVIAL <jl...@gmail.com>:
>
>> Hello,
>>    I'm using Struts 2.3.16.3. I use the json plugin to return information
>> to the client (browser and ios App). The problem I have is that the
>> dates/times are local to my server, and since I have the option to know the
>> client's timezone, I would like to return the date to the client converted
>> to his local time. In order to do that I need to set the timezone of the
>> DateFormatter used by the json plugin. I don't see any issue way to do
>> that, apart from extending JSONWriter. Is that something possible? how I
>> would indicate the plugin to use my own version of JSONWriter?
>>
>> Thanks
>>
>> JL
>>

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


Re: Set timezone in jsonwriter for date conversion

Posted by JOSE L MARTINEZ-AVIAL <jl...@gmail.com>.
Hello,

   Let me clarify the issue I have. I would like to be able to customize
the way the JSON plugin formats the date when converting an objecto to
json. Specifically, when I'm returning a JSONResult to a client. In order
to do that I need to modify the DateFormatter used by JSONWriter so I can
change its timezone. I took a look at the code, and it seems that make that
modification is going to be hard. It would be something like this:

  Extend JSONWriter to be able to use timezone with a Date(Maybe receiving
the timezone as a parameter, or using annotation at the field level)
  Extend JSONUtil to call my custom JSONWriter.
  Extend JSONResult to call my customer JSONUtil, by overriding the method
createJSONString. This would pretty much imply copy the whole code, as the
method has a bunch of dependences from private variables when calling
JSONUtil.

Can anyone suggest a better approach?

JL

2015-11-03 14:13 GMT-05:00 JOSE L MARTINEZ-AVIAL <jl...@gmail.com>:

> Hello,
>    I'm using Struts 2.3.16.3. I use the json plugin to return information
> to the client (browser and ios App). The problem I have is that the
> dates/times are local to my server, and since I have the option to know the
> client's timezone, I would like to return the date to the client converted
> to his local time. In order to do that I need to set the timezone of the
> DateFormatter used by the json plugin. I don't see any issue way to do
> that, apart from extending JSONWriter. Is that something possible? how I
> would indicate the plugin to use my own version of JSONWriter?
>
> Thanks
>
> JL
>