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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:39:23+00:00 2026-06-06T11:39:23+00:00

I was looking for some solution around here and I didnt find any correct

  • 0

I was looking for some solution around here and I didnt find any correct answer to my question so I would like to ask you.

I have POJO with some simple attribs. and one List of another POJOs.

public class Standard implements Serializable {
    private String id;
    private String title;
    private String description;
    private Set<Interpretation> interpretations = new LinkedHashSet<Interpretation>();
}

public class Interpretation implements Serializable {
    private String id;
    private String title;
    private String description;
}

In my controller class, I am returning Standard POJO with GSON.

@RequestMapping(value="/fillStandard", method= RequestMethod.GET)
public @ResponseBody String getStandard(@RequestParam String id) {
    Standard s = DAOFactory.getInstance().getStandardDAO().findById(id);
    return new Gson().toJson(s);
}

The question is, am I able to get the list of interpretations in my Standard POJO using jQuery ? Something like :

function newStandard() {
$.get("standard/fillStandard.htm", {id:"fe86742b2024"}, function(data) {
    alert(data.interpretations[0].title);
});

}

Thanks a lot !

EDIT:
Well, thanks to @Atticus, there is solution of my problem. Hope that it will help somebody.

@RequestMapping(value="/fillStandard", method= RequestMethod.GET, produces="application/json")
    public @ResponseBody Standard getStandard(@RequestParam String id) {
        Standard s = DAOFactory.getInstance().getStandardDAO().findById(id);
        return s;
    }

Using @ResponseBody allows you to return the whole POJO, but you need to add produces="application/json" to your @RequestMapping annotation. Then you will be able to catch a returning object as JSON in jQuery like as I supposed.

function newStandard() {
$.get("standard/fillStandard.htm", {id:"idOfStandard"}, function(data) {
    alert(data.id);    //Standard id
    alert(data.interpretations[0].title);   //id of Interpretation on first place in array
});
  • 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-06T11:39:25+00:00Added an answer on June 6, 2026 at 11:39 am

    Well you have to create and register your custom serializer.

    It goes like this:

    //You create your builder that registers your custom serializer with the class you want to serialize
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(Standard.class, new StandardSerializer());
    
    //Then you create your Gson object
    Gson gson = builder.create();
    //Then you pass your object to the gson like
    Standard s = DAOFactory.getInstance().getStandardDAO().findById(id);
    gson.toJson(s);
    

    Your serializer looks like this:

    public class StandardSerializer implements JsonSerializer<Standard>{
    
        @Override
        public JsonElement serialize(Standard src, Type typeOfSrc,
                JsonSerializationContext context) {
    
                JsonObject obj = new JsonObject();
                //You put your simple objects in like this
                obj.add("id",new JsonPrimitive(src.getId()));
                //You put your complex objects in like this
                JsonObject interpretations = new JsonObject();
                //Here you need to parse your LinkedHashSet object and set up the values. 
                //For the sake of simplicity I just access the properties (even though I know this would not compile)
                interpretations.add("title", src.getInterpretation().getTitle());
                obj.add("interpretations", interpretations);
                return obj;
            }
    
    }
    

    In this case your Json would look something like:

    {"id":"idValue", "title":"titleValue", "description":"descriptionValue", "interpretations":["id":"interpretationIdValue"]}
    

    Now, you can access your data with jQuery like this:

    function newStandard() {
    $.get("standard/fillStandard.htm", {id:"fe86742b2024"}, function(data) {
        alert(data.interpretations.title);
    });
    }
    

    I hope this helps.

    EDIT:
    I see that your response gets converted to the declared method argument type which is String (as stated here: 16.3.3.2 Supported method return types). But what you really want is your Standrad POJO converted to JSON. I am not very familiar with Spring but as I have read here (16.3.2.6 Producible Media Types) there is another, maybe easier solution. If you want to return a JSON object, then change the return type of the
    getStandard method to Standard instead of String and add produces="application/json" to your @RequestMapping annotation. As far as I have read this should tell Spring that the return type should be converted to JSON. In this case you do not need to use Gson.

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

Sidebar

Related Questions

I've been looking around (both here and the googles), and I can't find an
I have looked around the internet for 3 hours now looking for a solution
I've been searching around trying to find an answer both here and google, although
I've been looking around for an answer to my question for a few days
I'm looking for solution to extract some node from large xml file (using xmlstarlet
Looking for some guidance on a WCF service I’m prototyping. I have a WCF
looking for some help with images referenced within the stylesheet. I have no problems
While looking at some conceptual questions in C,I came across this question in a
somewhat open ended question here as I am mostly looking for opinions. I am
I have a folder full of .tex files and I would like to write

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.