Question

I just switched to FlexJson and I am already having a problem.

The documentation at http://flexjson.sourceforge.net/, chapter Controlling JSON naming with @JSON states :

When an object is serialized the names of the properties on JSON objects are determined from the name of the Java property. This means the names of the getter methods or the field names are used. However, sometimes the JSON output doesn't match the names used by the Java object. You can control this using the @JSON annotation. For example:

    public class Species {
        @JSON(jsonName = "genus")
        private String type;

        private String name;

        @JSON(jsonName="species")
        public String getName() {
           return name;
        }
    }

Except it doesn't work. And then they say :

Defining a @JSON.jsonName is used in both serialization and deserialization.

Now when I have a look into the javadocs at http://flexjson.sourceforge.net/javadoc/index.html, I can see there are 4 optional elements belonging to the @JSON annotation, those are

include name objectFactory transformer

None of it is jsonName, like in the example.

So how do I get this annotation to work, so I can have different java and json names? How can I define this annotation element or make use of the predefined name

To clarify, I can annotate @JSON and autocomplete recommends @JSON(include), but then include cannot be resolved...

I am using FlexJson 2.1, and I imported flexjson.JSON;

Btw I am aware of this answer https://stackoverflow.com/a/8879616/2001247, but it's not what I want. I want to use annotations.

Was it helpful?

Solution

You need to use FlexJson 3.2

The problem is, latest jar accessible via developer site have 2.1 version number. But java doc corresponds to version 3.2.
You can find FlexJson 3.2 jar in maven repository.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top