Issue with inflector.jar

16 views
Skip to first unread message

RafaelViana

unread,
Jan 23, 2011, 6:34:05 PM1/23/11
to restfulie-java
I'm studying Restfulie to use in a project. So, I cloned it from
github and configured the build path.

I ran the ClientTests from rest_from_scratch_part_1_client project.
But, I get a NullPointerException in the line 84 in the XmlMediaType
class.

Line: names.add(Character.toLowerCase(plural.charAt(0)) +
plural.substring(1));

This exception is happening because the variable plural: String plural
= Noun.pluralOf(type.getSimpleName());

Then, I created a new project just using the inflector-0.7.0.jar and
run this test: System.out.println(Noun.pluralOf("teste"));
The output was also null.

What do I need to configure to use inflector?

Guilherme Silveira

unread,
Jan 25, 2011, 10:55:35 AM1/25/11
to restfulie-java
Hi Rafael,

It seems like an issue of localization, did you try to change the
inflector to use portuguese rules? Can you also try with "test"?

Regards

Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/

RafaelViana

unread,
Jan 25, 2011, 6:03:55 PM1/25/11
to restfulie-java
The exception happens because library doesn't have a default locale.

Tests:

System.out.println(Noun.pluralOf("loaf")); //Like in the restful-
client
Output: null

System.out.println(Noun.pluralOf("loaf", Locale.ENGLISH));
Output: loaves

System.out.println(Noun.pluralOf("loaf", Locale.ITALY));
Output: loaf

Why don't you getting this exception?
My OS's language is Portuguese and yours? Maybe the inflector load the
locale from the OS?

=====

Considered I want to add a inflection to Restfulie. Can I? (The
inflector lets extends the RuleBasedPluralizer class to add
inflections).

On 25 jan, 13:55, Guilherme Silveira
<guilherme.silve...@caelum.com.br> wrote:
> Hi Rafael,
>
> It seems like an issue of localization, did you try to change the
> inflector to use portuguese rules? Can you also try with "test"?
>
> Regards
>
> Guilherme Silveira
> Caelum | Ensino e Inovaçãohttp://www.caelum.com.br/

RafaelViana

unread,
Jan 25, 2011, 6:59:20 PM1/25/11
to restfulie-java
I looked at the inflector project's tests and It's right.
If there isn't a locale the return is null.

In the test:
assertThat(pluralOf("loaf", CHINESE), NULL);

I'll try to implement portuguese rules using inflector.

RafaelViana

unread,
Jan 26, 2011, 10:27:50 AM1/26/11
to restfulie-java
If the Restfulie implements a RuleBasedPlurarizer. Is there a way to
externalize this configuration to work like Ruby?
I'll try to fork the project tonight to show this ( I don't have
experience with git).

It will be something like:

br.com.caelum.restfulie.config

public class Inflections extends RuleBasedPluralizer
{
... all the rules
}

And use this class in the XMLMediaType.java:

String plural = Noun.pluralOf(type.getSimpleName(), new
Inflections());

The inflections will be contained inside Restfulie instead Inflection
library. It will be easier to add exceptions.
The best would be externalize this configuration to whom will use the
Restfulie. But, I can't imagine how.

Lucas Cavalcanti

unread,
Jan 26, 2011, 11:02:20 AM1/26/11
to restful...@googlegroups.com
Great idea!

maybe you should use an English inflector by default when implementing Inflections too.

we can configure it the same way as media types, via Restfulie.custom()

Guilherme Silveira

unread,
Jan 26, 2011, 11:55:13 AM1/26/11
to restful...@googlegroups.com

Hi Rafael,

Go ahead with it, it makes sense. If you commit it somewhere while deving it, just let us know and we can get u some feedback..

Regards

2011. 1. 26. 오후 2:02에 "Lucas Cavalcanti" <lucasm...@gmail.com>님이 작성:



Great idea!

maybe you should use an English inflector by default when implementing Inflections too.

we can configure it the same way as media types, via Restfulie.custom()



On Wed, Jan 26, 2011 at 1:27 PM, RafaelViana <rfl....@gmail.com> wrote:
>

> If the Restfulie imp...

RafaelViana

unread,
Jan 26, 2011, 7:17:00 PM1/26/11
to restfulie-java
Please take a look at the fork.

https://github.com/RafaelRViana/restfulie-java

I needed to made the Restfulie like a singleton to access the
RestClient from the XmlMediaType.
I'll try to find other way to implement it, what do you think?

Today I spent more time configuring the github to fork the project
than working on the code rsrs

On 26 jan, 14:55, Guilherme Silveira
<guilherme.silve...@caelum.com.br> wrote:
> Hi Rafael,
>
> Go ahead with it, it makes sense. If you commit it somewhere while deving
> it, just let us know and we can get u some feedback..
>
> Regards
>
> 2011. 1. 26. 오후 2:02에 "Lucas Cavalcanti" <lucasmrtu...@gmail.com>님이 작성:
>
> Great idea!
>
> maybe you should use an English inflector by default when implementing
> Inflections too.
>
> we can configure it the same way as media types, via Restfulie.custom()
>

Guilherme Silveira

unread,
Jan 27, 2011, 8:00:53 AM1/27/11
to restfulie-java
Hi Rafael,

Well done! Lucas did some comments on the commit...
Let us know if you have some questions... its almost there

Regards

Guilherme Silveira
Caelum | Ensino e Inovação
http://www.caelum.com.br/

2011/1/26 RafaelViana <rfl....@gmail.com>:

RafaelViana

unread,
Jan 27, 2011, 10:59:01 AM1/27/11
to restfulie-java
Hi,

I did the changes like you can see at the commit's conversation.
I think now it's better.

On 27 jan, 11:00, Guilherme Silveira
<guilherme.silve...@caelum.com.br> wrote:
> Hi Rafael,
>
> Well done! Lucas did some comments on the commit...
> Let us know if you have some questions... its almost there
>
> Regards
>
> Guilherme Silveira
> Caelum | Ensino e Inovaçãohttp://www.caelum.com.br/
>
> 2011/1/26 RafaelViana <rfl.vi...@gmail.com>:
Reply all
Reply to author
Forward
0 new messages