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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:12:11+00:00 2026-05-28T05:12:11+00:00

I use FlexJson for serialization, the only problem is that it generates the field

  • 0

I use FlexJson for serialization, the only problem is that it generates the field names lower case while I need them to start with upper case:

class Person
{
     String name;
     public String getName() { return name;}
}

When serialized the field is serialized as name, while I need it to be Name.

How can I specify the output field name? Is there some attribute I can put to specify the required serialization name?

  • 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-28T05:12:12+00:00Added an answer on May 28, 2026 at 5:12 am

    You can achieve this by using a Custom Transformer. As per Flexjson page transformer is:

    Responsible for deciding how to translate the passed in object to
    JSON, making the appropriate calls on the JSONContext object to output
    the JSON, and/or passing the object along the transformation process.

    Flexjson has provided an abstract class AbstractTransformer for this purpose; Extend and override transform(Object object) to handle the transformation by yourself.

    Pasted below is the code of FieldNameTransformer which I wrote for specifying the field name s manually:

    public class FieldNameTransformer extends AbstractTransformer {
        private String transformedFieldName;
    
        public FieldNameTransformer(String transformedFieldName) {
            this.transformedFieldName = transformedFieldName;
        }
    
        public void transform(Object object) {
            boolean setContext = false;
    
            TypeContext typeContext = getContext().peekTypeContext();
    
            //Write comma before starting to write field name if this
            //isn't first property that is being transformed
            if (!typeContext.isFirst())
                getContext().writeComma();
    
            typeContext.setFirst(false);
    
            getContext().writeName(getTransformedFieldName());
            getContext().writeQuoted(object.toString());
    
            if (setContext) {
                getContext().writeCloseObject();
            }
        }
    
        /***
         * TRUE tells the JSONContext that this class will be handling 
         * the writing of our property name by itself. 
         */
        @Override
        public Boolean isInline() {
            return Boolean.TRUE;
        }
    
        public String getTransformedFieldName() {
            return this.transformedFieldName;
        }
    }
    

    Following is how to use this custom transformer:

    JSONSerializer serializer = new JSONSerializer().transform(new FieldNameTransformer("Name"), "name");
    

    where original field’s name is ‘name’ but in json ouput it will be replaced with Name.

    Sample out:

    {"Name":"Abdul Kareem"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Use Case I need to package up our kml which is in a String
use case example I have a servlet that is receiving login requests. If a
Use case: A does something on his box and gots stuck. He asks B
Use case: 3rd party application wants to programatically monitor a text file being generated
Use case: user clicks the link on a webpage - boom! load of files
Use case: I've just entered insert mode, and typed some text. Now I want
Use Case When a user goes to my website, they will be confronted with
We use a data acquisition card to take readings from a device that increases
Use Case: Would like to use IReport to Label item sold in my shop.
Use case: User launches app The user enters google password The app lets the

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.