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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:13:04+00:00 2026-05-19T14:13:04+00:00

I have the following classes: public class Student { private Long id ; private

  • 0

I have the following classes:

public class Student {
    private Long id  ;
    private String firstName;
    private String lastName;
private Set<Enrollment> enroll = new HashSet<Enrollment>();
//Setters and getters
}

public class Enrollment {
    private Student student;
    private Course course;
    Long enrollId;

//Setters and Getters
}

I have Struts2 controller and I would like to to return Serialized instance of Class Student only.

@ParentPackage("json-default")
public class JsonAction extends ActionSupport{

private Student student;

@Autowired
DbService dbService;

public String populate(){
    return "populate";
}

@Action(value="/getJson", results = {
        @Result(name="success", type="json")})
public String test(){
    student =  dbService.getSudent(new Long(1));
    return "success";
}

@JSON(name="student")
public Student getStudent() {
    return student;
}
public void setStudent(Student student) {
    this.student = student;
}

}

It returns me the serializable student object with all sub classes, but I would like to have only student object without the hashset returned .
How can I tell Struts to serialize only the object?
I do have Lazy loading enabled and hashset is returned as proxy class.

  • 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-19T14:13:05+00:00Added an answer on May 19, 2026 at 2:13 pm

    See the answer here which shows the use of include and exclude properties. I don’t think the example clearly shows excluding nested objects however I have used it for this purpose. If you still have issues I’ll post a regex which will demonstrate this.

    Problem with Json plugin in Struts 2

    Edit:
    Here is an example of using exclude properties in an annotation which blocks the serialization of a nested member:

    @ParentPackage("json-default")
    @Result(type = "json", params = {
            "excludeProperties",
            "^inventoryHistory\\[\\d+\\]\\.intrnmst, selectedTransactionNames, transactionNames"
        })
    public class InventoryHistoryAction extends ActionSupport {
    ...
    

    inventoryHistory is of type InventoryHistory a JPA entity object, intrnmst references another table but because of lazy loading if it were serialized it would cause an Exception when the action is JSON serialized for this reason the exclude parameter has been added to prevent this.

    Note that

    \\ 
    

    is required for each \ character, so a single \ would only be used in the xml where two are required because of escaping for the string to be parsed right.

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

Sidebar

Related Questions

I have the following classes: public class Person { public String FirstName { set;
I have the following three classes: public class Student { private Integer studentId; private
I have following classes: public abstract class CustomerBase { public long CustomerNumber { get;
I have the following classes: Public Class Email Private Shared ReadOnly EMAIL_REGEX = \b[a-zA-Z]+[a-zA-Z0-9._+-]+@
Suppose that I have the following HBM mapping: <class name=Student table=student> <set name=classes table=student_classes
I have the following classes: public class CartItem { public long Id { get;
I have the following classes public interface InterfaceBase { } public class ImplementA:InterfaceBase {
I have following classes. class A { public: void fun(); } class B: public
Given the classes: public class Person { public string Name { get; set; }
I have the following classes : public abstract class Item { //... } public

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.