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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:32:25+00:00 2026-06-17T18:32:25+00:00

I am trying to render a user object in JSON format using Play’s renderJSON

  • 0

I am trying to render a user object in JSON format using Play’s renderJSON function. However, when I call it I get an InvocationTargetException: null error.

While debugging, i’ve found that the value I gave for the user’s date of birth in the initial-data.yml file is the cause. It is as follows:

User(bob):
  firstName: Bob
  lastName: Bobson
  dob: 1979-01-01

If however I create a User programatically and set their dob with the new Date() constructor, the object rendered without issue. I even tried dob: !!java.util.Date "1979-01-01" as stated in SnakeYML’s documentation (http://code.google.com/p/snakeyaml/wiki/Documentation#YAML_syntax) to no avail.

What am I doing wrong here?

  • 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-17T18:32:26+00:00Added an answer on June 17, 2026 at 6:32 pm

    Eureka! I’ve got it! After about 9 hours of reading endless SO questions I finally got it through my thick skull that the error came about not because of the Date format, but because the default Gson renderer does not work well (by default) with bi-directional releationships such as @OneToMany and @ManyToOne.

    My solution? “Mute” one side of the relationship when the time came for rendering the object as JSON. Using the information found here: User Defined Exclusion Strategies i’ve come up with the following solution.

    /***************** Models ****************/
    
    class Person {
     @Expose
     public int age;
     @Expose
     public String name;
     @Expose
     @OneToMany(mappedBy="owner")
     public Dog dog;
    
     //Constructors and other code
    }
    
    class Dog {
     @Expose
     public String name;
     @ManyToOne(fetch=FetchType.Eager)
     public Person owner;
    
     //Constructor and other code
    }
    
    
    /**************Controller********************/
    
    public class Application extends Controller {
    
     public static Gson gson = GsonBuilder.excludeFieldsWithoutExposeAnnotation().create;
    
     public static void allPersons() {
      List<Person> people = Person.findAll();
      renderJSON(gson.toJson(people));
    
     //Error should be taken care of
     }
    }
    

    Using the @Expose annotation to mute one side of the bi-directional relationship at render time definitely solved the issue. Now I just have to figure out how to work around this new semi-one-sided structure.

    Another library I used before discovering this tip was FlexJSON. I might go back to it depending on how things go later down in the application because it works well with bi-directional relationships without requiring you to “mute” one side. It’s also (to me) more elegant than the Gson library.

    So thank you very much for all the assistance @emt14. I hope this post helps others out.

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

Sidebar

Related Questions

I am using the to_json method on an object, and trying to get the
I am trying to use the http GET method to retrieve JSON object I
I'm trying to display the following JSON object using YUI DataTable. I was able
I am trying to get the access_token for a user using the FB API
I have a User model that has many posts. Im trying to render the
I'm trying to render a ruby hash to a json string in haml. (the
I've been trying to render a webpage using the Adobe Flex / Flash builder
I get an AttributeError: 'QuerySet' object has no attribute 'ratings' when trying to do
I'm trying to deserialize JSON in this format: { data: [ { installed: 1,
I am trying to render a string over an image chosen by user via

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.