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

  • Home
  • SEARCH
  • 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 7795857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:11:30+00:00 2026-06-01T23:11:30+00:00

I am serializing a class like this into JSON using Flexjson: public class Item

  • 0

I am serializing a class like this into JSON using Flexjson:

public class Item {
    private Long id;
    private String name;
    private String description;
    ...

    // Getters and setters
    ...
}

Many of the Item fields can be null (e.g., description). Consequently, when such an Item object is serialized using Flexjson, I get the following JSON:

 {"id":62,"name":"Item A","description":null,...}

Since, as I already mentioned, an Item object may contain many null-value fields, the outcoming JSON is longer than effectively needed. This is in so far a problem, because I would like to send the generated JSON from a web server to a mobile client over a wireless connection via WiFi, 3G, EDGE or GPRS (i.e., more bandwidth is required, which results in less speed).

Therefore, I wanted to ask how it is possible to (efficiently) exclude null-value attributes using Flexjson?

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-01T23:11:31+00:00Added an answer on June 1, 2026 at 11:11 pm

    You can use the following transformer :

    import flexjson.transformer.AbstractTransformer;
    
    public class ExcludeTransformer extends AbstractTransformer {
    
      @Override
      public Boolean isInline() {
          return true;
      }
    
      @Override
      public void transform(Object object) {
          // Do nothing, null objects are not serialized.
          return;
      }
    }
    

    with the following usage :

    new JSONSerializer().transform(new ExcludeTransformer(), void.class).serialize(yourObject)
    

    Note that all null fields will be excluded.

    Adding the Transformer by Path (vs by Class) is not supported as FlexJSON forces TypeTransformer for null values :

    JSONContext.java : line 95 :

    private Transformer getPathTransformer(Object object) {
        if (null == object) return getTypeTransformer(object);
        return pathTransformerMap.get(path);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now, I'm currently serializing a class like this: class Session { String setting1;
I'm serializing a class like this public MyClass { public int? a { get;
I'm currently serializing objects like this: public static string ObjToJson(List<MyObject> TheObjects){ JavascriptSerializer TheSerializer =
I have an object like this: class MyObject { public string Object.Prop1 { get;
I have a simple class I'm serializing. [DataContract(Name = Test, Namespace = )] public
I'm serializing to XML my class where one of properties has type List<string>. public
class Person { public string m_name; private int m_age; // << how do I
I'm trying to serialize a class hierarchy to a Json string using DataContractJsonSerializer ,
I have a class that looks like this: public class MyModel{ public int TheId
I'd like to create a JSON string containing the instance variables of my class.

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.