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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:20:26+00:00 2026-06-02T11:20:26+00:00

EDIT: Solved, will mark my answer when SO lets me :) I’m using greenDAO

  • 0

EDIT: Solved, will mark my answer when SO lets me 🙂

I’m using greenDAO to generate a bunch of classes, and it when I try to get GSON to serialise them, it seems to attempt to serialise some of the fields generated by greenDAO (Which are of no interest to me) and crashes. The object I wish to serialise references other generated objects and lists of generated objects.

GSON says it allows serialisation described by toString() methods, I tried different approaches, but when I examine the output to a file it just appears as the toString() method. Could somebody show me how you could produce a JSON object from a toString() method, or suggest another way to do a custom serialisation.

My 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-02T11:20:33+00:00Added an answer on June 2, 2026 at 11:20 am

    Figured it out in the end 🙂 Turns out I needed to implement a JsonSerializer for each of my objects and specify the serialisation manually. Very tedious! References to other objects require nesting, which I did by using the toJsonTree() method. Here’s my most readable serializer

    private class InfoSerializer implements JsonSerializer<Info>
    {
        @Override
        public JsonElement serialize(Info src, Type typeOfSrc,
                JsonSerializationContext context)
        {
             JsonObject obj = new JsonObject();
             obj.addProperty("details", src.getDetails());
             obj.addProperty("hostId", src.getHostId());
             obj.addProperty("dateCreated", src.getDateCreated().toString());
             obj.addProperty("expiryDate", src.getExpiryDate().toString());
             obj.add("alternativeInfo", getGsonInstance().toJsonTree(src.getAlternativeInfo()));
             obj.add("alternativeTimes", getGsonInstance().toJsonTree(src.getAlternativeTimes()));
             return obj;
        }   
    }
    

    Note: getGsonInstance() is a method I wrote to return a singleton Gson Object.

    And it is called by:

    public String infoToJson(Info i)
    {
        GsonBuilder gson = new GsonBuilder();
        gson.registerTypeAdapter(Info.class, new InfoSerializer());
        return gson.create().toJson(i);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: SOLVED! answer below first code box When i try to connect with a
Edit: Solved. Hi, I'm starting with Qt, I try to connect a slot to
edit: Solved - mod_rewrite was the problem I can't get CI to work as
[EDIT: Problem solved. Please see my answer below.] In my app I call the
Answer solved in edit below I had this piece of code Dictionary<Merchant, int> remaingCards
EDIT: This question is solved, but I can't accept my own answer just yet.
MAJOR EDIT: Problem was solved after reading Will Dean's comment. The original question is
Edit: I solved it by getting all of the class variables using get_class_vars(), and
-- EDIT -- Solved by using JSON dataType. -- QUESTION -- Hello, I am
Edit: Solved with a lot of help from Dems, I will post a truncated

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.