private setFieldNamingStrategy

3944 views
Skip to first unread message

brianhks

unread,
Jan 9, 2009, 12:28:51 PM1/9/09
to google-gson
The design decision for why you use setFieldNamingPolicy and pass an
enum is beyond me. How do I pass a custom naming policy? Why have
you set it up to pass an enum instead of an interface?

It seems to me, the correct way of implementing this would be to make
setFieldNamingStrategy public, along with the matching interface, so I
can easily customize the naming policy/strategy.

It is open source so I can build it myself with the above changes, but
I am curios as to why it was made this way?

Brian

inde...@gmail.com

unread,
Jan 9, 2009, 12:37:38 PM1/9/09
to google-gson
The primary reason we did it that way is because we did not want to
complicate the API.
Moreover, the naming policy is a tricky thing to get right since the
output must be valid JSON as well as Java. What policy are you looking
for specifically? May be you can present an example of where the
custom policy will be useful.

Inder

Brian Hawkins

unread,
Jan 9, 2009, 1:23:02 PM1/9/09
to googl...@googlegroups.com
In my code I use the convention of m_varName for member variables.  I would like a policy that removes the m_ from the variable name.  Very simple really.  And I'm also only concerned with java to json, but it would be pretty easy to match varName to m_varName.

I understand the desire to not complicate the API, but restricting functionality only hinders adoption of your code.  Besides any complicated API can be simplified via good documentation, which you have done pretty well at.

Brian

Jacob Tomaw

unread,
Jan 9, 2009, 2:14:52 PM1/9/09
to googl...@googlegroups.com
Does the SerializedName annotation solve this?

Jacob
--
Jacob Tomaw
tfl:The Flatiron Life (http://tomaw.com)
Follow me on Twitter! (http://twitter.com/JacobTomaw)

Brian Hawkins

unread,
Jan 9, 2009, 3:09:04 PM1/9/09
to googl...@googlegroups.com
Write a small class of maybe 10 lines or add annotations to variables in 80+ files?  I think I'll go with 10 lines of code.

Brian

inde...@gmail.com

unread,
Jan 9, 2009, 11:11:31 PM1/9/09
to google-gson
Hi Brian,

Just to set some expectations: we are very close to release a version
of Gson 1.3 (probably beta) and would not like to add any more feature
at this time. However, we will start a discussion on the design of
this feature to get some feedback from the group before finalizing
it.

So, in the short term you have the option of modifying Gson's source-
code or following Jacob's suggestion.

Inder

inde...@gmail.com

unread,
Jan 9, 2009, 11:14:19 PM1/9/09
to google-gson
I entered a feature request on this topic at
http://code.google.com/p/google-gson/issues/detail?id=91
Reply all
Reply to author
Forward
0 new messages