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 9289147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:06:12+00:00 2026-06-18T20:06:12+00:00

In my schema I have an abstract class like this: @JsonAutoDetect(JsonMethod.NONE) public abstract class

  • 0

In my schema I have an abstract class like this:

@JsonAutoDetect(JsonMethod.NONE)
public abstract class AbstractEntity {

    @Id private Object id;
    @Version private Integer version;

    public AbstractEntity() {}

    @JsonProperty // this annotation causes infinite recursion
    public Object getId() { return id; }

}

This class is used as superclass for every entity, for example:

@JsonAutoDetect(JsonMethod.NONE)
public class Usuario extends AbstractEntity {

    private Cadastro cadastro;

    protected Usuario() {}

    public Usuario(Cadastro cadastro) {
        setCadastro(cadastro);
    }

    @JsonProperty
    public Cadastro getCadastro() { return cadastro; }

    @JsonProperty
    public void setCadastro(Cadastro cadastro) { this.cadastro = cadastro; }

}

I’m designing a REST layer which will let users create records in db via JSON request/response:

@POST
@Path("cadastrar")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response cadastrar(@Context HttpServletRequest request, Cadastro cadastro) {
    OObjectDatabaseTx bd = (OObjectDatabaseTx) request.getAttribute("object.database.tx");

    try {

        bd.begin();
        Usuario usuario = new Usuario(cadastro);
        usuario = bd.save(usuario);
        bd.commit();

        String json = new ObjectMapper().writeValueAsString(usuario);
        Response response = Response.status(HttpURLConnection.HTTP_CREATED).entity(json).build();

        return response;
        (...)

However, in this last method, when I call Jackson to serialize my newly created entity (in writeValueAsString method), I get an infinite recursion:

org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain:
  com.orientechnologies.orient.core.id.ORecordId["record"]->com.orientechnologies.orient.core.record.impl.ODocument["identity"]
->com.orientechnologies.orient.core.id.ORecordId["record"]->com.orientechnologies.orient.core.record.impl.ODocument["identity"]
->com.orientechnologies.orient.core.id.ORecordId["record"]->com.orientechnologies.orient.core.record.impl.ODoc...

I can avoid the infinite recursion by removing @JsonProperty from getId method in AbstractEntity class. However, this way the id property won’t be present in JSON response.

So, how can I serialize the id property?

Thanks!

  • 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-06-18T20:06:13+00:00Added an answer on June 18, 2026 at 8:06 pm

    Does Jackson support circular references? Is that the case?

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

Sidebar

Related Questions

I have an inheritance schema like below: public abstract class BaseAttachment { public abstract
I have a class like this public abstract class BaseType<T> { public string Name
I have a table which have schema like this id name 1 jack 2
I have a schema design that looks like this: Table: User Row Column Family
I have the following entities public abstract class Card { public virtual int Id
I have a Table Per Class Inheritance in Hibernate. @Entity @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) public abstract class
I have the following entities: [Table(Entities)] public abstract class Entity { public int EntityID
I have an xml with an xml-schema. The xml-schema defines an abstract complex type
i have this schema: <div id=container> <div id=content>some text</div> <footer> my footer things </footer>
I have an xml like this: <todo> <doLaundry cost=1/> <washCar cost=10/> <tidyBedroom cost=0 experiencePoints=5000/>

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.