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

  • Home
  • SEARCH
  • 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 5957027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:20:31+00:00 2026-05-22T18:20:31+00:00

I have a large object graph from which I would like to expose objects

  • 0

I have a large object graph from which I would like to expose objects in a RESTful via a web-service. All objects feature an id-property, which serves as a primary key unique within the objects of that class. Further, all relationships in my object graph are bi-directional. When exposing an instance as a REST resource, I need all attributes of the instance to be written to JSON; however, I want the instances that are associated via relationships merely to be represented by their id, rather than having the entire object serialised to JSON.

Example: So, say a Person has a Dog and a Dog has a Person.

class Person {
  private Integer id;
  private String firstName;
  private String lastName;
  private Dog dog;

  // public getters/setters omitted
}

class Dog {
  private Integer id;
  private String name;
  private Person owner;

  // public getters/setters omitted
}

When serialising a given dog, I need the result to be:

{"id": 24, "name": "Fifo", "owner": 42}

And when serialising a given Person, I need the result to be:

{"id": 42, "firstName": "John", "lastName": "Blogs", "dog": 24}

rather than

{"id": 24, "name": "Fifo", "owner":
  {"id": 42, "firstName": "John", "lastName": "Blogs", "dog": 24}
}

and

{"id": 42, "firstName": "John", "lastName": "Blogs", "dog":
  {"id": 24, "name": "Fifo", "owner": 42}
}

respectively. I have played with the @JsonValue annotation in Jackson on the getId() method, but unfortunately, that applies always no matter whether the object it directly serialised or whether the object is reached via a relationship from another object.

I would have thought, that this use case is reasonably common. If this is not possible, what do other people do when exposing objects in an object graph via a RESTful API.

Thank you.

  • 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-22T18:20:32+00:00Added an answer on May 22, 2026 at 6:20 pm

    I can’t think of an obvious ways to do this with Jackson (there are many ways to override functionality, so there may be a way to do it with custom handlers, but that’s not simple), but it sounds like a good feature to bring on user/dev lists; others may well have implemented solutions, and it would be great to figure out a declarative solution here.

    In fact I suspect that an annotation like @JsonKey could be added to handle simple cases where single property is used as the key. So a feature request might make sense.

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

Sidebar

Related Questions

I have a large directed, acylic graph (DAG) from which I would like to
I have a single NSDictionary object which contains a large number of custom objects.
I have a WCF client proxy which reads from a SOAP web service. I
I have a large database and would like to select table names that have
I have a very large object which I wish to serialize. During the process
I have a few large object graphs which I have serialised, and some of
If I have large object graph that contains many duplicate strings, is there a
I have an NSArray which contains a large number of NSNumber objects (thousands). I
I have a large tree of Java Objects in my Desktop Application and am
I have a large text template which needs tokenized sections replaced by other text.

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.