Template for an externally-defined bean-type class with custom field actions in msgpack-java?

34 views
Skip to first unread message

MK

unread,
Dec 10, 2013, 7:44:40 PM12/10/13
to msg...@googlegroups.com
Hi,

let's say there is a Java "bean-type" class (meaning it has properties discoverable through getters and setters). This class is defined in an external library, so no annotating it.

Normally, such a case would be handled by using MessagePack.register + Templates for any custom types.

However, this class also possesses fields of an already well-defined type that we want to handle in a special way. For example, there's a get/setX(), where the field x is of type String.  Note that this class also has a multitude of other bean-type fields that should be serialized in the standard way.

Obviously, registering a Template for String won't work here, since we want to have special handling for a *specific* field of a *specific* class. Browsing through the msgpack API, there seems to be several possibilities of building a solution by extending general templates (JavaassistTemplate, ReflectionClassTemplate etc.). However, it's not apparent which is the best course of action.

My question is: what would the preferred, "proper" way to handle such a scenario? What kind of Templates should be registered, what should they base from, etc.?

Cheers,
Mikołaj

PS. For the sake of completeness, here's a concrete example:

public class MyClass {

    private int a;
   
    private String b;
   
    private String x; //this field requires non-standard packing

    public int getA() {
        return a;
    }

    public void setA(int a) {
        this.a = a;
    }

    public String getB() {
        return b;
    }

    public void setB(String b) {
        this.b = b;
    }

    public String getX() {
        return x;
    }

    public void setX(String x) {
        this.x = x;
    }
   
}
Reply all
Reply to author
Forward
0 new messages