Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can achieve this by using a <strong>Custom Transformer</strong>. As per Flexjson page transformer is:</p> <blockquote> <p>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.</p> </blockquote> <p>Flexjson has provided an abstract class <a href="http://flexjson.sourceforge.net/javadoc/flexjson/transformer/AbstractTransformer.html" rel="nofollow">AbstractTransformer</a> for this purpose; Extend and override <code>transform(Object object)</code> to handle the transformation by yourself.</p> <p>Pasted below is the code of <code>FieldNameTransformer</code> which I wrote for specifying the field name s manually:</p> <pre><code>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; } } </code></pre> <p>Following is how to use this custom transformer:</p> <pre><code>JSONSerializer serializer = new JSONSerializer().transform(new FieldNameTransformer("Name"), "name"); </code></pre> <p>where original field's name is 'name' but in json ouput it will be replaced with Name.</p> <p>Sample out:</p> <pre><code>{"Name":"Abdul Kareem"} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload