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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:22:40+00:00 2026-05-23T01:22:40+00:00

I’m using FlexJSON(but I’m open to other libraries) and I want to manually build

  • 0

I’m using FlexJSON(but I’m open to other libraries) and I want to manually build a json array. I have certain things that I need to add that are not part of the model that is being serialized. For instance I want to add an html column and css column to my json array. This data would be determined by iterating through the list and seeing if the values are above or below a certain number.

Right now I just have this.

   JSONSerializer json = new JSONSerializer();
    json.transform(new DateTransformer("MM/dd/yyyy hh:mm:ss"), "timeStamp");
    json.transform(new DecimalTransformer("#.00") , "ounces");
    json.include("timeStamp", "ounces");
    json.exclude("*");
    json.prettyPrint(true);

    response.setContentTypeIfNotSet("application/json");
    response.out.write(json.serialize(list).getBytes());  

But I want to manually build this array instead of just calling serialize. Say the ounces number is below a certain number then that should change the value of the css column. The css column is not part of the object(model) so I need to manually add that too. 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-05-23T01:22:40+00:00Added an answer on May 23, 2026 at 1:22 am

    Flexjson, and other JSON serialization libraries, use the structure of the model as their guide so they work best when the model has the data you want to put into JSON. Flexjson will use the property methods (getter/setter) during serialization. So if you want to add computations like what you were saying you can add getCssColumn() property method and Flexjson will treat it as any old property:

    public String getCssColumn() {
       return ounces < SOME_THRESHOLD ? "tooSmall" : "justRight";
    }
    

    So you can add as many of those methods as you want to your object, and it will serialize them just as they were actual instance variables on your object. This is a nice trick to render computed values into your JSON output just as you are looking for.

    If you don’t like that then I’d suggest creating a wrapper object that wraps your model object to keep track of the data you want to add to the model. You’ll have to be flexible on the JSON output, but you can wrap values around it. You just might end up with something like this:

    {
        "cssColumn": "justRight",
        ...
        "data": {
            "ounces": 45,
            ...
        }
    }
    

    Where data points to your model object hence it’s down a level from the root. This option is going to consume a little more memory, and require a little more structure (aka more classes to write) to work so I’d prefer the 1st option if it was me.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
This could be a duplicate question, but I have no idea what search terms
I have an array which has BIG numbers and small numbers in it. I
I want to construct a data frame in an Rcpp function, but when I
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.