Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6824991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:58:03+00:00 2026-05-26T21:58:03+00:00

Foo and Bar are both Beans. If FooResource is accessed via /foo/{id} and BarResource

  • 0

Foo and Bar are both Beans.

If FooResource is accessed via /foo/{id} and BarResource by /bar/{id} and Foo relates to Bar, should I return the URI for Bar or just the id for Bar? I presume the URI.

I encapsulate Foo in FooRepresentation and Bar in BarRepresentation and these types are actually what are returned by (Foo|Bar)Resource to Jackson. In the case of the related Bar, I use UriBuilder, using BarResource.class and foo.getBar().getId() to generate a URI.

The part where I am stumped is what is best if I wanted to change which Bar the Foo referenced. So I have the URI for the “new” Bar.. lets PUT or POST that to foo/1

At this point I am in FooResource with a method that has a constructed FooRepresentation parameter being passed to it. For direct properties, this makes sense, because I can use an injected FooRepository to merge changes.

Does it make sense to then create something like FooService that has a method setFooBar(Foo foo, Id barId) and that’s where the multiple repositories are injected?

If no, how do I go from URI -> BarResource -> Bar (not BarRepresentation) within a request to FooResource?

If I were within BarResource I could use UriInfo to extract the id parameter, which feels cleaner as well, rather than just parsing the id from the URI. So is there a way to get an instance of BarResource that will have appropriately injected @Context items such as UriInfo, from within FooResource?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:58:04+00:00Added an answer on May 26, 2026 at 9:58 pm

    Sticking to Jersey, what I’ve resolved to do is:

    For a given root resource class, ensure that it has an obtainX() function which can use a service to get an instance of the referred entity via PathParams. This returns the actual domain entity, and also throws a 404 exception if not null.

    Then another class would take the URI, use ResourceContext to get an instance of the resource, then use obtainX to get the entity. With this, any interrelationship between entities (which is only ever expressed via root entities) works. It’s not the best and is definitely the least comfortable part of everything I’m doing in Jersey, but it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this: SolutionName: Foo.sln Assembly: Foo.Bar Namespaces are: Foo.Bar.Views Foo.Bar.Model Foo.Bar.BusinessObjects Foo.Bar.Services Should
There are two classes foo.bar.FileUploader and barbar.foofoo.FileUploader Both are identical and extend Uploader Somewhere
Following structure: app.py /package __init__.py foo.py bar.py foo.py and bar.py contains both classes Foo
I want to find a line that has both 'foo' and 'bar' in this
I'm coding a site that's using tags. Two other classes (Foo and Bar) both
It seems both (mapcar 'car '((foo bar) (foo1 bar1))) and (mapcar #'car '((foo bar)
If I've got Foo with a property of type Bar. Both are persisted in
Both C# and Python allow named arguments, so you can write something like: foo(bar:1)
class Foo { public: void bar(); }; void Foo::bar() { static int n =
I want to transform /foo/bar/.. to /foo Is there a bash command which does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.