marinmitev / smarthome

Eclipse SmartHome project
Eclipse Public License 1.0
2 stars 1 forks source link

Can we remove gson annotations from POJO objects? #229

Closed danchom closed 8 years ago

danchom commented 8 years ago

We want to remove @SerializedName gson annotations from Rule, Module and RuleTemplate objects. We propose to change to change internal (protected) name of fields to the serialized ones, but the public method will stay as they are.

For example in the rule: @SerializedName("on") protected List triggers;

should stay

protected List<Trigger> on;

but the public methods will be:

public List<Trigger> getTriggers() {
    if (on== null) {
        on = new ArrayList<Trigger>(3);
    }
    return on;
}

In this way we will decouple POJO implementation from gson serializer and can use different serializes too.

kaikreuzer commented 8 years ago

Calling a list of triggers "on" sounds pretty awkward to me. I would rather go the opposite way and rethink the name inside the JSON.

But what is the exact purpose of the suggested change? The implementation is already decoupled, the annotations are only an optional dependency at runtime and GSON does not need to be present.

hristostanchev commented 8 years ago

We want to use also other serializers for REST as Jackson or what ever else. We use it currently for other REST interfaces. Problem is that even with optional dependency if Jackcon is used then no on if then in JSON through the REST call but triggers, conditions and actions. This annotations in POJOs are only GSON related. Also for compilation GSON is needed. We think it is not OK to put GSON related annotations in main automation objects.

danchom commented 8 years ago

The annotations should be fixed in following way: 1) In the Rule and RuleTemplate json files on, if ,then property fields should be changed to triggers, conditions, actions. The annotations must be removed from Rule and RuleTemplates classes. 2) In the json presentation of module config property has to be changed to configuration. 3) In the Module class typeUID property has to be renamed to type, but the method should stay as it is getTypeUID(). 4) annotations @SerializedName("config") and @SerializedName("type") must be removed from Module class

kaikreuzer commented 8 years ago

Implemented with https://github.com/marinmitev/smarthome/pull/250