skyscreamer / yoga

Yoga is RESTful but flexible.
http://yoga.skyscreamer.org/
Apache License 2.0
157 stars 66 forks source link

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

Open rkrier85233 opened 11 years ago

rkrier85233 commented 11 years ago

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 commented 11 years ago

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?

rkrier85233 commented 11 years ago

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.com<mailto: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/skyscreamer/yoga/issues/221#issuecomment-21837773.

rkrier85233 commented 11 years ago

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.com<mailto:rkrier@axway.com> Date: Wednesday, July 31, 2013 9:18 AM To: skyscreamer/yoga reply@reply.github.com<mailto:reply@reply.github.com>, skyscreamer/yoga yoga@noreply.github.com<mailto:yoga@noreply.github.com> Cc: Bob Krier rkrier@axway.com<mailto: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.com<mailto: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/skyscreamer/yoga/issues/221#issuecomment-21837773.

sduskis commented 11 years ago

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.com<mailto:rkrier@axway.com> Date: Wednesday, July 31, 2013 9:18 AM To: skyscreamer/yoga reply@reply.github.com<mailto:reply@reply.github.com>, skyscreamer/yoga yoga@noreply.github.com<mailto:yoga@noreply.github.com>

Cc: Bob Krier rkrier@axway.com<mailto: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.com<mailto: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/skyscreamer/yoga/issues/221#issuecomment-21876641 .

rkrier85233 commented 11 years ago

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

From: Solomon Duskis notifications@github.com<mailto:notifications@github.com> Reply-To: skyscreamer/yoga reply@reply.github.com<mailto:reply@reply.github.com> Date: Wednesday, July 31, 2013 10:20 AM To: skyscreamer/yoga yoga@noreply.github.com<mailto:yoga@noreply.github.com> Cc: Bob Krier rkrier@axway.com<mailto: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.com<mailto: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.com<mailto:rkrier@axway.commailto:rkrier@axway.com> Date: Wednesday, July 31, 2013 9:18 AM To: skyscreamer/yoga reply@reply.github.com<mailto:reply@reply.github.commailto:reply@reply.github.com>, skyscreamer/yoga yoga@noreply.github.com<mailto:yoga@noreply.github.commailto:yoga@noreply.github.com>

Cc: Bob Krier rkrier@axway.com<mailto: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<mailto: notifications@github.commailto:notifications@github.com>> Reply-To: skyscreamer/yoga reply@reply.github.com<mailto: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.com<mailto:yoga@noreply.github.com<mailto: yoga@noreply.github.commailto:yoga@noreply.github.com>> Cc: Bob Krier rkrier@axway.com<mailto: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/skyscreamer/yoga/issues/221#issuecomment-21876641 .

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

ogok commented 11 years ago

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

SpuTTer commented 10 years ago

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

mjason3 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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

kentongray commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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 commented 10 years ago

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