Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to default all JSON fields if not selector specified. #221

Open
rkrier85233 opened this issue Jul 29, 2013 · 15 comments
Open

Comments

@rkrier85233
Copy link

If your entity does not have any @core annotated fields and the client does a GET request without a selector, it would be nice to have the entity return all fields (the default behavior for JAX-WS).

@sduskis
Copy link
Member

sduskis commented Jul 31, 2013

There are a couple of options for this. We have a weekly Google Hangout discussing these types of things, and we thought that overriding the MessageBodyWriter isWritable() method should probably work in your case for the short term. Simply return false if there is no selector parameter in the request or the class isn't one that you want yoga to render. There is another user that did something like that, i.e. only return true if the class is in a particular set of classes that were converted.

In the longer term, we need to figure out how to make this type of thing easier.

We're working on improving the initial experience, and we'll work to ease the transition from JAX-RS standard behavior to Yoga rendering.

Can you please test out the isWritable() approach for the time being?

@ghost ghost assigned sduskis Jul 31, 2013
@rkrier85233
Copy link
Author

Sounds like a good solution Solomon. I'll try it out and get back to you. I might be able to get back to you later today.

From: Solomon Duskis <notifications@github.commailto:notifications@github.com>
Reply-To: skyscreamer/yoga <reply@reply.github.commailto:reply@reply.github.com>
Date: Tuesday, July 30, 2013 8:17 PM
To: skyscreamer/yoga <yoga@noreply.github.commailto:yoga@noreply.github.com>
Cc: Bob Krier <rkrier@axway.commailto:rkrier@axway.com>
Subject: Re: [yoga] Add the ability to default all JSON fields if not selector specified. (#221)

There are a couple of options for this. We have a weekly Google Hangout discussing these types of things, and we thought that overriding the MessageBodyWriter isWritable() method should probably work in your case for the short term. Simply return false if there is no selector parameter in the request or the class isn't one that you want yoga to render. There is another user that did something like that, i.e. only return true if the class is in a particular set of classes that were converted.

In the longer term, we need to figure out how to make this type of thing easier.

We're working on improving the initial experience, and we'll work to ease the transition from JAX-RS standard behavior to Yoga rendering.

Can you please test out the isWritable() approach for the time being?


Reply to this email directly or view it on GitHubhttps://github.com//issues/221#issuecomment-21837773.

@rkrier85233
Copy link
Author

Solomon,

I did a quick look and debugged all the variables available in the MessageBodyWriter.isWriteable(). When this method is called, I can't find anything in the class that tells me if there is a selector parameter. The GDataSelectorParser.parse method is called after MessageBodyWriter.isWriteable() is called. Because of that, I don't see how to condition the isWriteable return value.

Any ideas?

Bob

From: Bob Krier <rkrier@axway.commailto:rkrier@axway.com>
Date: Wednesday, July 31, 2013 9:18 AM
To: skyscreamer/yoga <reply@reply.github.commailto:reply@reply.github.com>, skyscreamer/yoga <yoga@noreply.github.commailto:yoga@noreply.github.com>
Cc: Bob Krier <rkrier@axway.commailto:rkrier@axway.com>
Subject: Re: [yoga] Add the ability to default all JSON fields if not selector specified. (#221)

Sounds like a good solution Solomon. I'll try it out and get back to you. I might be able to get back to you later today.

From: Solomon Duskis <notifications@github.commailto:notifications@github.com>
Reply-To: skyscreamer/yoga <reply@reply.github.commailto:reply@reply.github.com>
Date: Tuesday, July 30, 2013 8:17 PM
To: skyscreamer/yoga <yoga@noreply.github.commailto:yoga@noreply.github.com>
Cc: Bob Krier <rkrier@axway.commailto:rkrier@axway.com>
Subject: Re: [yoga] Add the ability to default all JSON fields if not selector specified. (#221)

There are a couple of options for this. We have a weekly Google Hangout discussing these types of things, and we thought that overriding the MessageBodyWriter isWritable() method should probably work in your case for the short term. Simply return false if there is no selector parameter in the request or the class isn't one that you want yoga to render. There is another user that did something like that, i.e. only return true if the class is in a particular set of classes that were converted.

In the longer term, we need to figure out how to make this type of thing easier.

We're working on improving the initial experience, and we'll work to ease the transition from JAX-RS standard behavior to Yoga rendering.

Can you please test out the isWritable() approach for the time being?


Reply to this email directly or view it on GitHubhttps://github.com//issues/221#issuecomment-21837773.

@sduskis
Copy link
Member

sduskis commented Jul 31, 2013

You should have access to the HttpServletRequest via the request protected
member variable. request.getParameter("selector") should do the trick.

-Solomon

On Wed, Jul 31, 2013 at 12:39 PM, Bob Krier notifications@github.comwrote:

Solomon,

I did a quick look and debugged all the variables available in the
MessageBodyWriter.isWriteable(). When this method is called, I can't find
anything in the class that tells me if there is a selector parameter. The
GDataSelectorParser.parse method is called after
MessageBodyWriter.isWriteable() is called. Because of that, I don't see how
to condition the isWriteable return value.

Any ideas?

Bob

From: Bob Krier <rkrier@axway.commailto:rkrier@axway.com>
Date: Wednesday, July 31, 2013 9:18 AM
To: skyscreamer/yoga <reply@reply.github.commailto:reply@reply.github.com>,
skyscreamer/yoga <yoga@noreply.github.commailto:yoga@noreply.github.com>

Cc: Bob Krier <rkrier@axway.commailto:rkrier@axway.com>
Subject: Re: [yoga] Add the ability to default all JSON fields if not
selector specified. (#221)

Sounds like a good solution Solomon. I'll try it out and get back to you.
I might be able to get back to you later today.

From: Solomon Duskis <notifications@github.com<mailto:
notifications@github.com>>
Reply-To: skyscreamer/yoga <reply@reply.github.com<mailto:
reply@reply.github.com>>
Date: Tuesday, July 30, 2013 8:17 PM
To: skyscreamer/yoga <yoga@noreply.github.com<mailto:
yoga@noreply.github.com>>
Cc: Bob Krier <rkrier@axway.commailto:rkrier@axway.com>
Subject: Re: [yoga] Add the ability to default all JSON fields if not
selector specified. (#221)

There are a couple of options for this. We have a weekly Google Hangout
discussing these types of things, and we thought that overriding the
MessageBodyWriter isWritable() method should probably work in your case for
the short term. Simply return false if there is no selector parameter in
the request or the class isn't one that you want yoga to render. There is
another user that did something like that, i.e. only return true if the
class is in a particular set of classes that were converted.

In the longer term, we need to figure out how to make this type of thing
easier.

We're working on improving the initial experience, and we'll work to ease
the transition from JAX-RS standard behavior to Yoga rendering.

Can you please test out the isWritable() approach for the time being?


Reply to this email directly or view it on GitHub<
https://github.com/skyscreamer/yoga/issues/221#issuecomment-21837773>.


Reply to this email directly or view it on GitHubhttps://github.com//issues/221#issuecomment-21876641
.

@rkrier85233
Copy link
Author

Sorry, I should have figured that out. I tried it and it works great. Thanks!

From: Solomon Duskis <notifications@github.commailto:notifications@github.com>
Reply-To: skyscreamer/yoga <reply@reply.github.commailto:reply@reply.github.com>
Date: Wednesday, July 31, 2013 10:20 AM
To: skyscreamer/yoga <yoga@noreply.github.commailto:yoga@noreply.github.com>
Cc: Bob Krier <rkrier@axway.commailto:rkrier@axway.com>
Subject: Re: [yoga] Add the ability to default all JSON fields if not selector specified. (#221)

You should have access to the HttpServletRequest via the request protected
member variable. request.getParameter("selector") should do the trick.

-Solomon

On Wed, Jul 31, 2013 at 12:39 PM, Bob Krier <notifications@github.commailto:notifications@github.com>wrote:

Solomon,

I did a quick look and debugged all the variables available in the
MessageBodyWriter.isWriteable(). When this method is called, I can't find
anything in the class that tells me if there is a selector parameter. The
GDataSelectorParser.parse method is called after
MessageBodyWriter.isWriteable() is called. Because of that, I don't see how
to condition the isWriteable return value.

Any ideas?

Bob

From: Bob Krier <rkrier@axway.commailto:rkrier@axway.commailto:rkrier@axway.com>
Date: Wednesday, July 31, 2013 9:18 AM
To: skyscreamer/yoga <reply@reply.github.commailto:reply@reply.github.commailto:reply@reply.github.com>,
skyscreamer/yoga <yoga@noreply.github.commailto:yoga@noreply.github.commailto:yoga@noreply.github.com>

Cc: Bob Krier <rkrier@axway.commailto:rkrier@axway.commailto:rkrier@axway.com>
Subject: Re: [yoga] Add the ability to default all JSON fields if not
selector specified. (#221)

Sounds like a good solution Solomon. I'll try it out and get back to you.
I might be able to get back to you later today.

From: Solomon Duskis <notifications@github.commailto:notifications@github.com<mailto:
notifications@github.commailto:notifications@github.com>>
Reply-To: skyscreamer/yoga <reply@reply.github.commailto:reply@reply.github.com<mailto:
reply@reply.github.commailto:reply@reply.github.com>>
Date: Tuesday, July 30, 2013 8:17 PM
To: skyscreamer/yoga <yoga@noreply.github.commailto:yoga@noreply.github.com<mailto:
yoga@noreply.github.commailto:yoga@noreply.github.com>>
Cc: Bob Krier <rkrier@axway.commailto:rkrier@axway.commailto:rkrier@axway.com>
Subject: Re: [yoga] Add the ability to default all JSON fields if not
selector specified. (#221)

There are a couple of options for this. We have a weekly Google Hangout
discussing these types of things, and we thought that overriding the
MessageBodyWriter isWritable() method should probably work in your case for
the short term. Simply return false if there is no selector parameter in
the request or the class isn't one that you want yoga to render. There is
another user that did something like that, i.e. only return true if the
class is in a particular set of classes that were converted.

In the longer term, we need to figure out how to make this type of thing
easier.

We're working on improving the initial experience, and we'll work to ease
the transition from JAX-RS standard behavior to Yoga rendering.

Can you please test out the isWritable() approach for the time being?


Reply to this email directly or view it on GitHub<
https://github.com/skyscreamer/yoga/issues/221#issuecomment-21837773>.


Reply to this email directly or view it on GitHubhttps://github.com//issues/221#issuecomment-21876641
.


Reply to this email directly or view it on GitHubhttps://github.com//issues/221#issuecomment-21879610.

@ogok
Copy link

ogok commented Oct 28, 2013

What should we do for spring-mvc? Is there any workaround for it?

@SpuTTer
Copy link

SpuTTer commented Dec 20, 2013

I'm also looking for a solution to this issue for the spring-mvc version. Any input there?

@mjason3
Copy link

mjason3 commented Mar 13, 2014

Hi,

In the spring mvc, I extend the ResultTraverser and change the addInstanceFields(...) like as attached. It works great, but i don't know if it's a perfect workaround?
screen shot 2014-03-13 at 5 38 19 pm

@sduskis
Copy link
Member

sduskis commented Mar 13, 2014

Selecting all possible fields would cause infinite looping in cases where your persisted objects have a lot of relationships with other persisted objects. I'd rather not add that logic to the ResultTraverser.
If you don't have that complex relationship, you can inject your own selector factory.

@mjason3
Copy link

mjason3 commented Mar 13, 2014

thanks @sduskis for quick reply. i will try that.

@kentongray
Copy link
Contributor

I've been thinking about this (see my comment on the the map issue). I think there may be a value for a non-recursive select all. I definitely understand the danger of a recursive select all.

@cabbonizio
Copy link

I really really love this library and it's very useful, but at the same time it would be great to have it return all fields if no "selector" is specified. Any movement on a solution for this? I'm very keen on using Yoga, it's pretty darn awesome.

@sduskis
Copy link
Member

sduskis commented Apr 18, 2014

This is a popular request. I'll see if I can finagle * to include a single level of "all fields." I'll also add an alternative "use all if no selector specified" selector mechanism, either in the existing selectors or a new selector type.

@kentongray
Copy link
Contributor

For what it is worth it is possible to do this by extending the JsonSelectorMessageBodyWriter and defining an alternative selector. We have support for @default annotations (of course we had inside help from the skyscreamer team) which show when no selector is specified

@cabbonizio
Copy link

Solomon, that would be fantastic to have both the "*" to return all fields at single level in addition to returning all if no selector is specified. Appreciate you responding so quickly on this and if you have anything to test I will gladly give it a shot. Have a great day.

-Chris

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants