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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:19:14+00:00 2026-06-15T11:19:14+00:00

I have the class book: @Entity @Table(name = books) @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) @XmlType public class

  • 0

I have the class book:

@Entity
@Table(name = "books")
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType

public class Book {
    @Id
    @XmlAttribute
    private String isbn;

    private String title;
    private String authors;
    private int year;

    @OneToMany(mappedBy="reservedBook")
    private List<Reservation> bookReservations;

    //Getters, setters, addReservation, remove Reservation
        ......................
}

Then, I have class Reservation

@Entity
@Table(name = "reservations")
@XmlRootElement

public class Reservation {

    private String username;
    private String isbn;
    @Temporal(TemporalType.DATE)
    private Date date;

    @ManyToOne
    @JoinColumn(name = "isbn")
    private Book reservedBook;

    @ManyToOne
    @JoinColumn(name = "username")
    private User userWhoReserved;

        //Getters and setters

        ...........
 }

In the resource class I try to get a specific book like this:

@GET
@Path("/{isbn}")
@Produces(MediaType.TEXT_XML)
public Book getBookByIsbn(@PathParam("isbn") String isbn) {

    Book book = entityManager.find(Book.class, isbn);

    if (book != null) {
        return book;

    }

}

Now, it doesn’t serialize field List bookReservations. I’ve tried a lot of ideas found on the internet, like annotating the getter for the list with @XmlElement or using other annotations in other places (I don’t remember them now), but nothing worked.

EDIT: This is how a response looks like:

<book isbn="3333333333">
    <title>Mere Christianity</title>
    <authors>C. S. Lewis</authors>
    <year>2000</year>
</book>

but I also want to show the reservations.

What seems to be the solution?
Thanks!
Sorin

  • 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-15T11:19:15+00:00Added an answer on June 15, 2026 at 11:19 am

    I think the problem may be with the list bookReservations being null.

    class A{
    
        private List<String> someList = new ArrayList<String>();
    
        @XmlElement(name = "some-tag")
        public List<String> getList() {
            return someList;
        }
    
        public void setSomeList(List<String> someOtherList) {
            this.someList = someOtherList;
        }
    }
    

    I use this code everyday and works for me (Ignore other annotations that I have not provided).

    I have faced problem in these cases but only found that due to the list being null for some reason it is not serialized. Try checking whether the list is being set by JAXB in the setter method by debugging at that method.

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

Sidebar

Related Questions

I have the following class: @Entity @Table(name=tbl_books) public class Book{ private int id_book; private
I have 2 classes @Entity @Table(name = user) public class User @Id @Column(name =
I have the following model classes: @Entity @Table(name = title) public final class Title
I have three entity. public class Book { public string Name {get;set;} } public
I have an entity public class Book { public long Id { get; set;
I have something like this in my Spring Application: public class Book{ public Book(){
I have a class with two properties, say public class Book { public string
I have an example class book : public class Book { [Key] public int
I have a hierarchical data structure (using Entity beans)like say a Book Class which
I have 2 models. User: @Entity public class User implements Serializable { Long id;

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.