Search
ScheduleListener.jsonSerializeTag Method
See Also
 






Raised when the Tag of a schedule item or resource must be serialized to JSON.

Namespace: com.mindfusion.scheduling.model
Package: com.mindfusion.scheduling.model

 Syntax

Java  Copy Code

void jsonSerializeTag (
    JsonSerializeTagEvent e
)

 Parameters

 Remarks

If the event is not handled, the control automatically serializes primitive tag values.

 Example

The following code shows how to serialize a simple structure as a JsonObject. JsonObject derives from HashMap<String, JsonValue>, where JsonValue is a boxing class that can contain primitive values and JsonObject itself (so you could nest objects).

Java  Copy Code

schedule.addScheduleListener(
    new ScheduleAdapter()
    {
        @Override
        public void jsonSerializeTag(JsonSerializeTagEvent e)
        {
            if (e.getTag() instanceof MyTag)
            {
                MyTag myTag = (MyTag) e.getTag();

                e.setRepresentation(myTag.writeJson());
                e.setHandled(true);
            }
        }

        @Override
        public void jsonDeserializeTag(JsonSerializeTagEvent e)
        {
            if (e.getObject() instanceof Appointment)
            {
                MyTag myTag = new MyTag();
                myTag.readJson(e.getRepresentation());

                e.setTag(myTag);
                e.setHandled(true);
            }
        }
    });

public class MyTag
{
    private String name;
    private double value;
    private boolean flag;

    public MyTag() {}

    public MyTag(String name, double value, boolean flag)
    {
        this.name = name;
        this.value = value;
        this.flag = flag;
    }

    public String getName() { return name; }
    public void setName(String name)
    {
        this.name = name;
    }

    public double getValue() { return value; }
    public void setValue(double value)
    {
        this.value = value;
    }

    public boolean getFlag() { return flag; }
    public void setFlag(boolean flag)
    {
        this.flag = flag;
    }

    public JsonObject writeJson()
    {
        JsonObject obj = new JsonObject();
        obj.put("Name", new JsonValue(name));
        obj.put("Value", new JsonValue(value));
        obj.put("Flag", new JsonValue(flag));
        return obj;
    }

    public void readJson(JsonObject json)
    {
        this.name = JsonValue.toString(json.getValue("Name"));
        this.value = JsonValue.toDouble(json.getValue("Value"));
        this.flag = JsonValue.toBoolean(json.getValue("Flag"));
    }
}

 See Also